Closed nephros closed 12 years ago
This is a clumsy modification to the lxc-gentoo script I use to run the x32 stage3 in a container.
It allows a new -C URL parameter which will fetch and unpack custom tarballs.
Test with "lxc-gentoo-custom create -i dhcp -a amd64 -n lxc_x32 -u lxc_x32 -C http://dev.gentoo.org/~vapier/x32/stage3-amd64-x32-20120605.tar.xz
--- lxc-gentoo 2012-06-18 12:19:09.000000000 +0200
+++ lxc-gentoo-custom 2012-06-18 19:37:27.000000000 +0200
@@ -380,13 +380,18 @@
# make unique variables for x86 and amd64 since stage3 url are different
echo -n "Generating strings to run... "
- if [ $ARCH == 'x86' ]; then
- STAGE3SED="s/.*stage3-${SUBARCH}-\(........\)\.tar\.bz2.*/\1/p"
- STAGE3URL="http://distfiles.gentoo.org/releases/${ARCH}/autobuilds/current-stage3/stage3-${SUBARCH}"
- else
- STAGE3SED="s/.*stage3-${ARCH}-\(........\)\.tar\.bz2.*/\1/p"
- STAGE3URL="http://distfiles.gentoo.org/releases/${ARCH}/autobuilds/current-stage3/stage3-${ARCH}"
- fi
+ if [ x"$CUSTOMURL" = x"" ]; then
+ if [ $ARCH == 'x86' ]; then
+ STAGE3SED="s/.*stage3-${SUBARCH}-\(........\)\.tar\.bz2.*/\1/p"
+ STAGE3URL="http://distfiles.gentoo.org/releases/${ARCH}/autobuilds/current-stage3/stage3-${SUBARCH}"
+ else
+ STAGE3SED="s/.*stage3-${ARCH}-\(........\)\.tar\.bz2.*/\1/p"
+ STAGE3URL="http://distfiles.gentoo.org/releases/${ARCH}/autobuilds/current-stage3/stage3-${ARCH}"
+ fi
+ else
+ STAGE3SED="s/.*stage3-${ARCH}-\(........\)\.tar\.[xb]z[2].*/\1/p"
+ STAGE3URL=$CUSTOMURL
+ fi
echo -n "Determining latest ${DISTRO} ${ARCH} stage3 archive... "
mkdir -p ${CACHE} 1>/dev/null 2>/dev/null
@@ -394,7 +399,12 @@
echo ${LATEST_STAGE3_TIMESTAMP}
echo -n "Downloading (~120MB), please wait... "
- ${WGET} -O ${CACHE}/stage3-${ARCH}-${LATEST_STAGE3_TIMESTAMP}.tar.bz2 "${STAGE3URL}-${LATEST_STAGE3_TIMESTAMP}.tar.bz2" 1>/dev/null 2>/dev/null
+ if [ x"$CUSTOMURL" = x"" ]; then
+ ${WGET} -O ${CACHE}/stage3-${ARCH}-${LATEST_STAGE3_TIMESTAMP}.tar.bz2 "${STAGE3URL}-${LATEST_STAGE3_TIMESTAMP}.tar.bz2" 1>/dev/null 2>/dev/null
+ else
+ echo ${WGET} -O ${CACHE}/"${CUSTOMURL##*/}" "${CUSTOMURL}"
+ ${WGET} -O ${CACHE}/"${CUSTOMURL##*/}" "${CUSTOMURL}" 1>/dev/null 2>/dev/null
+ fi
RESULT=$?
if [ "${RESULT}" != "0" ]; then
@@ -408,7 +418,16 @@
mkdir -p "${TEMPLATE}" #1>/dev/null 2>/dev/null
echo -n "Extracting stage3 archive... "
- tar -jxf ${CACHE}/stage3-${ARCH}-${LATEST_STAGE3_TIMESTAMP}.tar.bz2 -C "${TEMPLATE}" 1>/dev/null 2>/dev/null
+ if [ x"$CUSTOMURL" = x"" ]; then
+ tar -jxf ${CACHE}/stage3-${ARCH}-${LATEST_STAGE3_TIMESTAMP}.tar.bz2 -C "${TEMPLATE}" 1>/dev/null 2>/dev/null
+ else
+ tar xvf ${CACHE}/"${CUSTOMURL##*/}" -C "${TEMPLATE}" 1>/dev/null 2>/dev/null
+ fi
+ RESULT=$?
+ if [ "${RESULT}" != "0" ]; then
+ echo "failed!"
+ exit 1
+ fi
echo "done."
echo -n "Downloading ${DISTRO} portage (software database) snapshot... "
rm -f ${CACHE}/portage-latest.tar.bz2 1>/dev/null 2>/dev/null
@@ -524,6 +543,9 @@
-p GUESTROOTPASS : password for root account
Env. Var.: GUESTROOTPASS
Current/Default: ${GUESTROOTPASS}
+ -C CUSTOMURL : URL for a custom tarball
+ Env. Var.: CUSTOMURL
+ Current/Default: ${CUSTOMURL}
This script is a helper to create ${DISTRO} system containers.
@@ -587,7 +609,7 @@
CACHE="/var/cache/lxc/${DISTRO}"
OPTIND=2
-while getopts "i:g:n:u:a:p:q" opt
+while getopts "i:g:n:u:a:p:qC:" opt
do
case $opt in
i) IPV4=$OPTARG ;;
@@ -595,6 +617,7 @@
n) NAME=$OPTARG ;;
u) UTSNAME=$OPTARG ;;
a) ARCH=$OPTARG ;;
+ C) CUSTOMURL=$OPTARG;;
p) GUESTROOTPASS=$OPTARG ;;
q) QUIET=Yes ;;
\?) ;;
While I support the feature request this patchfile won't apply cleanly to the latest code on git. If you can supply the same changes as a pull request against the current codebase, I will happily apply it for you.
It would be nice if we could use arbitrary stage tarballs to be used for creation. This would allow for easy deployment of custom setups.