From: Kevin Carter Date: Wed, 10 Jun 2015 20:06:49 +0000 (-0500) Subject: Added container-cache option to templates X-Git-Tag: lxc-2.0.0.beta1~244^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F558%2Fhead;p=thirdparty%2Flxc.git Added container-cache option to templates This change adds in the container-cache option within the mainline default lxc templates. The pupose here is to allow a template to pull from a location that may not be `@LOCALSTATEDIR@/cache/lxc` Signed-off-by: Kevin Carter --- diff --git a/templates/lxc-centos.in b/templates/lxc-centos.in index 265b7d0f3..5e1f50be7 100644 --- a/templates/lxc-centos.in +++ b/templates/lxc-centos.in @@ -761,7 +761,8 @@ then fi fi -cache_base=@LOCALSTATEDIR@/cache/lxc/centos/$basearch +# Allow the cache base to be set by environment variable +cache_base=${LXC_CACHE_PATH:-"@LOCALSTATEDIR@/cache/lxc"}/centos/$basearch # Let's do something better for the initial root password. # It's not perfect but it will defeat common scanning brute force diff --git a/templates/lxc-cirros.in b/templates/lxc-cirros.in index 349cdbfc4..55fc257c2 100644 --- a/templates/lxc-cirros.in +++ b/templates/lxc-cirros.in @@ -58,10 +58,11 @@ am_in_userns() { in_userns=0 [ $(am_in_userns) = "yes" ] && in_userns=1 +# Allow the cache base to be set by environment variable if [ $(id -u) -eq 0 ]; then - CACHE_D="@LOCALSTATEDIR@/cache/lxc/cirros" + CACHE_D=${LXC_CACHE_PATH:-"@LOCALSTATEDIR@/cache/lxc/cirros"} else - CACHE_D="$HOME/.cache/lxc/cirros" + CACHE_D=${LXC_CACHE_PATH:-"$HOME/.cache/lxc/cirros"} fi error() { echo "$@" 1>&2; } diff --git a/templates/lxc-debian.in b/templates/lxc-debian.in index 29d4d448d..558a3495b 100644 --- a/templates/lxc-debian.in +++ b/templates/lxc-debian.in @@ -37,6 +37,8 @@ MIRROR=${MIRROR:-http://http.debian.net/debian} SECURITY_MIRROR=${SECURITY_MIRROR:-http://security.debian.org/} LOCALSTATEDIR="@LOCALSTATEDIR@" LXC_TEMPLATE_CONFIG="@LXCTEMPLATECONFIG@" +# Allows the lxc-cache directory to be set by environment variable +LXC_CACHE_PATH=${LXC_CACHE_PATH:-"$LOCALSTATEDIR/cache/lxc"} configure_debian() { @@ -293,10 +295,10 @@ copy_debian() install_debian() { - cache="$LOCALSTATEDIR/cache/lxc/debian" rootfs=$1 release=$2 arch=$3 + cache="$4/debian" mkdir -p $LOCALSTATEDIR/lock/subsys/ ( flock -x 9 @@ -412,7 +414,7 @@ EOF clean() { - cache="$LOCALSTATEDIR/cache/lxc/debian" + cache=${LXC_CACHE_PATH:-"$LOCALSTATEDIR/cache/lxc/debian"} if [ ! -e $cache ]; then exit 0 @@ -575,7 +577,7 @@ if [ -z "$rootfs" ]; then fi fi -install_debian $rootfs $release $arch +install_debian $rootfs $release $arch $LXC_CACHE_PATH if [ $? -ne 0 ]; then echo "failed to install debian" exit 1 diff --git a/templates/lxc-download.in b/templates/lxc-download.in index e0a812f6b..3be54ef1b 100644 --- a/templates/lxc-download.in +++ b/templates/lxc-download.in @@ -380,7 +380,9 @@ else LXC_CACHE_BASE="$HOME/.cache/lxc/" fi -LXC_CACHE_PATH="$LXC_CACHE_BASE/download/$DOWNLOAD_DIST" +# Allow the setting of the LXC_CACHE_PATH with the usage of environment variables. +LXC_CACHE_PATH=${LXC_CACHE_PATH:-"$LXC_CACHE_BASE"} +LXC_CACHE_PATH=$LXC_CACHE_PATH/download/$DOWNLOAD_DIST LXC_CACHE_PATH="$LXC_CACHE_PATH/$DOWNLOAD_RELEASE/$DOWNLOAD_ARCH/" LXC_CACHE_PATH="$LXC_CACHE_PATH/$DOWNLOAD_VARIANT" diff --git a/templates/lxc-fedora.in b/templates/lxc-fedora.in index e33ba337e..013546ad9 100644 --- a/templates/lxc-fedora.in +++ b/templates/lxc-fedora.in @@ -1281,7 +1281,8 @@ then fi fi -cache_base=@LOCALSTATEDIR@/cache/lxc/fedora/$basearch +# Allow the cache base to be set by environment variable +cache_base=${LXC_CACHE_PATH:-"@LOCALSTATEDIR@/cache/lxc"}/fedora/$basearch # Let's do something better for the initial root password. # It's not perfect but it will defeat common scanning brute force diff --git a/templates/lxc-gentoo.in b/templates/lxc-gentoo.in index 0a7676686..2ad16e857 100644 --- a/templates/lxc-gentoo.in +++ b/templates/lxc-gentoo.in @@ -805,6 +805,7 @@ do -w|--password) forced_password=1; password=$2; shift 2;; -s|--settings) settings=$2; shift 2;; -m|--mirror) mirror=$2; shift 2;; + --container-cache) containercache=$2; shift 2;; --tty) [[ $2 -lt 6 ]] && tty=$2; shift 2;; --autologin) autologin=1; shift 1;; --) shift 1; break ;; @@ -812,7 +813,8 @@ do esac done -cacheroot="@LOCALSTATEDIR@/cache/lxc/gentoo" +# Allow the cache path to be set by environment variable +cacheroot="${LXC_CACHE_PATH:-"@LOCALSTATEDIR@/cache/lxc"}/gentoo" portage_cache="${cacheroot}/portage.tbz" cachefs="${cacheroot}/rootfs-${arch}-${variant}" diff --git a/templates/lxc-openmandriva.in b/templates/lxc-openmandriva.in index 6123c5e5f..12f998512 100644 --- a/templates/lxc-openmandriva.in +++ b/templates/lxc-openmandriva.in @@ -42,7 +42,8 @@ export PATH=$PATH:/usr/sbin:/usr/bin:/sbin:/bin #Configurations #distro=cooker hostarch=$(uname -m) -cache_base=@LOCALSTATEDIR@/cache/lxc/openmandriva/$arch +# Allow the cache base to be set by environment variable +cache_base="${LXC_CACHE_PATH:-@LOCALSTATEDIR@/cache/lxc/openmandriva/$arch}" default_path=@LXCPATH@ default_profile=default root_password=root diff --git a/templates/lxc-opensuse.in b/templates/lxc-opensuse.in index 4ff1dcffa..7c0a40ee2 100644 --- a/templates/lxc-opensuse.in +++ b/templates/lxc-opensuse.in @@ -227,7 +227,8 @@ copy_opensuse() install_opensuse() { - cache="@LOCALSTATEDIR@/cache/lxc/opensuse/$DISTRO" + # Allow the cache base to be set by environment variable + cache="${LXC_CACHE_PATH:-@LOCALSTATEDIR@/cache/lxc/opensuse/$DISTRO}" rootfs=$1 mkdir -p @LOCALSTATEDIR@/lock/subsys/ ( @@ -350,7 +351,7 @@ EOF clean() { - cache="@LOCALSTATEDIR@/cache/lxc/opensuse" + cache="${LXC_CACHE_PATH:-@LOCALSTATEDIR@/cache/lxc/opensuse}" if [ ! -e $cache ]; then exit 0 diff --git a/templates/lxc-ubuntu-cloud.in b/templates/lxc-ubuntu-cloud.in index 92dc69148..d23adc0d6 100644 --- a/templates/lxc-ubuntu-cloud.in +++ b/templates/lxc-ubuntu-cloud.in @@ -274,10 +274,11 @@ type wget # determine the url, tarball, and directory names # download if needed -cache="$STATE_DIR/cache/lxc/cloud-$release" +# Allow the cache base to be set by environment variable +cache=${LXC_CACHE_PATH:-"$STATE_DIR/cache/lxc"}/cloud-$release if [ $in_userns -eq 1 ]; then - STATE_DIR="$HOME/.cache/lxc/" - cache="$HOME/.cache/lxc/cloud-$release" + STATE_DIR="$HOME/.cache/lxc" + cache=${LXC_CACHE_PATH:-"$STATE_DIR"}/cloud-$release fi mkdir -p $cache diff --git a/templates/lxc-ubuntu.in b/templates/lxc-ubuntu.in index 55199dc5d..a3d240089 100644 --- a/templates/lxc-ubuntu.in +++ b/templates/lxc-ubuntu.in @@ -41,6 +41,8 @@ set -e LOCALSTATEDIR="@LOCALSTATEDIR@" LXC_TEMPLATE_CONFIG="@LXCTEMPLATECONFIG@" +# Allows the lxc-cache directory to be set by environment variable +LXC_CACHE_PATH=${LXC_CACHE_PATH:-"$LOCALSTATEDIR/cache/lxc"} if [ -r /etc/default/lxc ]; then . /etc/default/lxc @@ -423,7 +425,7 @@ install_ubuntu() rootfs=$1 release=$2 flushcache=$3 - cache="$LOCALSTATEDIR/cache/lxc/$release" + cache="$4/$release" mkdir -p $LOCALSTATEDIR/lock/subsys/ ( @@ -703,6 +705,7 @@ flushcache=0 packages="" user="ubuntu" password="ubuntu" + while true do case "$1" in @@ -787,7 +790,7 @@ if [ -z "$rootfs" ]; then fi fi -install_ubuntu $rootfs $release $flushcache +install_ubuntu $rootfs $release $flushcache $LXC_CACHE_PATH if [ $? -ne 0 ]; then echo "failed to install ubuntu $release" exit 1