This repository has been archived by the owner on Nov 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
update.sh
executable file
·62 lines (59 loc) · 1.99 KB
/
update.sh
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
#!/bin/bash
tmpdir=$(mktemp -d)
cleanup() {
rm -rf "$tmpdir"
}
trap cleanup EXIT
while read -r config; do
IFS="," read -r -a fields <<<"$config"
url="${fields[0]}"
fields=("${fields[@]:1}")
for repo in "${fields[@]}"; do
if [ -L "mirror/$repo" ] || [ -L "mirror/$repo/aarch64" ]; then
continue
fi
mkdir -p "mirror/$repo/aarch64"
wget "${url//\$repo/$repo}/$repo.db" -O "mirror/$repo/aarch64/$repo.db"
cp "mirror/$repo/aarch64/$repo.db" "$tmpdir/$repo.db"
mkdir -p "$tmpdir/$repo"
tar -xf "$tmpdir/$repo.db" -C "$tmpdir/$repo"
filenames=()
for pkgfile in "$tmpdir/$repo"/*/desc; do
readarray -t lines <"$pkgfile"
filename=""
sha256sum=""
for i in "${!lines[@]}"; do
line="${lines[$i]}"
if [ "$line" == "%FILENAME%" ]; then
filename="${lines[$i + 1]}"
elif [ "$line" == "%SHA256SUM%" ]; then
sha256sum="${lines[$i + 1]}"
fi
if [ -n "$filename" ] && [ -n "$sha256sum" ]; then
break
fi
done
filenames+=("$filename")
if [ -f "mirror/$repo/aarch64/$filename" ] && [ "$(sha256sum "mirror/$repo/aarch64/$filename")" != "$sha256sum mirror/$repo/aarch64/$filename" ]; then
echo "Invalid checksum, deleting old file"
rm "mirror/$repo/aarch64/$filename"
fi
while [ ! -f "mirror/$repo/aarch64/$filename" ]; do
wget "${url//\$repo/$repo}/$filename" -O "mirror/$repo/aarch64/$filename"
if [ "$(sha256sum "mirror/$repo/aarch64/$filename")" != "$sha256sum mirror/$repo/aarch64/$filename" ]; then
echo "Invalid checksum, retrying"
rm "mirror/$repo/aarch64/$filename"
fi
done
done
for file in "mirror/$repo/aarch64/"*; do
if [ "$(basename "$file")" == "$repo.db" ]; then
continue
fi
if ! [[ ${filenames[*]} =~ (^|[[:space:]])"$(basename "$file")"($|[[:space:]]) ]]; then
echo "Deleting old file $file"
rm "$file"
fi
done
done
done <repos