Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions contrib/rootfs-builder/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,27 @@ rootfs-%.tar.gz: rootfs/%/bin/echo
tar -czf $@ -C rootfs/$* .

.PRECIOUS: rootfs/%/bin/busybox
rootfs/%/bin/busybox: downloads/stage3-%-current.tar.bz2 rootfs-files
rootfs/%/bin/busybox: downloads/stage3-%-current.tar rootfs-files
gpg --verify $<.DIGESTS.asc
(cd downloads && \
grep -A1 '^# SHA512 HASH' stage3-$*-current.tar.bz2.DIGESTS.asc | \
grep -A1 '^# SHA512 HASH' stage3-$*-current.tar.DIGESTS.asc | \
grep -v '^--' | \
sha512sum -c)
sudo rm -rf rootfs/$*
sudo mkdir -p rootfs/$*
sudo tar -xvf downloads/stage3-$*-current.tar.bz2 -C rootfs/$* \
sudo tar -xvf downloads/stage3-$*-current.tar -C rootfs/$* \
--no-recursion --wildcards $$(< rootfs-files)
sudo touch $@

.PRECIOUS: rootfs/%/bin/echo
rootfs/%/bin/echo: rootfs/%/bin/busybox
sudo sh -c 'COMMANDS=$$($< --list) || exit 1; for COMMAND in $${COMMANDS}; do \
sudo sh -c 'COMMANDS=$$($< --list | grep -v "^busybox$$") || exit 1; for COMMAND in $${COMMANDS}; do \
test -L "rootfs/$*/bin/$${COMMAND}" || ln -rs $< "rootfs/$*/bin/$${COMMAND}" || exit; \
done'

downloads/stage3-%-current.tar.bz2: get-stage3.sh
downloads/stage3-%-current.tar: get-stage3.sh
STAGE3_ARCH=$* ./$<
touch downloads/stage3-$*-*.tar.bz2
touch downloads/stage3-$*-*.tar

clean:
rm -f downloads/*
Expand Down
73 changes: 60 additions & 13 deletions contrib/rootfs-builder/get-stage3.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# Download the current Gentoo stage3
#
# Copyright (C) 2014-2015 W. Trevor King <wking@tremily.us>
# Copyright (C) 2014-2018 W. Trevor King <wking@tremily.us>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -16,8 +16,36 @@
# See the License for the specific language governing permissions and
# limitations under the License.

die()
{
echo "$1"
exit 1
}

MIRROR="${MIRROR:-http://distfiles.gentoo.org/}"
STAGE3_ARCH="${STAGE3_ARCH:-amd64}"
if test -n "${STAGE3}"
then
if test -n "${STAGE3_ARCH}"
then
die 'if you set STAGE3, you do not need to set STAGE3_ARCH'
fi
if test -n "${DATE}"
then
die 'if you set STAGE3, you do not need to set DATE'
fi
STAGE3_ARCH=$(echo "${STAGE3}" | sed -n 's/stage3-\([^-]*\)-.*/\1/p')
if test -z "${STAGE3_ARCH}"
then
die "could not calculate STAGE3_ARCH from ${STAGE3}"
fi
DATE=$(echo "${STAGE3}" | sed -n "s/stage3-${STAGE3_ARCH}-\([0-9TZ]*\)[.]tar[.].*/\1/p")
if test -z "${DATE}"
then
die "could not calculate DATE from ${STAGE3}"
fi
else
STAGE3_ARCH="${STAGE3_ARCH:-amd64}"
fi

if test -z "${BASE_ARCH}"
then
Expand All @@ -38,19 +66,35 @@ then
fi

BASE_ARCH_URL="${BASE_ARCH_URL:-${MIRROR}releases/${BASE_ARCH}/autobuilds/}"
LATEST=$(wget -O - "${BASE_ARCH_URL}latest-stage3.txt")
DATE=$(echo "${LATEST}" | sed -n "s|/stage3-${STAGE3_ARCH}-[0-9]*[.]tar[.]bz2.*||p")

if test -z "${STAGE3}"
then
LATEST=$(wget -O - "${BASE_ARCH_URL}latest-stage3.txt")
if test -z "${DATE}"
then
DATE=$(echo "${LATEST}" | sed -n "s|/stage3-${STAGE3_ARCH}-[0-9TZ]*[.]tar.*||p")
if test -z "${DATE}"
then
die "could not calculate DATE from ${BASE_ARCH_URL}latest-stage3.txt"
fi
fi

STAGE3=$(echo "${LATEST}" | sed -n "s|${DATE}/\(stage3-${STAGE3_ARCH}-${DATE}[.]tar[.][^ ]*\) .*|\1|p")
if test -z "${STAGE3}"
then
die "could not calculate STAGE3 from ${BASE_ARCH_URL}latest-stage3.txt"
fi
fi

ARCH_URL="${ARCH_URL:-${BASE_ARCH_URL}${DATE}/}"
STAGE3="${STAGE3:-stage3-${STAGE3_ARCH}-${DATE}.tar.bz2}"
STAGE3_CONTENTS="${STAGE3_CONTENTS:-${STAGE3}.CONTENTS}"
STAGE3_DIGESTS="${STAGE3_DIGESTS:-${STAGE3}.DIGESTS.asc}"

die()
{
echo "$1"
exit 1
}

COMPRESSION=$(echo "${STAGE3}" | sed -n 's/^.*[.]\([^.]*\)$/\1/p')
if test -z "${COMPRESSION}"
then
die "could not calculate COMPRESSION from ${STAGE3}"
fi
for FILE in "${STAGE3}" "${STAGE3_CONTENTS}" "${STAGE3_DIGESTS}"; do
if [ ! -f "downloads/${FILE}" ]; then
wget -O "downloads/${FILE}" "${ARCH_URL}${FILE}"
Expand All @@ -60,12 +104,15 @@ for FILE in "${STAGE3}" "${STAGE3_CONTENTS}" "${STAGE3_DIGESTS}"; do
fi
fi

CURRENT=$(echo "${FILE}" | sed "s/${DATE}/current/")
FILE_NOCOMPRESSION=$(echo "${FILE}" | sed "s/[.]${COMPRESSION}//")
if [ "${FILE_NOCOMPRESSION}" = "${FILE}" ]; then
die "unable to remove .${COMPRESSION} from ${FILE}"
fi
CURRENT=$(echo "${FILE_NOCOMPRESSION}" | sed "s/${DATE}/current/")
(
cd downloads &&
rm -f "${CURRENT}" &&
ln -s "${FILE}" "${CURRENT}" ||
die "failed to link ${CURRENT} -> ${FILE}"
)
done

3 changes: 3 additions & 0 deletions contrib/rootfs-builder/rootfs-files
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
./bin/busybox
./dev
./etc/group
./etc/passwd
./proc
./sys
Binary file modified rootfs-386.tar.gz
Binary file not shown.
Binary file modified rootfs-amd64.tar.gz
Binary file not shown.