-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathauto.sh
More file actions
executable file
·258 lines (220 loc) · 7.98 KB
/
Copy pathauto.sh
File metadata and controls
executable file
·258 lines (220 loc) · 7.98 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
#!/usr/bin/env bash
set -euo pipefail
REPOS=(
"oneclickvirt/lxc_amd64_images"
"oneclickvirt/lxc_arm_images"
"oneclickvirt/lxd_images"
"oneclickvirt/incus_images"
"oneclickvirt/docker"
"oneclickvirt/pve_kvm_images"
"oneclickvirt/kvm_images"
"oneclickvirt/containerd"
"oneclickvirt/podman"
)
RAW_LIST_SOURCES=(
"https://raw.githubusercontent.com/ILLKX/Windows/master/README.md"
"https://raw.githubusercontent.com/ILLKX/Windows-VirtIO/master/README.md"
"https://raw.githubusercontent.com/oneclickvirt/pve/main/extra_scripts/configure_macos.sh"
"https://raw.githubusercontent.com/oneclickvirt/pve/main/scripts/install_macos_images.sh"
)
MACOS_INSTALLER_REFS=(
"https://github.com/oneclickvirt/macos/releases/download/images/high-sierra.iso.7z"
"https://github.com/oneclickvirt/macos/releases/download/images/mojave.iso.7z"
"https://github.com/oneclickvirt/macos/releases/download/images/catalina.iso.7z"
"https://github.com/oneclickvirt/macos/releases/download/images/big-sur.iso.7z"
"https://github.com/oneclickvirt/macos/releases/download/images/monterey.iso.7z"
"https://github.com/oneclickvirt/macos/releases/download/images/ventura.iso.7z"
"https://github.com/oneclickvirt/macos/releases/download/images/sonoma.iso.7z"
"https://github.com/oneclickvirt/macos/releases/download/images/sequoia.iso.7z"
)
ANDROID_X86_DIRS=(
"https://mirrors.tuna.tsinghua.edu.cn/osdn/android-x86/71931/"
)
BLISSOS_INSTALLER_REFS=(
"https://sourceforge.net/projects/blissos-x86/files/Official/BlissOS15/Gapps/Generic/Bliss-v15.9.2-x86_64-OFFICIAL-gapps-20241012.iso/download"
)
API_ENDPOINTS=(
"https://api.github.com"
"https://githubapi.spiritlhl.workers.dev"
"https://githubapi.spiritlhl.top"
)
OUTPUT_FILE="${OUTPUT_FILE:-images.txt}"
USER_AGENT="${USER_AGENT:-GitHub-Releases-Fetcher/1.0}"
EXCLUDE_PATTERNS=(
"vagrant_2.3.8.dev-1_amd64.deb"
)
EXTRA_IMAGE_REFS=(
"docker://spiritlhl/wds:10"
"docker://spiritlhl/wds:2019"
"docker://spiritlhl/wds:2022"
"docker://redroid/redroid:8.1.0-latest"
"docker://redroid/redroid:9.0.0-latest"
"docker://redroid/redroid:10.0.0-latest"
"docker://redroid/redroid:11.0.0-latest"
"docker://redroid/redroid:12.0.0-latest"
"docker://dockurr/macos:11"
"docker://dockurr/macos:12"
"docker://dockurr/macos:13"
"docker://dockurr/macos:14"
"docker://dockurr/macos:15"
)
log() {
printf '[images_auto_list] %s\n' "$*" >&2
}
require_command() {
local name="$1"
if ! command -v "$name" >/dev/null 2>&1; then
log "ERROR: missing required command: $name"
exit 1
fi
}
test_api_endpoint() {
local endpoint="$1"
local test_url="${endpoint}/repos/oneclickvirt/lxc_amd64_images"
curl -fsSL --connect-timeout 5 --max-time 10 -H "User-Agent: ${USER_AGENT}" "${test_url}" |
jq -e '.full_name? == "oneclickvirt/lxc_amd64_images" or .name? == "lxc_amd64_images"' >/dev/null
}
get_working_api() {
local endpoint
for endpoint in "${API_ENDPOINTS[@]}"; do
if test_api_endpoint "$endpoint"; then
printf '%s\n' "$endpoint"
return 0
fi
done
return 1
}
should_exclude_url() {
local url="$1"
local pattern
for pattern in "${EXCLUDE_PATTERNS[@]}"; do
if [[ "$url" == *"$pattern"* ]]; then
return 0
fi
done
return 1
}
emit_repo_download_urls() {
local repo="$1"
local api_base="$2"
local page=1
while true; do
local url="${api_base}/repos/${repo}/releases?per_page=100&page=${page}"
local releases_data
if ! releases_data=$(curl -fsSL -H "User-Agent: ${USER_AGENT}" "$url"); then
log "WARN: failed to fetch releases for ${repo} from page ${page}"
return 1
fi
local release_count
release_count=$(jq 'length' <<<"${releases_data}")
if [[ ! "$release_count" =~ ^[0-9]+$ ]] || [ "$release_count" -eq 0 ]; then
break
fi
jq -r '
.[] |
select(.tag_name != "processed" and .tag_name != null) |
.assets[]? |
.browser_download_url // empty
' <<<"${releases_data}" | while IFS= read -r download_url; do
if [ -n "$download_url" ] && ! should_exclude_url "$download_url"; then
printf '%s\n' "$download_url"
fi
done
page=$((page + 1))
done
}
emit_urls_from_text_source() {
local source_url="$1"
local content
if ! content=$(curl -fsSL --connect-timeout 10 --max-time 30 -H "User-Agent: ${USER_AGENT}" "$source_url"); then
log "WARN: failed to fetch raw list source: ${source_url}"
return 1
fi
grep -Eo '(https?://|download\.testip\.xyz/)[^[:space:]<>"'\''\)]*\.(iso|iso\.7z)(/download|\?[^[:space:]<>"'\''\)]*)?' <<<"${content}" |
sed -E 's#^download\.testip\.xyz/#https://download.testip.xyz/#I'
}
emit_android_x86_urls() {
local dir_url="$1"
local content
if ! content=$(curl -fsSL --connect-timeout 10 --max-time 30 -H "User-Agent: ${USER_AGENT}" "$dir_url"); then
log "WARN: failed to fetch Android-x86 directory: ${dir_url}"
return 1
fi
grep -Eo 'href="[^"]+\.iso"' <<<"${content}" |
sed -E 's/^href="//; s/"$//' |
while IFS= read -r href; do
if [[ "$href" == http://* || "$href" == https://* ]]; then
printf '%s\n' "$href"
else
printf '%s%s\n' "$dir_url" "$href"
fi
done
}
main() {
require_command curl
require_command jq
require_command grep
require_command sed
require_command sort
log "Testing GitHub API endpoints"
local working_api
if ! working_api=$(get_working_api); then
log "ERROR: no GitHub API endpoint is available"
exit 1
fi
log "Using API endpoint: ${working_api}"
local tmp_file
tmp_file=$(mktemp)
# Use double quotes so ${tmp_file} is expanded now (at trap-setup time),
# not later when the EXIT trap fires and the local variable is out of scope.
# shellcheck disable=SC2064
trap "rm -f '${tmp_file}'" EXIT
local repo
local failed_repos=0
for repo in "${REPOS[@]}"; do
log "Processing repository: ${repo}"
if ! emit_repo_download_urls "$repo" "$working_api" >>"${tmp_file}"; then
failed_repos=$((failed_repos + 1))
fi
sleep 1
done
local source_url
for source_url in "${RAW_LIST_SOURCES[@]}"; do
log "Processing raw image source: ${source_url}"
if ! emit_urls_from_text_source "$source_url" >>"${tmp_file}"; then
failed_repos=$((failed_repos + 1))
fi
sleep 1
done
local android_dir
for android_dir in "${ANDROID_X86_DIRS[@]}"; do
log "Processing Android-x86 mirror directory: ${android_dir}"
if ! emit_android_x86_urls "$android_dir" >>"${tmp_file}"; then
failed_repos=$((failed_repos + 1))
fi
sleep 1
done
log "Adding installer and special runtime image references"
printf '%s\n' "${MACOS_INSTALLER_REFS[@]}" >>"${tmp_file}"
printf '%s\n' "${BLISSOS_INSTALLER_REFS[@]}" >>"${tmp_file}"
printf '%s\n' "${EXTRA_IMAGE_REFS[@]}" >>"${tmp_file}"
if [ ! -s "$tmp_file" ]; then
log "ERROR: no image URLs were generated"
exit 1
fi
sort -u "$tmp_file" >"$OUTPUT_FILE"
local url_count
url_count=$(wc -l <"$OUTPUT_FILE" | tr -d ' ')
local special_count
special_count=$(grep -c '^docker://' "$OUTPUT_FILE" || true)
local installer_count
installer_count=$(grep -Eci '\.(iso|iso\.7z)(/download)?(\?|$)' "$OUTPUT_FILE" || true)
log "Generated ${url_count} image entries"
log "Included ${special_count} Docker special runtime entries"
log "Included ${installer_count} installer ISO entries"
if [ "$failed_repos" -gt 0 ]; then
log "WARN: ${failed_repos} repositories failed; generated list still includes available entries"
fi
log "Saved result to: ${OUTPUT_FILE}"
}
main "$@"