-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10-fetch-current-stage3-from-gentoo.sh
executable file
·92 lines (81 loc) · 2.64 KB
/
10-fetch-current-stage3-from-gentoo.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/bin/bash
#
# download latest x86 & amd64 stage3 image
pause() {
local Answer=""
echo "Pause."
echo -n "Enter to continue: "
read Answer
}
prepare_directories() {
[ -e "$DIR_NFS_SHARES/distfiles" ] || mkdir "$DIR_NFS_SHARES/distfiles"
[ -e "$DIR_NFS_SHARES/work" ] || mkdir "$DIR_NFS_SHARES/work"
[ -e "$DIR_NFS_SHARES/binpkgs-$1-$2" ] || mkdir "$DIR_NFS_SHARES/binpkgs-$1-$2"
}
download_variant() {
local Arch=$1
local Variant=$2
local Tmpfile=$(mktemp)
case $Arch in
x86) FArch=i686;;
*) FArch=$Arch;;
esac
# example URLs
# https://bouncer.gentoo.org/fetch/root/all/releases/amd64/autobuilds/latest-stage3-amd64-systemd.txt
# https://bouncer.gentoo.org/fetch/root/all/releases/amd64/autobuilds/20210919T170549Z/stage3-amd64-openrc-20210919T170549Z.tar.xz
# determine the exact filename of the download archive behind "latest-XXXX"
# first, check if the composed download url exists
HTTPCODE=$(curl --silent --output /dev/null --write-out "%{http_code}" --location "https://bouncer.gentoo.org/fetch/root/all/releases/$Arch/autobuilds/latest-stage3-$FArch-$Variant.txt")
if [ "$HTTPCODE" -ne 200 ]
then
echo
echo "cannot download $Arch $Variant - HTTP Returncode is $HTTPCODE"
exit 100
fi
curl --location "https://bouncer.gentoo.org/fetch/root/all/releases/$Arch/autobuilds/latest-stage3-$FArch-$Variant.txt" --output $Tmpfile
# check if file is GPG signed
local FirstLine=$(head -n1 $Tmpfile)
if [ "$FirstLine" = "-----BEGIN PGP SIGNED MESSAGE-----" ]
then
echo "download done, GPG check:"
mv "$Tmpfile" "${Tmpfile}-s"
gpg --output "$Tmpfile" --verify "${Tmpfile}-s"
rm -f "${Tmpfile}-s"
fi
FILE=$(cat $Tmpfile | sed '/^#/d' | cut -f1 -d" " )
FILEPATH="https://bouncer.gentoo.org/fetch/root/all/releases/$Arch/autobuilds/$FILE"
rm -f "${Tmpfile}"
echo "Download URL: $FILEPATH"
pause
curl --remote-name --location --continue-at - "$FILEPATH" && echo "Download successful."
echo
prepare_directories $Arch $Variant
}
LANG=C
# source the config file
DIR=$(dirname $0); [ -e "$DIR/00-config.sh" ] && source "$DIR/00-config.sh"
cd $DIR_BASE
echo "download latest gentoo stage3 images"
echo "===================================="
echo " optional parameters: <architecure> <variant>"
echo " example combinations:"
echo " $0 amd64 systemd"
echo " $0 amd64 openrc"
echo " $0 amd64 musl"
echo " $0 amd64 musl-hardened"
echo " $0 amd64 desktop-openrc"
echo " $0 amd64 desktop-systemd"
echo " $0 x86 systemd"
echo
echo " $0 all"
if [ -z "$1" ]; then
exit
fi
if [ "$1" = "all" ]
then
download_variant amd64 systemd
download_variant amd64 musl
download_variant x86 systemd
else
download_variant "$1" "$2"
fi