-
Notifications
You must be signed in to change notification settings - Fork 1
/
shrdl.sh
executable file
·71 lines (61 loc) · 1.95 KB
/
shrdl.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
63
64
65
66
67
68
69
70
71
#!/bin/sh
case $1 in
http://*|https://*) set "${1%/}" && repodomain=${1#*//} ;;
*) printf "Usage: [SINGLETHREADED=1] %s <repo url>\n" "${0##*/}" ; exit 0 ;;
esac
for dep in curl gzip bzip2; do
if ! command -v $dep > /dev/null; then
printf "%s not found, please install %s\n" "$dep" "$dep"
exit 1
fi
done
headers1="X-Machine: iPod4,1"
headers2="X-Unique-ID: 0000000000000000000000000000000000000000"
headers3="X-Firmware: 6.1"
headers4="User-Agent: Telesphoreo APT-HTTP/1.0.999"
[ -d "$repodomain" ] || mkdir -p "$repodomain"
cd "$repodomain" || exit 1
:> urllist.txt
if [ "$(curl -H "$headers1" -H "$headers2" -H "$headers3" -H "$headers4" -w '%{http_code}' -L -s -o Packages.bz2 "$1/Packages.bz2")" -eq 200 ]; then
archive=bz2
prog=bzip2
elif [ "$(curl -H "$headers1" -H "$headers2" -H "$headers3" -H "$headers4" -w '%{http_code}' -L -s -o Packages.gz "$1/Packages.gz")" -eq 200 ]; then
archive=gz
prog=gzip
rm Packages.bz2
else
printf "Couldn't find a Packages file. Exiting\n"
rm Packages.bz2 Packages.gz
exit 1
fi
$prog -df Packages.$archive
while read -r line; do
case $line in
Filename:*)
deburl=${line#Filename: }
case $deburl in
./*) deburl=${deburl#./} ;;
esac
printf "%s/%s\n" "$1" "$deburl" >> urllist.txt
;;
esac
done < ./Packages
[ ! -d debs ] && mkdir debs
cd debs || exit 1
command -v pgrep > /dev/null || SINGLETHREADED=1
printf "Downloading debs\n"
if [ -n "$SINGLETHREADED" ]; then
while read -r i; do
curl -H "$headers1" -H "$headers2" -H "$headers3" -H "$headers4" -g -L -s -O "$i"
done < ../urllist.txt
else
[ -z "$JOBS" ] && JOBS=16
while read -r i; do
while [ "$(pgrep -c curl)" -ge "$JOBS" ]; do
sleep 0.1
done
curl -H "$headers1" -H "$headers2" -H "$headers3" -H "$headers4" -g -L -s -O "$i" &
done < ../urllist.txt
wait
fi
printf "Done!\n"