Skip to content

Commit 141f9ea

Browse files
committed
contrib/rootfs-builder: Don't hit latest-stage3 when STAGE3 is supplied
This saves some unnecessary network traffic for folks who already know what they want. Also guard against redundant configuration, like: $ DATE=20170907 STAGE3=stage3-amd64-20170907.tar.bz2 get-stage3.sh Signed-off-by: W. Trevor King <[email protected]>
1 parent 4dfca7a commit 141f9ea

File tree

1 file changed

+45
-11
lines changed

1 file changed

+45
-11
lines changed

contrib/rootfs-builder/get-stage3.sh

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# Download the current Gentoo stage3
44
#
5-
# Copyright (C) 2014-2015 W. Trevor King <[email protected]>
5+
# Copyright (C) 2014-2018 W. Trevor King <[email protected]>
66
#
77
# Licensed under the Apache License, Version 2.0 (the "License");
88
# you may not use this file except in compliance with the License.
@@ -16,8 +16,36 @@
1616
# See the License for the specific language governing permissions and
1717
# limitations under the License.
1818

19+
die()
20+
{
21+
echo "$1"
22+
exit 1
23+
}
24+
1925
MIRROR="${MIRROR:-http://distfiles.gentoo.org/}"
20-
STAGE3_ARCH="${STAGE3_ARCH:-amd64}"
26+
if test -n "${STAGE3}"
27+
then
28+
if test -n "${STAGE3_ARCH}"
29+
then
30+
die 'if you set STAGE3, you do not need to set STAGE3_ARCH'
31+
fi
32+
if test -n "${DATE}"
33+
then
34+
die 'if you set STAGE3, you do not need to set DATE'
35+
fi
36+
STAGE3_ARCH=$(echo "${STAGE3}" | sed -n 's/stage3-\([^-]*\)-.*/\1/p')
37+
if test -z "${STAGE3_ARCH}"
38+
then
39+
die "could not calculate STAGE3_ARCH from ${STAGE3}"
40+
fi
41+
DATE=$(echo "${STAGE3}" | sed -n "s/stage3-${STAGE3_ARCH}-\([0-9]*\)[.]tar[.].*/\1/p")
42+
if test -z "${DATE}"
43+
then
44+
die "could not calculate DATE from ${STAGE3}"
45+
fi
46+
else
47+
STAGE3_ARCH="${STAGE3_ARCH:-amd64}"
48+
fi
2149

2250
if test -z "${BASE_ARCH}"
2351
then
@@ -38,19 +66,25 @@ then
3866
fi
3967

4068
BASE_ARCH_URL="${BASE_ARCH_URL:-${MIRROR}releases/${BASE_ARCH}/autobuilds/}"
41-
LATEST=$(wget -O - "${BASE_ARCH_URL}latest-stage3.txt")
42-
DATE=$(echo "${LATEST}" | sed -n "s|/stage3-${STAGE3_ARCH}-[0-9]*[.]tar[.]bz2.*||p")
69+
70+
if test -z "${STAGE3}"
71+
then
72+
LATEST=$(wget -O - "${BASE_ARCH_URL}latest-stage3.txt")
73+
if test -z "${DATE}"
74+
then
75+
DATE=$(echo "${LATEST}" | sed -n "s|/stage3-${STAGE3_ARCH}-[0-9]*[.]tar.*||p")
76+
if test -z "${DATE}"
77+
then
78+
die "could not calculate DATE from ${BASE_ARCH_URL}latest-stage3.txt"
79+
fi
80+
fi
81+
STAGE3="${STAGE3:-stage3-${STAGE3_ARCH}-${DATE}.tar.bz2}"
82+
fi
83+
4384
ARCH_URL="${ARCH_URL:-${BASE_ARCH_URL}${DATE}/}"
44-
STAGE3="${STAGE3:-stage3-${STAGE3_ARCH}-${DATE}.tar.bz2}"
4585
STAGE3_CONTENTS="${STAGE3_CONTENTS:-${STAGE3}.CONTENTS}"
4686
STAGE3_DIGESTS="${STAGE3_DIGESTS:-${STAGE3}.DIGESTS.asc}"
4787

48-
die()
49-
{
50-
echo "$1"
51-
exit 1
52-
}
53-
5488
for FILE in "${STAGE3}" "${STAGE3_CONTENTS}" "${STAGE3_DIGESTS}"; do
5589
if [ ! -f "downloads/${FILE}" ]; then
5690
wget -O "downloads/${FILE}" "${ARCH_URL}${FILE}"

0 commit comments

Comments
 (0)