/usr/bin/adt-build-lxd is in autopkgtest 3.20.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 | #!/bin/sh
# adt-build-lxd is part of autopkgtest
# autopkgtest is a tool for testing Debian binary packages
#
# autopkgtest is Copyright (C) 2006-2015 Canonical Ltd.
#
# Build or update an LXD image autopkgtest/<distro>/<release>/<arch> with
# autopkgtest customizations from an arbitrary existing image.
#
# 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 -eu
# generate temporary container name
generate_container_name() {
while true; do
CONTAINER=$(mktemp adt-prepare-XXX -u)
lxc info "$CONTAINER" >/dev/null 2>&1 || break
done
}
# auto-detect apt-cacher-ng
proxy_detect() {
if [ -z "${ADT_APT_PROXY:-}" ]; then
RES=`apt-config shell proxy Acquire::http::Proxy`
eval $RES
if echo "${proxy:-}" | egrep -q '(localhost|127\.0\.0\.[0-9]*):3142'; then
# 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
ADT_APT_PROXY="http://$bridge_ip:3142"
fi
fi
if [ -n "${ADT_APT_PROXY:-}" ]; then
echo "Detected local apt-cacher-ng, using $ADT_APT_PROXY as container proxy"
fi
fi
fi
}
setup() {
# set up apt proxy for the container
if [ -n "${ADT_APT_PROXY:-}" ] && [ "$ADT_APT_PROXY" != "none" ]; then
echo "Acquire::http::Proxy \"$ADT_APT_PROXY\";" | lxc file push - "$CONTAINER/etc/apt/apt.conf.d/01proxy"
# work around LP#1548878
lxc exec "$CONTAINER" -- chmod 644 /etc/apt/apt.conf.d/01proxy
fi
# wait until it is booted: lxc exec works and we get a numeric runlevel
timeout=60
while [ $timeout -ge 0 ]; do
timeout=$((timeout - 1))
sleep 1
O=`lxc exec "$CONTAINER" runlevel 2>/dev/null </dev/null` || continue
[ "$O" = "${O%[0-9]}" ] || break
done
[ $timeout -ge 0 ] || {
echo "Timed out waiting for container to boot" >&2
exit 1
}
ARCH=$(lxc exec "$CONTAINER" -- dpkg --print-architecture </dev/null)
DISTRO=$(lxc exec "$CONTAINER" -- sh -ec 'lsb_release -si 2>/dev/null || . /etc/os-release; echo "${NAME% *}"' </dev/null)
RELEASE=$(lxc exec "$CONTAINER" -- sh -ec 'lsb_release -sc 2>/dev/null || awk "/^deb/ {sub(/\\[.*\\]/, \"\", \$0); print \$3; quit}" /etc/apt/sources.list' </dev/null)
echo "Container finished booting. Distribution $DISTRO, release $RELEASE, architecture $ARCH"
# 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..."
lxc exec "$CONTAINER" -- sh < "$script"
break
fi
done
lxc stop "$CONTAINER"
}
#
# main
#
if [ -z "${1:-}" ]; then
echo "Usage: $0 <image>" >&2
exit 1
fi
IMAGE="$1"
CONTAINER=''
trap '[ -z "$CONTAINER" ] || lxc delete -f "$CONTAINER"' EXIT INT QUIT PIPE
proxy_detect
generate_container_name
lxc launch "$IMAGE" "$CONTAINER"
setup
# if there already is a published image, get its fingerprint to clean it up
# afterwards
DISTROLC=$(echo "$DISTRO" | tr '[:upper:]' '[:lower:]')
ALIAS="adt/$DISTROLC/$RELEASE/$ARCH"
DESCRIPTION="autopkgtest $DISTRO $RELEASE $ARCH"
lxc publish "$CONTAINER" --alias "$ALIAS" --public description="$DESCRIPTION" distribution="$DISTROLC" release="$RELEASE" architecture="$ARCH"
# clean up old images
for i in $(lxc image list | grep "$DESCRIPTION" | grep -v "$ALIAS" | cut -d'|' -f3); do
echo "Removing previous image $i"
lxc image delete "$i"
done
|