-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathgentoo_get_stage_url.sh
executable file
·162 lines (147 loc) · 3.08 KB
/
gentoo_get_stage_url.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
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
#!/bin/sh
DEBUG=0
RFS_BASE=http://ftp.free.fr/mirrors/ftp.gentoo.org/
debug() {
if [ $DEBUG -ge 1 ];then
echo "$*"
fi
}
while [ $# -ge 1 ]
do
case $1 in
--arch)
shift
if [ -z "$1" ];then
echo "ERROR: missing subargument"
exit 1
fi
ARCH=$1
case $1 in
x86_64)
ARCH=amd64
;;
powerpc64)
ARCH=ppc64
;;
esac
SARCH=$ARCH
shift
;;
-d)
DEBUG=1
shift
;;
*)
echo "ERROR: unknow argument $1"
exit 1
;;
esac
done
if [ -z "$ARCH" ];then
echo "ERROR: arch is not set"
exit 1
fi
CHECK_SIG=1
found_latest()
{
RFS_BPATH=/releases/$ARCH/autobuilds
BASEURL=$RFS_BASE$RFS_BPATH
case $ARCH in
arm)
SARCH=armv7a_hardfp
;;
ppc64)
RFS_BPATH=/releases/ppc/autobuilds
BASEURL=$RFS_BASE$RFS_BPATH
;;
sparc64)
RFS_BPATH=/releases/sparc/autobuilds
BASEURL=$RFS_BASE$RFS_BPATH
;;
x86)
SARCH=i686
;;
esac
LATEST_TXT="latest-stage3-${SARCH}-openrc.txt"
curl -s "$BASEURL/$LATEST_TXT" > $LATEST_TXT
RET=$?
grep -q '404 - Not Found' $LATEST_TXT && RET=1
if [ $RET -ne 0 ];then
#echo "DEBUG: retry without openrc variant"
LATEST_TXT="latest-stage3-${SARCH}.txt"
curl -s "$BASEURL/$LATEST_TXT" > $LATEST_TXT
RET=$?
if [ $RET -ne 0 ];then
echo "ERROR: fail to grab $BASEURL/$LATEST_TXT"
exit 1
fi
fi
echo "ROOTFS_LATEST=$BASEURL/$LATEST_TXT"
LATEST=$(grep -v ^# $LATEST_TXT | cut -d' ' -f1)
return 0
}
found_latest || exit $?
DIGESTS_ASC=$(basename "$LATEST.asc")
DIGESTS=$(basename "$LATEST.DIGESTS")
curl -s "$BASEURL/$LATEST.DIGESTS" > $DIGESTS
if [ $? -ne 0 ];then
echo "ERROR: fail to download $BASEURL/$LATEST.DIGESTS"
rm $LATEST_TXT
exit 1
fi
if [ $CHECK_SIG -eq 1 ];then
debug "DEBUG: curl $BASEURL/$LATEST.DIGESTS.asc"
curl -s "$BASEURL/$LATEST.asc" > $DIGESTS_ASC
RET=$?
if [ $RET -ne 0 ];then
echo "ERROR: fail to download $BASEURL/$LATEST.DIGESTS.asc"
rm ${LATEST_TXT}
rm latest-stage3-$SARCH.DIGESTS
exit 1
fi
debug "DEBUG: curl $LATEST"
wget -q -N "$BASEURL/$LATEST"
RET=$?
if [ $RET -ne 0 ];then
echo "ERROR: fail to download $BASEURL/$LATEST"
rm ${LATEST_TXT}
rm latest-stage3-$SARCH.DIGESTS
exit 1
fi
debug "DEBUG: GPG check with $DIGESTS_ASC and $(basename $LATEST)"
gpg --batch -q --verify "$DIGESTS_ASC" $(basename $LATEST) >gpg.out 2>gpg.err
RET=$?
if [ $RET -ne 0 ];then
echo "ERROR: GPG fail to verify"
cat gpg.out
cat gpg.err
rm gpg.err gpg.out
exit 1
fi
rm gpg.err gpg.out
fi
echo "ROOTFS_URL=$BASEURL/$LATEST"
echo "ROOTFS_BASE=$RFS_BASE"
echo "ROOTFS_PATH=$RFS_BPATH/$LATEST"
while read -r line
do
echo "$line" | grep -q SHA512
RET=$?
if [ $RET -eq 0 ];then
read line
LATEST_BASENAME=$(basename "$LATEST")
echo "$line" | grep -q "$LATEST_BASENAME$"
RET=$?
if [ $RET -eq 0 ];then
ROOTFS_SHA512=$(echo "$line" | cut -d' ' -f1)
echo "ROOTFS_SHA512=$ROOTFS_SHA512"
fi
fi
done < "$DIGESTS"
rm "$DIGESTS"
if [ $CHECK_SIG -eq 1 ];then
rm "$DIGESTS_ASC"
fi
if [ -e "$LATEST_TXT" ];then
rm "$LATEST_TXT"
fi