Created
March 7, 2016 18:58
-
-
Save brianredbeard/9bae454a1d42988aee82 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -e | |
# Set default values | |
: ${GENTOO_ARCH:=amd64} | |
: ${GENTOO_PROFILE:=""} | |
: ${GENTOO_PORTAGE:=no} | |
# Check for Gentoo profile, if there if a profile, add a "-" | |
if [ "${GENTOO_PROFILE}x" != "x" ]; then | |
GENTOO_PROFILE="-${GENTOO_PROFILE}" | |
fi | |
# Import the Gentoo signing keys | |
# Gentoo-keys team | |
gpg --recv-key '0x825533CBF6CD6C97' | |
# Gentoo automated weekly release key | |
gpg --recv-key '0xBB572E0E2D182910' | |
# Identify the current Gentoo version | |
GENTOO_CUR=`curl -s http://distfiles.gentoo.org/releases/${GENTOO_ARCH}/autobuilds/latest-stage3-${GENTOO_ARCH}${GENTOO_PROFILE}.txt | awk '/stage3/ {print $1}'` | |
GENTOO_BZIP=${GENTOO_CUR##*/} | |
GENTOO_TAR=${GENTOO_BZIP%%.bz2} | |
# Pull down the Gentoo stage3 image | |
if [ ! -e ${GENTOO_BZIP} ]; then | |
echo "Downloading Gentoo Stage 3 (${GENTOO_BZIP})" | |
curl -O http://distfiles.gentoo.org/releases/${GENTOO_ARCH}/autobuilds/current-stage3-${GENTOO_ARCH}${GENTOO_PROFILE}/${GENTOO_BZIP} | |
echo "Downloading Gentoo digests" | |
curl -O http://distfiles.gentoo.org/releases/${GENTOO_ARCH}/autobuilds/current-stage3-${GENTOO_ARCH}${GENTOO_PROFILE}/${GENTOO_BZIP}.DIGESTS | |
echo "Downloading Gentoo digests (detached signature)" | |
curl -O http://distfiles.gentoo.org/releases/${GENTOO_ARCH}/autobuilds/current-stage3-${GENTOO_ARCH}${GENTOO_PROFILE}/${GENTOO_BZIP}.DIGESTS.asc | |
gpg --verify ${GENTOO_BZIP}.DIGESTS.asc | |
EXIT_CODE=$? | |
if [ "${EXIT_CODE}" != "0" ]; then | |
echo "Digest file failed GPG validation (Exit code: ${EXIT_CODE})." | |
exit ${EXIT_CODE} | |
fi | |
# Check to ensure that the images were signed with the proper release key | |
echo "Validating hashes" | |
grep -A1 SHA512 ${GENTOO_BZIP}.DIGESTS.asc | awk "/${GENTOO_BZIP}$/ {print \$0}" | sha512sum -c - | |
EXIT_CODE=$? | |
if [ "${EXIT_CODE}" != "0" ]; then | |
echo "Payload file failed SHA512 validation (Exit code: ${EXIT_CODE})." | |
exit ${EXIT_CODE} | |
fi | |
fi | |
# If the rootfs does not exist, then explode the corresponding tarball | |
# and install the Gentoo portage tree into the correct location | |
if [ ! -d "rootfs" ]; then | |
echo "Creating rootfs" | |
mkdir -p rootfs | |
set +e | |
echo "Exploding stage3 to rootfs" | |
tar jxpf ${GENTOO_BZIP} -C rootfs --xattrs | |
set -e | |
mkdir -p rootfs/usr/portage | |
if [ "${GENTOO_PORTAGE}x" != "x" ]; then | |
echo "Performing rsync of portage tree" | |
rsync -az rsync://rsync.us.gentoo.org/gentoo-portage rootfs/usr/portage/ | |
echo "Completed rsync of portage tree" | |
fi | |
fi | |
# Begin operations to finish packaging our assets into ACI format | |
echo "Writing ACI manifest" | |
echo "{\"acKind\":\"ImageManifest\",\"acVersion\":\"0.7.4\",\"name\":\"${GENTOO_TAR%%.tar}\",\"labels\":[{\"name\":\"os\",\"value\":\"linux\"},{\"name\":\"arch\",\"value\":\"${GENTOO_ARCH}\"}],\"app\":{\"exec\":[\"/bin/bash\"],\"user\":\"0\",\"group\":\"0\"}}" > manifest | |
echo "Building ACI image" | |
tar Jcpf ${GENTOO_TAR%%.tar}.aci --xattrs rootfs manifest | |
echo "Built Image ${GENTOO_TAR%%.tar}.aci" | |
# some common packages needed to build subsequent packages include: | |
# dev-vcs/git | |
# sys-devel/bc | |
# app-arch/cpio |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It might be nice to be mirror-aware with this :)