lxc-download.in revision 207bf0e475f1dc6e9a2dac2cee3a209b56427855
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber# Client script for LXC container images.
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber# Copyright © 2014 Stéphane Graber <stgraber@ubuntu.com>
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber# This library is free software; you can redistribute it and/or
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber# modify it under the terms of the GNU Lesser General Public
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber# License as published by the Free Software Foundation; either
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber# version 2.1 of the License, or (at your option) any later version.
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber# This library is distributed in the hope that it will be useful,
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber# but WITHOUT ANY WARRANTY; without even the implied warranty of
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber# Lesser General Public License for more details.
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber# You should have received a copy of the GNU Lesser General Public
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber# License along with this library; if not, write to the Free Software
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
4eb706b3ce9891f86ff3f9b5b5d063922df9f6b6Stéphane GraberDOWNLOAD_KEYSERVER="hkp://pool.sks-keyservers.net"
4eb706b3ce9891f86ff3f9b5b5d063922df9f6b6Stéphane Graber# Deal with GPG over http proxy
4eb706b3ce9891f86ff3f9b5b5d063922df9f6b6Stéphane Graberif [ -n "${http_proxy:-}" ]; then
4eb706b3ce9891f86ff3f9b5b5d063922df9f6b6Stéphane Graber DOWNLOAD_KEYSERVER="${DOWNLOAD_KEYSERVER}:80"
207bf0e475f1dc6e9a2dac2cee3a209b56427855Stéphane Graber# Make sure the usual locations are in PATH
207bf0e475f1dc6e9a2dac2cee3a209b56427855Stéphane Graberexport PATH=$PATH:/usr/sbin:/usr/bin:/sbin:/bin
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber# Some useful functions
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber if ! wget -q https://${DOWNLOAD_SERVER}/$1 -O $2 >/dev/null 2>&1; then
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber if ! wget -q http://${DOWNLOAD_SERVER}/$1 -O $2 >/dev/null 2>&1; then
fad967669817061cda3aafc40be04dcb712a4767Dwight Engen echo "ERROR: Failed to download http://${DOWNLOAD_SERVER}/$1" 1>&2
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber elif [ "$DOWNLOAD_SHOW_HTTP_WARNING" = "true" ]; then
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber echo "WARNING: Failed to download the file over HTTPs." 1>&2
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber echo -n " The file was instead download over HTTP. " 1>&2
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber echo "A server replay attack may be possible!" 1>&2
33aa351ac13936fb2549403f18a44fed32b2edfbStéphane Graber if ! download_file $1 $2 noexit; then
33aa351ac13936fb2549403f18a44fed32b2edfbStéphane Graber echo "ERROR: Failed to download http://${DOWNLOAD_SERVER}/$1" 1>&2
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber --recv-keys ${DOWNLOAD_KEYID} >/dev/null 2>&1; then
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber echo "ERROR: Unable to fetch GPG key from keyserver."
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber if [ "$DOWNLOAD_SHOW_GPG_WARNING" = "true" ]; then
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber echo "WARNING: Running without gpg validation!" 1>&2
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber if ! gpg --verify $1 >/dev/zero 2>&1; then
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber [ -e /proc/self/uid_map ] || { echo no; return; }
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber [ "$(wc -l /proc/self/uid_map | awk '{ print $1 }')" -eq 1 ] || \
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber line=$(awk '{ print $1 " " $2 " " $3 }' /proc/self/uid_map)
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber [ "$line" = "0 0 4294967295" ] && { echo no; return; }
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber if [ -e "${FILE_PATH}-${DOWNLOAD_MODE}" ]; then
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber if [ -e "$FILE_PATH.${DOWNLOAD_COMPAT_LEVEL}" ]; then
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber FILE_PATH="${FILE_PATH}.${DOWNLOAD_COMPAT_LEVEL}"
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane GraberLXC container image downloader
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane GraberRequired arguments:
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber[ -d | --dist <distribution> ]: The name of the distribution
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber[ -r | --release <release> ]: Release name/version
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber[ -a | --arch <architecture> ]: Architecture of the container
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane GraberOptional arguments:
10a5fab6f3ad5cab234b198da31633e41c8ee364Stéphane Graber[ -h | --help ]: This help message
10a5fab6f3ad5cab234b198da31633e41c8ee364Stéphane Graber[ -l | --list ]: List all available images
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber[ --variant <variant> ]: Variant of the image (default: "default")
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber[ --server <server> ]: Image server (default: "images.linuxcontainers.org")
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber[ --keyid <keyid> ]: GPG keyid (default: 0x...)
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber[ --keyserver <keyserver> ]: GPG keyserver to use
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber[ --no-validate ]: Disable GPG validation (not recommended)
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber[ --flush-cache ]: Flush the local copy (if present)
9accc2efea59a685942501c13e8eb7a21f74a5f6Stéphane Graber[ --force-cache ]; Force the use of the local copy even if expired
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane GraberLXC internal arguments (do not pass manually!):
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber[ --name <name> ]: The container name
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber[ --path <path> ]: The path to the container
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber[ --rootfs <rootfs> ]: The path to the container's rootfs
2133f58c66ab7627a4159fafbb75106c556b014dSerge Hallyn[ --mapped-uid <map> ]: A uid map (user namespaces)
2133f58c66ab7627a4159fafbb75106c556b014dSerge Hallyn[ --mapped-gid <map> ]: A gid map (user namespaces)
10a5fab6f3ad5cab234b198da31633e41c8ee364Stéphane Graberoptions=$(getopt -o d:r:a:hl -l dist:,release:,arch:,help,list,variant:,\
c1becef2d2d96ce2c782d2b0eb19b24dcd6026d9Stéphane Graberserver:,keyid:,no-validate,flush-cache,force-cache,name:,path:,\
10a5fab6f3ad5cab234b198da31633e41c8ee364Stéphane Graber -l|--list) DOWNLOAD_LIST_IMAGES="true"; shift 1;;
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber -r|--release) DOWNLOAD_RELEASE=$2; shift 2;;
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber --no-validate) DOWNLOAD_VALIDATE="false"; shift 1;;
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber --flush-cache) DOWNLOAD_FLUSH_CACHE="true"; shift 1;;
9accc2efea59a685942501c13e8eb7a21f74a5f6Stéphane Graber --force-cache) DOWNLOAD_FORCE_CACHE="true"; shift 1;;
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber# Check for required binaries
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber echo "ERROR: Missing required tool: $bin" 1>&2
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber# Check for GPG
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber echo "ERROR: Missing recommended tool: gpg" 1>&2
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber echo "You can workaround this by using --no-validate." 1>&2
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber# Check that we have all variables we need
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graberif [ -z "$LXC_NAME" ] || [ -z "$LXC_PATH" ] || [ -z "$LXC_ROOTFS" ]; then
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber if [ -z "$LXC_MAPPED_UID" ] || [ "$LXC_MAPPED_UID" = "-1" ]; then
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber echo "ERROR: In a user namespace without a map." 1>&2
b0f0932a944abf6425e9f185dea9c6d9ba6e8436Stéphane Graberif [ -z "$DOWNLOAD_DIST" ] || [ -z "$DOWNLOAD_RELEASE" ] || \
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber# Trap all exit signals
10a5fab6f3ad5cab234b198da31633e41c8ee364Stéphane Graber# Simply list images
10a5fab6f3ad5cab234b198da31633e41c8ee364Stéphane Graber # Initialize GPG
10a5fab6f3ad5cab234b198da31633e41c8ee364Stéphane Graber # Grab the index
10a5fab6f3ad5cab234b198da31633e41c8ee364Stéphane Graber DOWNLOAD_INDEX_PATH=/meta/1.0/index-${DOWNLOAD_MODE}
10a5fab6f3ad5cab234b198da31633e41c8ee364Stéphane Graber echo "Downloading the image index"
10a5fab6f3ad5cab234b198da31633e41c8ee364Stéphane Graber if ! download_file ${DOWNLOAD_INDEX_PATH}.${DOWNLOAD_COMPAT_LEVEL} \
10a5fab6f3ad5cab234b198da31633e41c8ee364Stéphane Graber ! download_sig ${DOWNLOAD_INDEX_PATH}.${DOWNLOAD_COMPAT_LEVEL}.asc \
10a5fab6f3ad5cab234b198da31633e41c8ee364Stéphane Graber download_file ${DOWNLOAD_INDEX_PATH} ${DOWNLOAD_TEMP}/index normal
10a5fab6f3ad5cab234b198da31633e41c8ee364Stéphane Graber echo "DIST\tRELEASE\tARCH\tVARIANT\tBUILD"
10a5fab6f3ad5cab234b198da31633e41c8ee364Stéphane Graber while read line; do
10a5fab6f3ad5cab234b198da31633e41c8ee364Stéphane Graber # Basic CSV parser
10a5fab6f3ad5cab234b198da31633e41c8ee364Stéphane Graber [ -n "$DOWNLOAD_DIST" ] && [ "$1" != "$DOWNLOAD_DIST" ] && continue
10a5fab6f3ad5cab234b198da31633e41c8ee364Stéphane Graber [ -n "$DOWNLOAD_RELEASE" ] && [ "$2" != "$DOWNLOAD_RELEASE" ] && continue
10a5fab6f3ad5cab234b198da31633e41c8ee364Stéphane Graber [ -n "$DOWNLOAD_ARCH" ] && [ "$3" != "$DOWNLOAD_ARCH" ] && continue
10a5fab6f3ad5cab234b198da31633e41c8ee364Stéphane Graber [ -n "$DOWNLOAD_VARIANT" ] && [ "$4" != "$DOWNLOAD_VARIANT" ] && continue
10a5fab6f3ad5cab234b198da31633e41c8ee364Stéphane Graber echo "$1\t$2\t$3\t$4\t$5"
b0f0932a944abf6425e9f185dea9c6d9ba6e8436Stéphane Graber if [ "$DOWNLOAD_LIST_IMAGES" = "true" ]; then
b0f0932a944abf6425e9f185dea9c6d9ba6e8436Stéphane Graber # Interactive mode
b0f0932a944abf6425e9f185dea9c6d9ba6e8436Stéphane Graber if [ -z "$DOWNLOAD_DIST" ]; then
b0f0932a944abf6425e9f185dea9c6d9ba6e8436Stéphane Graber echo -n "Distribution: "
b0f0932a944abf6425e9f185dea9c6d9ba6e8436Stéphane Graber if [ -z "$DOWNLOAD_RELEASE" ]; then
b0f0932a944abf6425e9f185dea9c6d9ba6e8436Stéphane Graber echo -n "Release: "
b0f0932a944abf6425e9f185dea9c6d9ba6e8436Stéphane Graber if [ -z "$DOWNLOAD_ARCH" ]; then
b0f0932a944abf6425e9f185dea9c6d9ba6e8436Stéphane Graber echo -n "Architecture: "
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber# Setup the cache
b56661fead638d40eaee54d9134063098e4fa51cStéphane GraberLXC_CACHE_PATH="$LXC_CACHE_BASE/download/$DOWNLOAD_DIST"
b56661fead638d40eaee54d9134063098e4fa51cStéphane GraberLXC_CACHE_PATH="$LXC_CACHE_PATH/$DOWNLOAD_RELEASE/$DOWNLOAD_ARCH/"
b56661fead638d40eaee54d9134063098e4fa51cStéphane GraberLXC_CACHE_PATH="$LXC_CACHE_PATH/$DOWNLOAD_VARIANT"
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graberif [ -d "$LXC_CACHE_PATH" ]; then
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber if [ "$DOWNLOAD_FLUSH_CACHE" = "true" ]; then
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber echo "Flushing the cache..."
9accc2efea59a685942501c13e8eb7a21f74a5f6Stéphane Graber elif [ "$DOWNLOAD_FORCE_CACHE" = "true" ]; then
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber if [ "$(cat $(relevant_file expiry))" -lt $(date +%s) ]; then
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber echo "The cached copy has expired, re-downloading..."
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber# Download what's needed
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber # Initialize GPG
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber # Grab the index
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber DOWNLOAD_INDEX_PATH=/meta/1.0/index-${DOWNLOAD_MODE}
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber echo "Downloading the image index"
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber if ! download_file ${DOWNLOAD_INDEX_PATH}.${DOWNLOAD_COMPAT_LEVEL} \
33aa351ac13936fb2549403f18a44fed32b2edfbStéphane Graber ! download_sig ${DOWNLOAD_INDEX_PATH}.${DOWNLOAD_COMPAT_LEVEL}.asc \
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber download_file ${DOWNLOAD_INDEX_PATH} ${DOWNLOAD_TEMP}/index normal
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber while read line; do
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber # Basic CSV parser
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber [ -z "$6" ]; then
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber if [ -z "$DOWNLOAD_URL" ]; then
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber echo "ERROR: Couldn't find a matching image." 1>&1
9accc2efea59a685942501c13e8eb7a21f74a5f6Stéphane Graber if [ -d "$LXC_CACHE_PATH" ] && [ -f "$LXC_CACHE_PATH/build_id" ] && \
9accc2efea59a685942501c13e8eb7a21f74a5f6Stéphane Graber [ "$(cat $LXC_CACHE_PATH/build_id)" = "$DOWNLOAD_BUILD" ]; then
9accc2efea59a685942501c13e8eb7a21f74a5f6Stéphane Graber echo "The cache is already up to date."
9accc2efea59a685942501c13e8eb7a21f74a5f6Stéphane Graber echo "Using image from local cache"
9accc2efea59a685942501c13e8eb7a21f74a5f6Stéphane Graber # Download the actual files
9accc2efea59a685942501c13e8eb7a21f74a5f6Stéphane Graber echo "Downloading the rootfs"
9accc2efea59a685942501c13e8eb7a21f74a5f6Stéphane Graber download_sig $DOWNLOAD_URL/rootfs.tar.xz.asc \
9accc2efea59a685942501c13e8eb7a21f74a5f6Stéphane Graber gpg_validate ${DOWNLOAD_TEMP}/rootfs.tar.xz.asc
9accc2efea59a685942501c13e8eb7a21f74a5f6Stéphane Graber echo "Downloading the metadata"
9accc2efea59a685942501c13e8eb7a21f74a5f6Stéphane Graber download_sig $DOWNLOAD_URL/meta.tar.xz.asc \
9accc2efea59a685942501c13e8eb7a21f74a5f6Stéphane Graber gpg_validate ${DOWNLOAD_TEMP}/meta.tar.xz.asc
9accc2efea59a685942501c13e8eb7a21f74a5f6Stéphane Graber mv ${DOWNLOAD_TEMP}/rootfs.tar.xz $LXC_CACHE_PATH
9accc2efea59a685942501c13e8eb7a21f74a5f6Stéphane Graber if ! tar Jxf ${DOWNLOAD_TEMP}/meta.tar.xz -C $LXC_CACHE_PATH; then
9accc2efea59a685942501c13e8eb7a21f74a5f6Stéphane Graber echo $DOWNLOAD_BUILD > $LXC_CACHE_PATH/build_id
9accc2efea59a685942501c13e8eb7a21f74a5f6Stéphane Graber if [ -n "$LXC_MAPPED_UID" ] && [ "$LXC_MAPPED_UID" != "-1" ]; then
0d656b0549e67635ad9c24474b82dfa26e1f4512Stéphane Graber chown -R $LXC_MAPPED_UID $LXC_CACHE_BASE >/dev/null 2>&1 || true
2133f58c66ab7627a4159fafbb75106c556b014dSerge Hallyn if [ -n "$LXC_MAPPED_GID" ] && [ "$LXC_MAPPED_GID" != "-1" ]; then
2133f58c66ab7627a4159fafbb75106c556b014dSerge Hallyn chgrp -R $LXC_MAPPED_GID $LXC_CACHE_BASE >/dev/null 2>&1 || true
9accc2efea59a685942501c13e8eb7a21f74a5f6Stéphane Graber echo "The image cache is now ready"
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber echo "Using image from local cache"
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber# Unpack the rootfs
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graberecho "Unpacking the rootfs"
fecf101cc4352e9bf60ed3477196146a65b5c4f6Stéphane Graberif [ -f "${excludelist}" ]; then
fecf101cc4352e9bf60ed3477196146a65b5c4f6Stéphane Graber while read line; do
fecf101cc4352e9bf60ed3477196146a65b5c4f6Stéphane Grabertar --anchored ${EXCLUDES} --numeric-owner -xpJf \
fecf101cc4352e9bf60ed3477196146a65b5c4f6Stéphane Graber ${LXC_CACHE_PATH}/rootfs.tar.xz -C ${LXC_ROOTFS}
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber# Setup the configuration
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graberif [ ! -e $configfile ]; then
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber echo "ERROR: meta tarball is missing the configuration file" 1>&2
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber## Extract all the network config entries
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Grabersed -i -e "/lxc.network/{w ${LXC_PATH}/config-network" -e "d}" \
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber## Extract any other config entry
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Grabersed -i -e "/lxc./{w ${LXC_PATH}/config-auto" -e "d}" ${LXC_PATH}/config
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber## Append the defaults
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graberecho "# Distribution configuration" >> ${LXC_PATH}/config
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber## Add the container-specific config
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graberecho "# Container specific configuration" >> ${LXC_PATH}/config
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graberif [ -e "${LXC_PATH}/config-auto" ]; then
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber cat ${LXC_PATH}/config-auto >> ${LXC_PATH}/config
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graberif [ -e "$fstab" ]; then
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber echo "lxc.mount = ${LXC_PATH}/fstab" >> ${LXC_PATH}/config
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graberecho "lxc.utsname = ${LXC_NAME}" >> ${LXC_PATH}/config
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber## Re-add the previously removed network config
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graberif [ -e "${LXC_PATH}/config-network" ]; then
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber echo "# Network configuration" >> ${LXC_PATH}/config
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber cat ${LXC_PATH}/config-network >> ${LXC_PATH}/config
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber# Setup the fstab
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graberif [ -e $fstab ]; then
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber TEMPLATE_FILES="$TEMPLATE_FILES ${LXC_PATH}/fstab"
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber# Look for extra templates
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber while read line; do
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber [ ! -e "$fullpath" ] && continue
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber# Replace variables in all templates
fad967669817061cda3aafc40be04dcb712a4767Dwight Engen [ ! -f "$file" ] && continue
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber sed -i "s#LXC_TEMPLATE_CONFIG#$LXC_TEMPLATE_CONFIG#g" $file
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graber sed -i "s#LXC_HOOK_DIR#$LXC_HOOK_DIR#g" $file
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graberif [ -n "$LXC_MAPPED_UID" ] && [ "$LXC_MAPPED_UID" != "-1" ]; then
0d656b0549e67635ad9c24474b82dfa26e1f4512Stéphane Graber chown $LXC_MAPPED_UID $LXC_PATH/config $LXC_PATH/fstab >/dev/null 2>&1 || true
2133f58c66ab7627a4159fafbb75106c556b014dSerge Hallynif [ -n "$LXC_MAPPED_GID" ] && [ "$LXC_MAPPED_GID" != "-1" ]; then
2133f58c66ab7627a4159fafbb75106c556b014dSerge Hallyn chgrp $LXC_MAPPED_GID $LXC_PATH/config $LXC_PATH/fstab >/dev/null 2>&1 || true
71d3a6590fe665421d7a0026d699b0654ddfc7f6Stéphane Graberif [ -e "$(relevant_file create-message)" ]; then