/usr/bin/autopkgtest-build-lxc is in autopkgtest 4.4.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 | #!/bin/sh
# autopkgtest-build-lxc is part of autopkgtest
# autopkgtest is a tool for testing Debian binary packages
#
# autopkgtest is Copyright (C) 2006-2014 Canonical Ltd.
#
# Build or update a container with the debian or ubuntu LXC template
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
# See the file CREDITS for a full list of credits information (often
# installed as /usr/share/doc/autopkgtest/CREDITS).
set -e
DISTRO="$1"
RELEASE="$2"
if [ -z "$1" ] || [ -z "$2" ]; then
echo "Usage: $0 debian|ubuntu <release> [arch] [script]" >&2
exit 1
fi
# check that LXC config has networking
if grep -q 'lxc.network.type *= *empty' /etc/lxc/default.conf; then
cat <<EOF >&2
ERROR: autopkgtest containers need networking; please set it up and adjust
lxc.network.type in /etc/lxc/default.conf
EOF
exit 1
fi
ARCH=${3:-}
if [ "${0%adt-build-lxc}" != "$0" ]; then
echo "WARNING: Deprecated command, please call this as autopkgtest-build-lxc" >&2
NAME="adt-${RELEASE}${ARCH:+-$ARCH}"
else
NAME="autopkgtest-${RELEASE}${ARCH:+-$ARCH}"
fi
SCRIPT=${4:-}
if [ -n "$SCRIPT" -a ! -r "$SCRIPT" ]; then
echo "ERROR: can't read customization script $SCRIPT" >&2
exit 1
fi
# fall back for older LXC option name
LXCDIR=`lxc-config lxc.lxcpath` || LXCDIR=`lxc-config lxcpath` || LXCDIR=/var/lib/lxc
LXC_ARGS="-t $DISTRO -- -r $RELEASE ${ARCH:+-a $ARCH}"
# packages_template defaults to "ssh,vim" in Ubuntu; don't install those
export packages_template=eatmydata
if type eatmydata >/dev/null 2>&1; then
LXC_CREATE_PREFIX="eatmydata"
fi
# detect apt proxy
proxy_detect() {
# support backwards compatible env var too
AUTOPKGTEST_APT_PROXY=${AUTOPKGTEST_APT_PROXY:-${ADT_APT_PROXY:-}}
if [ -z "$AUTOPKGTEST_APT_PROXY" ]; then
RES=`apt-config shell proxy Acquire::http::Proxy`
eval $RES
if echo "${proxy:-}" | egrep -q '(localhost|127\.0\.0\.[0-9]*)'; then
# set http_proxy for the initial debootstrap
export http_proxy="$proxy"
# translate proxy address to one that can be accessed from the
# running container
local bridge_interface=$(awk '{ if ($1 == "lxc.network.link") print($3)}' /etc/lxc/default.conf)
if [ -n "$bridge_interface" ]; then
local bridge_ip=$(ip -4 a show dev "$bridge_interface" | awk '/ inet / {sub(/\/.*$/, "", $2); print $2}') || true
if [ -n "$bridge_ip" ]; then
AUTOPKGTEST_APT_PROXY=$(echo "$proxy" | sed -r "s#localhost|127\.0\.0\.[0-9]*#$bridge_ip#")
fi
fi
if [ -n "$AUTOPKGTEST_APT_PROXY" ]; then
echo "Detected local apt proxy, using $AUTOPKGTEST_APT_PROXY as container proxy"
fi
elif [ -n "${proxy:-}" ]; then
AUTOPKGTEST_APT_PROXY="$proxy"
echo "Using $AUTOPKGTEST_APT_PROXY as container proxy"
# set http_proxy for the initial debootstrap
export http_proxy="$proxy"
fi
fi
}
setup() {
# a host's http_proxy for localhost does not work in the guest, apt proxy
# needs to be set up separately there
if [ "$http_proxy" != "${http_proxy#*localhost*}" ] || \
[ "$http_proxy" != "${http_proxy#*127.0.0.*}" ]; then
unset http_proxy
unset https_proxy
fi
# set up apt proxy for the container
if [ -n "$AUTOPKGTEST_APT_PROXY" ]; then
echo "Acquire::http { Proxy \"$AUTOPKGTEST_APT_PROXY\"; };" > $LXCDIR/$1/rootfs/etc/apt/apt.conf.d/01proxy
fi
lxc-start --daemon --name=$1
# wait until it is booted: lxc-attach works and we get a numeric runlevel
timeout=60
while [ $timeout -ge 0 ]; do
timeout=$((timeout - 1))
sleep 1
O=`lxc-attach --name=$1 runlevel 2>/dev/null` || continue
[ "$O" = "${O%[0-9]}" ] || break
done
[ $timeout -ge 0 ] || {
echo "Timed out waiting for container to boot" >&2
lxc-stop --kill --name=$1 || true
lxc-destroy --name=$1 || true
exit 1
}
# find setup-testbed script
for script in $(dirname $(dirname "$0"))/setup-commands/setup-testbed \
/usr/share/autopkgtest/setup-commands/setup-testbed; do
if [ -r "$script" ]; then
echo "Running setup script $script..."
cat "$script" | lxc-attach --name=$1 env MIRROR=${MIRROR:-} sh
break
fi
done
# run customize script
if [ -n "$SCRIPT" ]; then
echo "Running customization script $SCRIPT..."
cat "$SCRIPT" | lxc-attach --name=$1 env MIRROR=${MIRROR:-} sh
fi
lxc-stop --name=$1
}
proxy_detect
if [ ! -e $LXCDIR/$NAME ]; then
# first-time run: just create the container
$LXC_CREATE_PREFIX lxc-create -B best --name=$NAME $LXC_ARGS
setup $NAME
else
# remove LXC rootfs caches; on btrfs this might be a subvolume, otherwise
# rm it
btrfs subvolume delete /var/cache/lxc/$RELEASE/rootfs-* 2>/dev/null || rm -rf /var/cache/lxc/$RELEASE/rootfs-*
# create a new rootfs in a temp container
$LXC_CREATE_PREFIX lxc-create -B best --name=${NAME}.new $LXC_ARGS
setup ${NAME}.new
sed -i "s/${NAME}.new/${NAME}/" $LXCDIR/${NAME}.new/rootfs/etc/hostname $LXCDIR/${NAME}.new/rootfs/etc/hosts
# replace the original rootfs; can't make this more atomic unfortunately
mv $LXCDIR/${NAME}.new/rootfs $LXCDIR/${NAME}/rootfs.new
mv $LXCDIR/${NAME}/rootfs $LXCDIR/${NAME}/rootfs.old
mv $LXCDIR/${NAME}/rootfs.new $LXCDIR/${NAME}/rootfs
# old rootfs might contain btrfs subvolumes, remove them
subvols=$(btrfs subvolume list -o $LXCDIR/${NAME}/rootfs.old 2>/dev/null | awk "/\/rootfs.old/ {print \$(NF)}") || true
for vol in $subvols; do
btrfs subvolume delete "/${vol#@}"
done
btrfs subvolume delete $LXCDIR/${NAME}/rootfs.old 2>/dev/null || rm -rf $LXCDIR/${NAME}/rootfs.old
mkdir $LXCDIR/${NAME}.new/rootfs
lxc-destroy --name=${NAME}.new
fi
|