]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
Added container-cache option to templates 558/head
authorKevin Carter <kevin.carter@rackspace.com>
Wed, 10 Jun 2015 20:06:49 +0000 (15:06 -0500)
committerKevin Carter <kevin.carter@rackspace.com>
Thu, 11 Jun 2015 16:21:17 +0000 (11:21 -0500)
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 <kevin.carter@rackspace.com>
templates/lxc-centos.in
templates/lxc-cirros.in
templates/lxc-debian.in
templates/lxc-download.in
templates/lxc-fedora.in
templates/lxc-gentoo.in
templates/lxc-openmandriva.in
templates/lxc-opensuse.in
templates/lxc-ubuntu-cloud.in
templates/lxc-ubuntu.in

index 265b7d0f36a410ecf511512902e0fb4ee83e751f..5e1f50be7a4f5ea334e64ae68c21a42e95b3eeba 100644 (file)
@@ -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
index 349cdbfc474815add9acf7de54f82cfe4ca738fc..55fc257c2a2bbace2a5af089592b98740ea9b714 100644 (file)
@@ -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; }
index 29d4d448def6c2aa3e29b0ff0402c98f39bdf633..558a3495bc4ba73725ab53ecb42e207c728325ab 100644 (file)
@@ -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
index e0a812f6b9dea0edba4efda3d7c726b4eb7dc9ec..3be54ef1ba520fa61585a1021922f4f182360545 100644 (file)
@@ -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"
 
index e33ba337ece6995165236145bff34999edb97b74..013546ad9f257a82a48ae3e1f517af0fcc53d465 100644 (file)
@@ -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
index 0a767668669973bd145aef5cf24bc10cbfd0b741..2ad16e85783d1c043ebaebe3969e4f9a8c50a312 100644 (file)
@@ -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}"
 
index 6123c5e5f721a620b291b14610cbeaf2b9e6a2e3..12f998512da48784f69b42c5aad27aa1afa0656c 100644 (file)
@@ -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
index 4ff1dcffa7c11db80c966367d7102accbd980a11..7c0a40ee2cb190973ea20d8cce1eb6dc965085d5 100644 (file)
@@ -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
index 92dc69148ea64b2fb7b1f60fe6b73d9012542b7f..d23adc0d6f4c3b58d4797966986bda0557491bf3 100644 (file)
@@ -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
index 55199dc5ddaba6503da993cedd7dd9ef94b6c58d..a3d2400895f4d12e50f078686ff886d27649ca2b 100644 (file)
@@ -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