-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathpack.ps1
87 lines (83 loc) · 2.96 KB
/
pack.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# 定义下载 URL 和路径变量
$CacheDir = "$PSScriptRoot\cache"
$UrlWitchCachePath = @{
"https://github.com/AdguardTeam/AdGuardHome/releases/latest/download/AdGuardHome_linux_arm64.tar.gz" = "$CacheDir\AdGuardHome_linux_arm64.tar.gz"
"https://github.com/AdguardTeam/AdGuardHome/releases/latest/download/AdGuardHome_linux_armv7.tar.gz" = "$CacheDir\AdGuardHome_linux_armv7.tar.gz"
}
# 创建缓存目录
if (-Not (Test-Path -Path $CacheDir)) {
Write-Host "Creating cache directory..."
New-Item -Path $CacheDir -ItemType Directory
}
# 下载文件,有缓存时不再下载
Write-Host "Downloading AdGuardHome..."
foreach ($url in $UrlWitchCachePath.Keys) {
$CachePath = $UrlWitchCachePath[$url]
if (-Not (Test-Path -Path $CachePath)) {
Write-Host "Downloading $url..."
Invoke-WebRequest -Uri $url -OutFile $CachePath
if ($?) {
Write-Host "Download completed successfully."
}
else {
Write-Host "Download failed. Exiting..."
exit 1
}
}
else {
Write-Host "File already exists in cache. Skipping download."
}
}
# 使用 tar 解压文件
Write-Host "Extracting AdGuardHome..."
foreach ($url in $UrlWitchCachePath.Keys) {
$CachePath = $UrlWitchCachePath[$url]
if ($CachePath -match 'AdGuardHome_linux_(arm64|armv7)\.tar\.gz$') {
$ExtractDir = "./cache/" + $matches[1]
}
else {
throw "Invalid file path: $CachePath"
}
if (-Not (Test-Path -Path $ExtractDir)) {
New-Item -Path $ExtractDir -ItemType Directory
Write-Host "Extracting $CachePath..."
tar -xzf $CachePath -C $ExtractDir
if ($?) {
Write-Host "Extraction completed successfully."
}
else {
Write-Host "Extraction failed"
exit 1
}
}
}
# 给项目打包,使用 7-Zip 压缩 zip
Write-Host "Packing AdGuardHome..."
$7z = "C:\Program Files\7-Zip\7z.exe"
$OutputPathArm64 = "$CacheDir\AdGuardHomeForMagisk_arm64.zip"
$OutputPathArmv7 = "$CacheDir\AdGuardHomeForMagisk_armv7.zip"
if (Test-Path -Path $OutputPathArm64) {
Remove-Item -Path $OutputPathArm64
}
if (Test-Path -Path $OutputPathArmv7) {
Remove-Item -Path $OutputPathArmv7
}
# pack arm64
& $7z a -tzip $OutputPathArm64 "*.sh"
& $7z a -tzip $OutputPathArm64 "module.prop"
& $7z a -tzip $OutputPathArm64 "META-INF"
& $7z a -tzip $OutputPathArm64 "scripts"
& $7z a -tzip $OutputPathArm64 "webroot"
& $7z a -tzip $OutputPathArm64 "bin/"
& $7z a -tzip $OutputPathArm64 "./cache/arm64/AdGuardHome/AdGuardHome"
& $7z rn $OutputPathArm64 "AdGuardHome" "bin/AdGuardHome"
# pack armv7
& $7z a -tzip $OutputPathArmv7 "*.sh"
& $7z a -tzip $OutputPathArmv7 "module.prop"
& $7z a -tzip $OutputPathArmv7 "META-INF"
& $7z a -tzip $OutputPathArmv7 "scripts"
& $7z a -tzip $OutputPathArmv7 "webroot"
& $7z a -tzip $OutputPathArmv7 "bin/"
& $7z a -tzip $OutputPathArmv7 "./cache/armv7/AdGuardHome/AdGuardHome"
& $7z rn $OutputPathArmv7 "AdGuardHome" "bin/AdGuardHome"
Write-Host "Packing completed successfully."