f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr#!/bin/bash
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr#
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr# LXC template for gentoo
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr#
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr# Author: Guillaume Zitta <lxc@zitta.fr>
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr#
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr# Widely inspired from lxc-gentoo script at https://github.com/globalcitizen/lxc-gentoo
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr#
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr# this version is reworked with :
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr# - out of the lxc-create compat
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr# - vanilla gentoo config
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr# - ready to use cache
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr#
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
8ec981fc8b0105da5f071e40811e0c2472a6c3c9Stéphane Graber# Detect use under userns (unsupported)
c63c04fcaf1c3a78c70500eae253d72fa9c8358aTAMUKI Shoichifor arg in "$@"; do
96283b546081e7ff709968378fca25cb44f1ab6cStéphane Graber [ "$arg" = "--" ] && break
96283b546081e7ff709968378fca25cb44f1ab6cStéphane Graber if [ "$arg" = "--mapped-uid" -o "$arg" = "--mapped-gid" ]; then
8ec981fc8b0105da5f071e40811e0c2472a6c3c9Stéphane Graber echo "This template can't be used for unprivileged containers." 1>&2
8ec981fc8b0105da5f071e40811e0c2472a6c3c9Stéphane Graber echo "You may want to try the \"download\" template instead." 1>&2
8ec981fc8b0105da5f071e40811e0c2472a6c3c9Stéphane Graber exit 1
8ec981fc8b0105da5f071e40811e0c2472a6c3c9Stéphane Graber fi
8ec981fc8b0105da5f071e40811e0c2472a6c3c9Stéphane Graberdone
8ec981fc8b0105da5f071e40811e0c2472a6c3c9Stéphane Graber
207bf0e475f1dc6e9a2dac2cee3a209b56427855Stéphane Graber# Make sure the usual locations are in PATH
207bf0e475f1dc6e9a2dac2cee3a209b56427855Stéphane Graberexport PATH=$PATH:/usr/sbin:/usr/bin:/sbin:/bin
207bf0e475f1dc6e9a2dac2cee3a209b56427855Stéphane Graber
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr# Ensure strict root's umask doesen't render the VM unusable
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.frumask 022
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
cae3584efccc63f544c8748bd13d80e11bc79aefgzaLXC_TEMPLATE_CONFIG="@LXCTEMPLATECONFIG@"
cae3584efccc63f544c8748bd13d80e11bc79aefgza
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr################################################################################
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr# Various helper functions
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr################################################################################
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr# param: $1: the name of the lock
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr# param: $2: the timeout for the lock
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr# The rest contain the command to execute and its parameters
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.frexecute_exclusively()
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr{
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr mkdir -p @LOCALSTATEDIR@/lock/subsys/
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr local lock_name="$1"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr local timeout="$2"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr shift 2
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr {
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr printf "Attempting to obtain an exclusive lock (timeout: %s sec) named \"%s\"...\n" "${timeout}" "$lock_name"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr flock -x -w "${timeout}" 50
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr if [[ $? -ne 0 ]]; then
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr printf " => unable to obtain lock, aborting.\n"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr return 2
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr else
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr printf " => done.\n"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr fi
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr printf " => Executing \"%s\"\n" "$*"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr "$@"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr retval=$?
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr } 50> "@LOCALSTATEDIR@/lock/subsys/lxc-gentoo-${lock_name}"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr return $retval
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr}
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr# a die function is always a good idea
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.frdie()
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr{
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr printf "\n[the last exit code leading to this death was: %s ]\n" "$?"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr local retval="$1"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr shift 1
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr printf "$@"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr exit "$retval"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr}
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr# gentoo arch/variant detection
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.frset_default_arch()
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr{
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr printf "### set_default_arch: default arch/variant autodetect...\n"
4849ab991b31b90fab06848366f08d689983ad89Michael Werner arch=$(uname -m)
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr if [[ $arch =~ i.86 ]]; then
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr arch="x86"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr variant="x86"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr elif [[ $arch == "x86_64" ]]; then
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr arch="amd64"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr variant="amd64"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr elif [[ $arch =~ arm.* ]]; then
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr arch="arm"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr variant="armv7a"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr else
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr #who knows, it may work...
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr printf " => warn: unexpected arch:${arch} let me knows if it works :)\n"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr variant="${arch}"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr fi
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr printf " => Got: arch=%s variant=%s\n" "${arch}" "${variant}"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr}
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.frstore_user_message()
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr{
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr user_message="${user_message}=> $@\n"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr}
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr################################################################################
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr# CACHE Preparation
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr################################################################################
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr# during setup cachedir is $cacheroot/partial-$arch-$variant
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr# at the end, it will be $cacheroot/rootfs-$arch-$variant
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.frcache_setup(){
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr partialfs="${cacheroot}/partial-${arch}-${variant}"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr #if cache exists and flush not needed, return
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr [[ -d "${cachefs}" && -z "${flush_cache}" ]] && return 0
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr printf "###### cache_setup(): doing cache preparation\n"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr local retval=1
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr #clean from failed previous run
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr rm -rf "${partialfs}"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr mkdir -p "${partialfs}"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr #let's go
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr cache_precheck && \
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr cache_stage3 && \
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr cache_portage && \
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr cache_inittab && \
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr cache_net && \
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr cache_dev && \
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr cache_openrc && \
3a74e9097a932729d9eff9ce562288e89731b177Guillaume ZITTA cache_locale && \
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr rm -rf "${cachefs}" && \
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr mv "${partialfs}" "${cachefs}" && \
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr printf "###### cache_setup: Cache should be ready\n"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr return $?
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr}
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.frcache_precheck()
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr{
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr printf "### cache_precheck(): doing some pre-start checks ...\n"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr # never hurts to have a fail-safe.
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr [[ -n "${cacheroot//\/}" ]] \
ec64264d78d4ed608553842ce9e1f07eeab2a032Veres Lajos || die 8 "\$cacheroot (%s) IS EMPTY OR MADE OF ONLY DIRECTORY SEPARATORS, THIS IS *VERY* BAD!\n" "${cacheroot}"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr}
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr#get latest stage3 tarball
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.frcache_stage3()
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr{
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr printf "### cache_stage3(): stage3 cache deployment...\n"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr if [ -z "${tarball}" ]; then
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr #variables init
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr local stage3_baseurl="${mirror}/releases/${arch}/autobuilds"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr # get latest-stage3....txt file for subpath
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr local stage3_pointer="${stage3_baseurl}/latest-stage3-${variant}.txt"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr printf "Determining path to latest Gentoo %s (%s) stage3 archive...\n" "${arch}" "${variant}"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr printf " => downloading and processing %s\n" "${stage3_pointer}"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
35e68b0447feb185db41395c70bdf16da6bbad94lxc@zitta.fr local stage3_latest_tarball=$(wget -q -O - "${stage3_pointer}" | tail -n1 | cut -d' ' -f1) \
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr || die 6 "Error: unable to fetch\n"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr printf " => Got: %s\n" "${stage3_latest_tarball}"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr printf "Downloading/untarring the actual stage3 tarball...\n"
dc5518b82e04326639f4b60ebcdb69a4072d0c1cTAMUKI Shoichi wget -O - "${stage3_baseurl}/${stage3_latest_tarball}" \
dc5518b82e04326639f4b60ebcdb69a4072d0c1cTAMUKI Shoichi | tar -xjpf - --numeric-owner -C "${partialfs}" \
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr || die 6 "Error: unable to fetch or untar\n"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr printf " => extracted to: %s\n" "${partialfs}"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr else
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr printf "Extracting the stage3 tarball...\n"
dc5518b82e04326639f4b60ebcdb69a4072d0c1cTAMUKI Shoichi tar -xpf "${tarball}" --numeric-owner -C "${partialfs}" \
dc5518b82e04326639f4b60ebcdb69a4072d0c1cTAMUKI Shoichi || die 6 "unable to untar ${tarball} to ${partialfs}"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr fi
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr #check if it chroots
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr printf "chroot test..."
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr chroot ${partialfs} /bin/true || die 1 "Error: chroot %s /bin/true, failed" "${partialfs}"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr printf " OK\n"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr printf " => stage3 cache extracted in : %s\n" "${partialfs}"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr return 0
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr}
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.frcache_portage()
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr{
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr printf "### cache_portage: caching portage tree tarball...\n"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr [[ -z "${flush_cache}" && -f "${portage_cache}" ]] && return 0
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr rm -f ${portage_cache}
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr printf "Downloading Gentoo portage (software build database) snapshot...\n"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr execute_exclusively portage 60 wget -O "${portage_cache}" "${mirror}/snapshots/portage-latest.tar.bz2" \
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr || die 6 "Error: unable to fetch\n"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr printf " => done.\n"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr}
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr# custom inittab
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.frcache_inittab()
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr{
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr printf "### cache_inittab: tuning inittab...\n"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr INITTAB="${partialfs}/etc/inittab"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr [[ -w "$INITTAB" ]] || die 1 "Error: $INITTAB is not writeable"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr # create console
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr echo "# Lxc main console" >> "$INITTAB"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr echo "1:12345:respawn:/sbin/agetty -a root --noclear 115200 console linux" >> "$INITTAB"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr # finally we add a pf line to enable clean shutdown on SIGPWR (issue 60)
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr echo "# clean container shutdown on SIGPWR" >> "$INITTAB"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr echo "pf:12345:powerwait:/sbin/halt" >> "$INITTAB"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr # we also blank out /etc/issue here in order to prevent delays spawning login
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr # caused by attempts to determine domainname on disconnected containers
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr sed -i 's/[\][Oo]//g' "${partialfs}/etc/issue"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr}
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.frcache_net()
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr{
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr printf "### cache_net: doing some useful net tuning...\n"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr # useful for chroot
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr # /etc/resolv.conf
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr grep -i 'search ' /etc/resolv.conf > "${partialfs}/etc/resolv.conf"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr grep -i 'nameserver ' /etc/resolv.conf >> "${partialfs}/etc/resolv.conf"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr # fix boot-time interface config wipe under aggressive cap drop
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr # (openrc 0.9.8.4 ~sep 2012 - https://bugs.gentoo.org/show_bug.cgi?id=436266)
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr # initial warkaround was: sed -i -e 's/^#rc_nostop=""/rc_nostop="net.eth0 net.lo"/' "${partialfs}/etc/rc.conf"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr # but this one does not depends on interfaces names
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr echo 'rc_keyword="-stop"' >> "${partialfs}/etc/conf.d/net"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr}
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.frcache_dev()
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr{
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr printf "### cache_dev(): /dev tuning...\n"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr #Wait for https://bugs.gentoo.org/show_bug.cgi?id=496054
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr mkdir "${partialfs}/dev/pts"
cae3584efccc63f544c8748bd13d80e11bc79aefgza mkdir "${partialfs}/dev/shm"
cae3584efccc63f544c8748bd13d80e11bc79aefgza mkdir "${partialfs}/dev/mqueue"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
9749441a0e8072f43e955fba47e07bfd015d0a45Stéphane Graber mkdir -m 755 "${partialfs}/dev/net"
9749441a0e8072f43e955fba47e07bfd015d0a45Stéphane Graber mknod -m 666 "${partialfs}/dev/net/tun" c 10 200
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr return 0
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr}
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr# fix openrc system
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.frcache_openrc()
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr{
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr printf "### cache_openrc(): doing openrc tuning\n"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr #Wait for https://bugs.gentoo.org/show_bug.cgi?id=496054
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr chroot "${partialfs}" sed s/-lxc//g -i "/etc/init.d/devfs"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr return 0
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr}
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
3a74e9097a932729d9eff9ce562288e89731b177Guillaume ZITTAcache_locale()
3a74e9097a932729d9eff9ce562288e89731b177Guillaume ZITTA{
3a74e9097a932729d9eff9ce562288e89731b177Guillaume ZITTA printf "### cache_locale(): initiating minimale locale en_US.UTF-8 \n"
3a74e9097a932729d9eff9ce562288e89731b177Guillaume ZITTA
3a74e9097a932729d9eff9ce562288e89731b177Guillaume ZITTA echo "en_US.UTF-8 UTF-8" >> "${partialfs}/etc/locale.gen"
3a74e9097a932729d9eff9ce562288e89731b177Guillaume ZITTA chroot "${partialfs}" locale-gen
3a74e9097a932729d9eff9ce562288e89731b177Guillaume ZITTA
3a74e9097a932729d9eff9ce562288e89731b177Guillaume ZITTA return 0
3a74e9097a932729d9eff9ce562288e89731b177Guillaume ZITTA}
3a74e9097a932729d9eff9ce562288e89731b177Guillaume ZITTA
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr################################################################################
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr# CONTAINER Preparation
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr################################################################################
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.frcontainer_setup() {
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr printf "##### container_setup(): starting container setup\n"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr #in most cases lxc-create should have provided a copy of default lxc.conf
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr #let's tag where template starts, or just create the files
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr echo '### lxc-gentoo template stuff starts here' >> "$path/config"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr #Determine rootfs
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr #If backingstore was specified, lxc.rootfs should be present or --rootfs did the rootfs var creation
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr if [ -z "${rootfs}" ]; then
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr rootfs=`awk -F= '$1 ~ /^lxc.rootfs/ { print $2 }' "$path/config" 2>/dev/null`
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr if [ -z "${rootfs}" ]; then
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr #OK it's default
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr rootfs="${path}/rootfs"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr fi
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr fi
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr store_user_message "rootfs of container is : ${rootfs}"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr store_user_message "config of container is : ${path}/config"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr container_precheck && \
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr container_rootfs && \
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr container_consoles && \
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr container_tz && \
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr container_portage && \
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr container_net && \
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr container_hostname && \
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr container_auth && \
84ad17ede0febe7cc0d19e1125c25e549dc9104fGuillaume ZITTA container_sshd && \
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr container_conf
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr if [ $? -ne 0 ]; then
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr die 1 "container_setup(): one step didn't complete, sorry\n"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr fi
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr printf "###### container_setup(): container should be ready to start!\n"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr printf "\n\n"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr printf "You could now use you container with: lxc-start -n %s\n" "${name}"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr printf "little things you should know about your container:\n"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr printf "${user_message}"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr return 0
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr}
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.frcontainer_precheck()
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr{
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr printf "### container_precheck(): doing some pre-start checks ...\n"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr # never hurts to have a fail-safe.
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr [[ -n "${name//\/}" ]] \
ec64264d78d4ed608553842ce9e1f07eeab2a032Veres Lajos || die 8 "\$name (%s) IS EMPTY OR MADE OF ONLY DIRECTORY SEPARATORS, THIS IS *VERY* BAD!\n" "${name}"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr [[ -n "${rootfs//\/}" ]] \
ec64264d78d4ed608553842ce9e1f07eeab2a032Veres Lajos || die 8 "\$rootfs (%s) IS EMPTY OR MADE OF ONLY DIRECTORY SEPARATORS, THIS IS *VERY* BAD!\n" "${rootfs}"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr [[ -n "${cachefs//\/}" ]] \
ec64264d78d4ed608553842ce9e1f07eeab2a032Veres Lajos || die 8 "\$cachefs (%s) IS EMPTY OR MADE OF ONLY DIRECTORY SEPARATORS, THIS IS *VERY* BAD!\n" "${cachefs}"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr # check if the rootfs already exists
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr [[ -d "${rootfs}/etc" ]] && die 18 "Error: \$rootfs (%s) already exists!" "${rootfs}"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr # check cache
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr [[ ! -d "${cachefs}/etc" ]] && die 1 "Error: \$cachefs (%s) not found!" "${cachefs}"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr return 0
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr}
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.frcontainer_rootfs()
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr{
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr printf "#### container_rootfs(): copying rootfs %s from cache %s ...\n" "${rootfs}" "${cachefs}"
dc5518b82e04326639f4b60ebcdb69a4072d0c1cTAMUKI Shoichi tar -c -f - --numeric-owner -C "${cachefs}" . \
dc5518b82e04326639f4b60ebcdb69a4072d0c1cTAMUKI Shoichi | tar -x -p -f - --numeric-owner -C "${rootfs}" \
dc5518b82e04326639f4b60ebcdb69a4072d0c1cTAMUKI Shoichi || die 1 "Error: cache copy to rootfs failed"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr printf "chroot test..."
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr chroot "${rootfs}" /bin/true || die 1 "Error: 'chroot %s /bin/true' failed"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr printf " OK\n"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr printf " => done\n"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr return 0
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr}
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.frcontainer_consoles() {
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr printf "#### container_consoles(): setting container consoles ...\n"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr # disable unwanted ttys
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr if [[ ${tty} < 6 ]]; then
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr local mindis=$(( ${tty} + 1 ))
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr sed -i "s/^c[${mindis}-6]/#&/" "${rootfs}/etc/inittab"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr fi
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr printf " => main console + ${tty} ttys\n"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr if [[ -z "${autologin}" ]]; then
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr sed 's/agetty -a root/agetty/' -i "${rootfs}/etc/inittab"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr elif [[ "${user}" != "root" ]]; then
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr sed "s/agetty -a root/agetty -a ${user}/" -i "${rootfs}/etc/inittab"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr printf " => Autologin on main console for %s enabled\n" "${user}"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr [[ -z "${forced_password}" ]] && unset password
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr store_user_message "${user} has autologin on main console"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr else
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr printf " => Autologin on main console for root enabled\n"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr [[ -z "${forced_password}" ]] && unset password
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr store_user_message "${user} has autologin on main console"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr fi
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr printf " => done\n"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr}
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.frcontainer_tz()
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr{
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr printf "#### container_tz(): setting container timezone ...\n"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr #let's try to copy it from host
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr if [ -L "/etc/localtime" ]; then
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr #host has a symlink
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr #let see if we can reproduct symlink
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr target=$(readlink /etc/localtime)
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr if [[ "$target" != "" ]]; then
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr if [ -f "${rootfs}/${target}" ]; then
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr #same target exists in container
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr chroot "${rootfs}" ln -sf "${target}" "/etc/localtime"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr printf " => host symlink reproducted in container : %s\n" "${target}"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr store_user_message "timezone copyed from host"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr return 0
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr fi
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr fi
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr fi
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr if [ -e /etc/localtime ]; then
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr # duplicate host timezone
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr cat /etc/localtime > "${rootfs}/etc/localtime"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr printf " => host localtime copyed to container\n"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr store_user_message "timezone was staticly copyed from host"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr else
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr # otherwise set up UTC
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr chroot "${rootfs}" ln -sf /usr/share/zoneinfo/UTC /etc/localtime
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr printf " => fallback: fixed to UTC\n"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr store_user_message "timezone was fixed to UTC"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr fi
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr}
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.frcontainer_portage()
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr{
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr printf "#### container_portage(): setting container portage... \n"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr #default entry for conf
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr portage_mount="#container set with private portage tree, no mount here"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr printf "Warnings are normal here, don't worry\n"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr #container repos detection
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr if chroot ${rootfs} portageq get_repo_path / gentoo > /dev/null ; then
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr portage_container="$(chroot ${rootfs} portageq get_repo_path / gentoo)"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr else
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr die 1 "Failed to figure out container portage tree location with portageq get_repo_path / gentoo\n"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr fi
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr if [[ -n "${private_portage}" ]]; then
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr container_private_portage
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr return 0
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr fi
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr if [ -z "${portage_dir}" ]; then
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr #gentoo host detection
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr printf "trying to guess portage_dir from host...\n"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr portage_dir="$(portageq get_repo_path / gentoo 2>/dev/null)"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr if [ ! -d "${portage_dir}/profiles" ]; then
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr printf " => host portage detection failed (not gentoo host), fallback to private portage tree\n"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr container_private_portage
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr return 0
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr fi
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr else
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr if [ ! -d "${portage_dir}/profiles" ]; then
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr die 1 "specified portage_dir (%s) does not contains profiles, is it a portage tree ?\n" "${portage_dir}"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr fi
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr fi
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
b69e7bf14e8182912bfda2472ca7caffd60cef41rabisg printf "trying to guess portage distfiles dir from host ...\n"
b69e7bf14e8182912bfda2472ca7caffd60cef41rabisg portage_distfiles_dir="$(portageq distdir 2>/dev/null)"
b69e7bf14e8182912bfda2472ca7caffd60cef41rabisg if [ ! -d "${portage_distfiles_dir}" ]; then
b69e7bf14e8182912bfda2472ca7caffd60cef41rabisg portage_distfiles_dir="${portage_dir}/distfiles"
b69e7bf14e8182912bfda2472ca7caffd60cef41rabisg fi
b69e7bf14e8182912bfda2472ca7caffd60cef41rabisg
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr # if we are here, we have shared portage_dir
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr #ensure dir exists
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr chroot "${rootfs}" mkdir ${portage_container}
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr portage_mount="#container set with shared portage
cf261d584e4d78c1482aac56117f6d1266e5b84dgzalxc.mount.entry=${portage_dir} ${portage_container/\//} none ro,bind 0 0
b69e7bf14e8182912bfda2472ca7caffd60cef41rabisglxc.mount.entry=${portage_distfiles_dir} ${portage_container/\//}/distfiles none rw,bind 0 0
cf261d584e4d78c1482aac56117f6d1266e5b84dgza#If you use eix, you should uncomment this
cf261d584e4d78c1482aac56117f6d1266e5b84dgza#lxc.mount.entry=/var/cache/eix var/cache/eix none ro,bind 0 0"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr store_user_message "container has a shared portage from host's ${portage_dir} to ${portage_container/\//}"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr #Let's propose binary packages
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr cat <<- EOF >> "${rootfs}/etc/portage/make.conf"
cf261d584e4d78c1482aac56117f6d1266e5b84dgza# enable this to store built binary packages
cf261d584e4d78c1482aac56117f6d1266e5b84dgza#FEATURES="\$FEATURES buildpkg"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
cf261d584e4d78c1482aac56117f6d1266e5b84dgza# enable this to use built binary packages
cf261d584e4d78c1482aac56117f6d1266e5b84dgza#EMERGE_DEFAULT_OPTS="\${EMERGE_DEFAULT_OPTS} --usepkg"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
cf261d584e4d78c1482aac56117f6d1266e5b84dgza# enable and *tune* this kind of entry to slot binaries, specialy if you use multiples archs and variants
cf261d584e4d78c1482aac56117f6d1266e5b84dgza#PKGDIR="\${PKGDIR}/amd64
cf261d584e4d78c1482aac56117f6d1266e5b84dgza#or PKGDIR="\${PKGDIR}/hardened"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.frEOF
ec64264d78d4ed608553842ce9e1f07eeab2a032Veres Lajos printf " => portage stuff done, see /etc/portage/make.conf for additional tricks\n"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr}
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.frcontainer_private_portage()
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr{
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr #called from container_portage() do not call directly from container_setup
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr printf "# untaring private portage to %s from %s ... \n" "${rootfs}/${portage_container}" "${portage_cache}"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr mkdir -p "${rootfs}/${portage_container}"
dc5518b82e04326639f4b60ebcdb69a4072d0c1cTAMUKI Shoichi execute_exclusively portage 60 \
dc5518b82e04326639f4b60ebcdb69a4072d0c1cTAMUKI Shoichi tar -xp --strip-components 1 -C "${rootfs}/${portage_container}" \
dc5518b82e04326639f4b60ebcdb69a4072d0c1cTAMUKI Shoichi -f "${portage_cache}" --numeric-owner \
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr || die 2 "Error: unable to extract the portage tree.\n"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr store_user_message "container has its own portage tree at ${portage_container}"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr printf "=> done\n"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr}
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr#helper func for container_genconf_net()
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.frnic_write()
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr{
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr #display with gentoo's confd.net format
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr echo "config_${nic_name}=\"${nic_conf}\""
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr #add to managed list
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr [[ "${nic_conf}" == "dhcp" ]] && nic_managed="${nic_managed} ${nic_name}"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr [[ "${nic_conf}" == "null" ]] && nic_unmanaged="${nic_unmanaged} ${nic_name}"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr [[ -z "${nic_hwaddr}" && ${nic_type} == "veth" ]] && nic_wo_hwaddr="${nic_wo_hwaddr} ${nic_name}"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr nic_writed=1
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr}
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr#Analyse lxc.conf and print conf.d/net content
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.frcontainer_conf_net()
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr{
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr local file=${1}
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr [[ -z "${nic_last}" ]] && nic_last=-1
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr [[ -z "${nic_named}" ]] && nic_named=0
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr OLDIFS=$IFS
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr IFS="
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr"
cae3584efccc63f544c8748bd13d80e11bc79aefgza #let's do some drity bash things to parse lxc network conf
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr for line in $( sed -r "s/[ ]*=[ ]*/_real_ugly_sep_42_/" "${file}" ); do
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr key=$(echo "${line}" | sed 's/_real_ugly_sep_42_.*$//')
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr value=$(echo "${line}" | sed 's/^.*_real_ugly_sep_42_//')
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr #new nic !
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr if [[ "${key}" == "lxc.network.type" ]]; then
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr #we don't know what to do with it.
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr [[ "${value}" == "empty" ]] && continue
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr #write conf from previous loops
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr [[ "${nic_writed}" == "0" ]] && nic_write
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr #init defaults
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr let nic_last=nic_last+1
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr nic_writed=0
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr #if 1 named between 2 not named: last is eth1
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr #=> Number is ID munis number of named NIC before
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr nic_name="eth$(( ${nic_last} - ${nic_named} ))"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr nic_conf="dhcp"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr nic_type="${value}"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr fi
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr if [[ "${key}" == "lxc.network.hwaddr" ]]; then
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr nic_hwaddr=1
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr fi
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr if [[ "${key}" =~ ^lxc.network.ipv(4|6) ]]; then
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr #tell openrc to not manage this NIC as LXC set there address
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr nic_conf="null"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr fi
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr if [[ "${key}" =~ ^lxc.network.name ]]; then
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr nic_name="${value}"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr let nic_named=nic_named+1
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr fi
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr if [[ "${key}" == "lxc.include" ]]; then
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr #recursive into include
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr container_conf_net "${value}"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr fi
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr done
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr #write conf from previous loops
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr [[ "${nic_writed}" == "0" ]] && nic_write
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr IFS=$OLDIFS
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr}
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.frcontainer_net()
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr{
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr printf "container_net(): setting container network conf... \n"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr #Analyse network configuration in config
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr container_conf_net "$path/config" >> "${rootfs}/etc/conf.d/net"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
ec64264d78d4ed608553842ce9e1f07eeab2a032Veres Lajos # found how much nic finally have
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr nic_count=$(( ${nic_last} + 1 ))
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr # unless openrc manage a nic, we now have to force openrc to automatic
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr # provision of the 'net' dep. If we do not, network dependent services
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr # will fail to load
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr if [[ -z "${nic_managed}" ]]; then
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr #tell openrc that lxc already did the work
2562784e950b05f2e3036b1af8f7e7e3fe728da2gza echo 'rc_provide="net"' >> "${rootfs}/etc/rc.conf"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr fi
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr #No NIC ?
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr if [[ ${nic_count} == 0 ]]; then
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr #If no Nic, no need to continue
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr bridge=$(brctl show | awk 'NR==2 {print $1}')
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr if [[ "${bridge}" != "" ]]; then
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr store_user_message "No network interface for this container
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.frIt's a pitty, you have bridge, ${bridge}.
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.frIf it is for Lxc, use it next time by adding this to your default.conf :
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.frlxc.network.type = veth
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.frlxc.network.link = ${bridge}
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.frlxc.network.flags = up
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.frlxc.network.hwaddr = fe:xx:xx:xx:xx:xx"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr return 0
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr else
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr store_user_message "No network interface for this container"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr return 0
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr fi
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr fi
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr #For each openrc managed nic, activate
cae3584efccc63f544c8748bd13d80e11bc79aefgza sys_nic_index=1
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr for nic in ${nic_managed}
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr do
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr chroot "${rootfs}" ln -s net.lo "/etc/init.d/net.${nic}"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr chroot "${rootfs}" rc-update add net.${nic} default
cae3584efccc63f544c8748bd13d80e11bc79aefgza #fake sysfs for openrc, in case settings does not provide it
cae3584efccc63f544c8748bd13d80e11bc79aefgza mkdir -p "${rootfs}/sys/class/net/${nic}"
cae3584efccc63f544c8748bd13d80e11bc79aefgza echo ${sys_nic_index} > "${rootfs}/sys/class/net/${nic}/ifindex"
cae3584efccc63f544c8748bd13d80e11bc79aefgza echo up > "${rootfs}/sys/class/net/${nic}/operstate"
cae3584efccc63f544c8748bd13d80e11bc79aefgza let sys_nic_index=sys_nic_index+1
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr done
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr #Warn about dynamic hwaddr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr if [[ -n "${nic_wo_hwaddr}" ]]; then
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr store_user_message "Warning, these veth NIC don't have fixed hwaddr :
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr${nic_wo_hwaddr}
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.frsee http://lists.linuxcontainers.org/pipermail/lxc-devel/2013-December/006736.html
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.frand man lxc.conf"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr fi
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr printf " => network conf done.\n"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr}
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr# custom hostname
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.frcontainer_hostname()
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr{
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr printf "#### container_hostname(): setting hostname... \n"
3d8b68b1d5be415544a71b18df9635deceb2fd8aDark Templar printf "hostname=\"%s\"\n" "${name}" > "${rootfs}/etc/conf.d/hostname"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr printf " => done.\n"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr}
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.frcontainer_auth()
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr{
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr printf "#### container_auth(): setting authentification... \n"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr if [[ "${user}" != "root" ]]; then
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr printf " non root user requested, creating... \n"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr chroot "${rootfs}" useradd --create-home -s /bin/bash "${user}" || die 1 "failed to create user ${user}"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr printf " => user %s created\n" "${user}"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr fi
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr store_user_message "Connection user is ${user}"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr #Home of user
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr auth_home=$(chroot "${rootfs}" getent passwd "${user}" | cut -d : -f 6)
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr if [[ -r "${auth_key}" ]]; then
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr printf " deploying auth_key %s for user %s ...\n" "${auth_key}" "${user}"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr mkdir -p "${rootfs}/${auth_home}/.ssh"
7785e39c96a25bab32a426bf3c1d1e0a1993ac49Erik Mackdanz cat "${auth_key}" >> "${rootfs}/${auth_home}/.ssh/authorized_keys"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr chroot "${rootfs}" chown "${user}:" "${auth_home}/.ssh/authorized_keys"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr printf " => inserted public key in %s/.ssh/authorized_keys\n" "${auth_home}"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr [[ -z "${forced_password}" ]] && unset password
7785e39c96a25bab32a426bf3c1d1e0a1993ac49Erik Mackdanz store_user_message "${user} has the ssh key you gave us"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr fi
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr if [[ -n "${password}" ]]; then
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr printf " setting password for %s ...\n" "${user}"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr echo "${user}:${password}" | chroot "${rootfs}" chpasswd || die 1 "failed to change password"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr printf " => done. if you didn't specify , default is 'toor'\n"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr if [[ -n "${forced_password}" ]]; then
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr store_user_message "${user} has the password you give for him"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr fi
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr fi
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr printf " => done.\n"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr}
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
84ad17ede0febe7cc0d19e1125c25e549dc9104fGuillaume ZITTAcontainer_sshd() {
84ad17ede0febe7cc0d19e1125c25e549dc9104fGuillaume ZITTA printf "#### container_sshd(): enabling sshd... \n"
84ad17ede0febe7cc0d19e1125c25e549dc9104fGuillaume ZITTA
84ad17ede0febe7cc0d19e1125c25e549dc9104fGuillaume ZITTA chroot "${rootfs}" rc-update add sshd || die 1 "failed to enable sshd\n"
84ad17ede0febe7cc0d19e1125c25e549dc9104fGuillaume ZITTA
84ad17ede0febe7cc0d19e1125c25e549dc9104fGuillaume ZITTA printf " => done.\n"
84ad17ede0febe7cc0d19e1125c25e549dc9104fGuillaume ZITTA}
84ad17ede0febe7cc0d19e1125c25e549dc9104fGuillaume ZITTA
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr################################################################################
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr# lxc configuration files
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr################################################################################
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.frcontainer_conf()
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr{
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr printf "container_configuration(): making lxc configuration file... \n"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr #at this point if there
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr conf_file="${path}/config"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
b8ebaa9c78a78e3e3c4043a20d3c84cac9ca7fd1Vicente Olivert Riera # if there is exactly one veth network entry, make sure it has an
b8ebaa9c78a78e3e3c4043a20d3c84cac9ca7fd1Vicente Olivert Riera # associated hwaddr.
b8ebaa9c78a78e3e3c4043a20d3c84cac9ca7fd1Vicente Olivert Riera nics=`grep -e '^lxc\.network\.type[ \t]*=[ \t]*veth' ${conf_file} | wc -l`
b8ebaa9c78a78e3e3c4043a20d3c84cac9ca7fd1Vicente Olivert Riera if [ $nics -eq 1 ]; then
b8ebaa9c78a78e3e3c4043a20d3c84cac9ca7fd1Vicente Olivert Riera grep -q "^lxc.network.hwaddr" ${conf_file} || sed -i -e "/^lxc\.network\.type[ \t]*=[ \t]*veth/a lxc.network.hwaddr = 00:16:3e:$(openssl rand -hex 3| sed 's/\(..\)/\1:/g; s/.$//')" ${conf_file}
b8ebaa9c78a78e3e3c4043a20d3c84cac9ca7fd1Vicente Olivert Riera fi
b8ebaa9c78a78e3e3c4043a20d3c84cac9ca7fd1Vicente Olivert Riera
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr if grep -q "^lxc.rootfs" "${conf_file}" ; then
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr #lxc-create already provided one
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr conf_rootfs_line=""
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr else
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr conf_rootfs_line="lxc.rootfs = $(readlink -f "${rootfs}")"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr fi
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr if [[ "${arch}" == "x86" || "${arch}" == "amd64" ]]; then
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr local conf_arch_line="lxc.arch = ${arch}"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr else
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr local conf_arch_line="# lxc.arch = ${arch}"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr fi
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
cae3584efccc63f544c8748bd13d80e11bc79aefgza cat <<- EOF >> "${conf_file}"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr# sets container architecture
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr# If desired architecture != amd64 or x86, then we leave it unset as
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr# LXC does not oficially support anything other than x86 or amd64.
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr${conf_arch_line}
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr# set the hostname
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.frlxc.utsname = ${name}
cae3584efccc63f544c8748bd13d80e11bc79aefgzalxc.tty = ${tty}
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr${conf_rootfs_line}
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr${portage_mount}
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr${conf_sysfs}
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr${conf_mounts}
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
cae3584efccc63f544c8748bd13d80e11bc79aefgzalxc.include = ${LXC_TEMPLATE_CONFIG}/gentoo.${settings}.conf
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.frEOF
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr printf " => done.\n"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr}
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.frusage()
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr{
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr cat <<EOF
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr$1 -h|--help [-a|--arch <arch>] [-v|--variant <variant>] [-P|--private-portage] [--portage-dir <protagedir>] [-t|--tarball <stage3file>]
cae3584efccc63f544c8748bd13d80e11bc79aefgza [-F|--flush-cache] [-c|--cache-only] [-u|--user <username>] [-w|--password <password>] [--autologin] [-S|--auth-key <keyfile>]
cae3584efccc63f544c8748bd13d80e11bc79aefgza [-s|--settings <name>] [-m|--mirror <gentoomirror>] [--tty <number>]
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.frarch: the container architecture (e.g. amd64): defaults to host arch (currently: '${arch}')
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr If you choose one that needs emulation
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr tested: amd64, x86
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr You could try any other gentoo arch, why not...
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.frvariant: gentoo's Architecture variant as of dec 2013 : (currently: '${variant}')
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr for amd64 arch: amd64 (default), amd64-hardened+nomultilib, amd64-hardened, amd64-nomultilib, x32
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr for x86 arch: i686 (default), i486, i686-hardened
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr for arm arch: armv7a (default), armv7a_hardfp, armv6j, armv6j_hardfp, armv5tel, armv4tl
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.frprivate-portage: by default, /usr/portage is mount-binded with host one if exists (currently: '${private_portage}')
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr this force container to have his own copy
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.frportage-dir: portage dir used for shared portage
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr by default the host on if any (currently: '${portage_dir}')
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.frtarball: force usage of local stage3 archive (currently: '${arch}')
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr If empty, latest will be downloaded
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.frflush-cache: do like there is no previous cache
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.frcache-only: just ensure cache is present
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr if cache exists and "flush-cache" not specified, does nothing
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fruser: user used in auth oriented options (currently: '${user}')
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.frpassword: password for user (currently: '${password}')
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr if default, usage of auth-key will disable password setting
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.frautologin: enable autologin for user (currently: '${autologin}')
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr This unset default password setting
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.frauth-key: SSH Public key file to inject into container for user (currently: '${auth_key}')
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr This unset default password setting
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
cae3584efccc63f544c8748bd13d80e11bc79aefgzasettings: choose common configuration (currently: '${settings}')
cae3584efccc63f544c8748bd13d80e11bc79aefgza see ${LXC_TEMPLATE_CONFIG}/gentoo.*.conf
cae3584efccc63f544c8748bd13d80e11bc79aefgza Available settings:
cae3584efccc63f544c8748bd13d80e11bc79aefgza $(ls -1 ${LXC_TEMPLATE_CONFIG}/gentoo.*.conf | xargs basename -a -s .conf | sed 's/^gentoo.//')
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.frmirror: gentoo mirror for download (currently: '${mirror}')
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.frtty: number of tty (6 max) (currently: '${tty}')
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.frEOF
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr exit 0
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr}
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr#some overridable defaults
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.frset_default_arch
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.frmirror="http://distfiles.gentoo.org"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fruser="root"
982b59592e494794d5ac3da0c10bf20ebe208f72Guillaume ZITTAtty=1
cae3584efccc63f544c8748bd13d80e11bc79aefgzasettings="common"
7785e39c96a25bab32a426bf3c1d1e0a1993ac49Erik Mackdanzoptions=$(getopt -o hp:n:a:FcPv:t:S:u:w:s:m: -l help,rootfs:,path:,name:,arch:,flush-cache,cache-only,private-portage,variant:,portage-dir:,tarball:,auth-key:,user:,autologin,password:,settings:,mirror:,tty: -- "$@")
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.freval set -- "$options"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.frwhile true
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.frdo
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr case "$1" in
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr -h|--help) usage $0 && exit 0;;
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr --rootfs) rootfs=$2; shift 2;;
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr -p|--path) path=$2; shift 2;;
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr -n|--name) name=$2; shift 2;;
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr -a|--arch) arch=$2; shift 2;;
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr -F|--flush-cache) flush_cache=1; shift 1;;
4167102e93571e776dc7248a21145e753acdc3b8Dark Templar -c|--cache-only) cache_only=1; shift 1;;
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr -P|--private-portage) private_portage=1; shift 1;;
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr -v|--variant) variant=$2; shift 2;;
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr --portage-dir) portage_dir=$2; shift 2;;
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr -t|--tarball) tarball=$2; shift 2;;
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr -S|--auth-key) auth_key=$2; shift 2;;
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr -u|--user) user=$2; shift 2;;
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr -w|--password) forced_password=1; password=$2; shift 2;;
cae3584efccc63f544c8748bd13d80e11bc79aefgza -s|--settings) settings=$2; shift 2;;
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr -m|--mirror) mirror=$2; shift 2;;
6dc6f80bfd7cb169948f2ef9a95dcf6d2edee853Kevin Carter --container-cache) containercache=$2; shift 2;;
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr --tty) [[ $2 -lt 6 ]] && tty=$2; shift 2;;
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr --autologin) autologin=1; shift 1;;
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr --) shift 1; break ;;
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr *) break ;;
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr esac
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.frdone
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
6dc6f80bfd7cb169948f2ef9a95dcf6d2edee853Kevin Carter# Allow the cache path to be set by environment variable
6dc6f80bfd7cb169948f2ef9a95dcf6d2edee853Kevin Cartercacheroot="${LXC_CACHE_PATH:-"@LOCALSTATEDIR@/cache/lxc"}/gentoo"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.frportage_cache="${cacheroot}/portage.tbz"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.frcachefs="${cacheroot}/rootfs-${arch}-${variant}"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fralias wget="wget --timeout=8 --read-timeout=15 -c -t10 -nd"
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.frdo_all() {
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr cache_setup
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr if [ -z "${cache_only}" ]; then
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr container_setup
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr fi
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr}
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.fr
f8d0243a78c65ea3c46eb60fbeef799c3f6e9a5blxc@zitta.frexecute_exclusively "cache-${arch}-${variant}" 60 do_all