8
error() { echo "$@" 1>&2; }
9
fail() { local r=$?; [ $r -eq 0 ] && r=1; failrc "$r" "$@"; }
10
failrc() { local r=$1; shift; [ $# -eq 0 ] || error "$@"; exit $r; }
14
Usage: ${0##*/} [ options ] <image> name
16
start a container of image (ubuntu-daily:xenial) and install curtin.
19
--proposed enable proposed
20
--daily enable daily curtin archive
21
--source D grab the source deb, unpack inside, and copy unpacked
26
bad_Usage() { Usage 1>&2; [ $# -eq 0 ] || error "$@"; return 1; }
28
if [ -n "$CONTAINER" ]; then
29
debug 1 "deleting container $CONTAINER"
30
lxc delete --force "$CONTAINER"
35
local n="$1" close_in=true
37
[ "$1" = "-" ] && { close_in=false; shift; }
38
set -- lxc exec --mode=non-interactive "$n" -- "$@"
40
debug 1 "$* </dev/null"
51
inside "$name" $eatmydata \
52
env DEBIAN_FRONTEND=noninteractive \
53
apt-get install --no-install-recommends -qy "$@" || {
54
error "failed apt-get install --no-install-recommends -qy $*"
60
local n="$1" max="${2:-30}" debug=${3}
61
inside "$n" - /bin/sh -s $max $debug <<"EOF"
62
max=$1; debug=${2:-0};
64
while [ ! -e /run/cloud-init/result.json ] && i=$(($i+1)); do
65
[ $i -ge $max ] && exit 1
66
[ "$debug" = "0" ] || echo -n .
69
[ "$debug" = "0" ] || echo "[done after $i]"
76
local level=${1}; shift;
77
[ "${level}" -gt "${VERBOSITY}" ] && return
83
local long_opts="help,daily,proposed,source:,verbose"
85
getopt_out=$(getopt --name "${0##*/}" \
86
--options "${short_opts}" --long "${long_opts}" -- "$@") &&
87
eval set -- "${getopt_out}" ||
88
{ bad_Usage; return; }
91
local proposed=false daily=false src="" name="" maxwait=30
92
local eatmydata="eatmydata" getsource="none"
94
while [ $# -ne 0 ]; do
97
-h|--help) Usage ; exit 0;;
98
--source) getsource="$next"; shift;;
99
--proposed) proposed=true;;
100
--daily) daily=true;;
101
-v|--verbose) VERBOSITY=$((${VERBOSITY}+1));;
107
[ $# -eq 2 ] || { bad_Usage "expected 2 args, got $#: $*"; return; }
113
if [ "$getsource" != "none" ]; then
114
[ ! -e "$getsource" ] || fail "source output '$getsource' exists."
117
lxc launch "$src" "$name" || fail "failed lxc launch $src $name"
120
wait_for_ready "$name" $maxwait $VERBOSITY ||
121
fail "$name did not become ready after $maxwait"
123
inside "$name" which eatmydata >/dev/null || eatmydata=""
126
mirror=$(inside $name awk '$1 == "deb" { print $2; exit(0); }' \
127
/etc/apt/sources.list) &&
128
rel=$(inside $name lsb_release -sc) ||
129
fail "failed to get mirror in $name"
130
line="$mirror $rel-proposed main universe"
131
local fname="/etc/apt/sources.list.d/proposed.list"
132
debug 1 "enabling proposed in $fname: deb $line"
133
inside "$name" sh -c "echo deb $line > $fname" ||
134
fail "failed adding proposed to $fname"
135
if [ "$getsource" != "none" ]; then
136
inside "$name" sh -c "echo deb-src $line >> $fname" ||
137
fail "failed adding proposed deb-src to $fname"
141
local daily_ppa="ppa:curtin-dev/daily"
142
debug 1 "enabling daily: $daily_ppa"
143
inside "$name" add-apt-repository --enable-source --yes \
145
fail "failed add-apt-repository for daily."
148
line="Acquire::Languages \"none\";"
149
fname="/etc/apt/apt.conf.d/99notranslations"
150
inside "$name" sh -c '
151
rm -f /var/lib/apt/lists/*Translation*;
152
echo "$1" > "$2"' -- "$line" "$fname" ||
153
error "failed to disable translations"
156
if [ "${getsource}" = "none" ]; then
157
inside "$name" sed -i '/^deb-src/s/^/#/' /etc/apt/sources.list ||
158
error "failed to disable deb-src entries"
160
pkgs="${pkgs} dpkg-dev"
163
inside "$name" $eatmydata apt-get -q update ||
164
fail "failed apt-get update"
165
install "$name" $pkgs || fail "failed install of $pkgs"
167
if [ "${getsource}" != "none" ]; then
168
local isrcd="/tmp/curtin-source"
169
debug 1 "getting source for curtin to $getsource"
170
inside "$name" $eatmydata sh -ec '
174
apt-get source curtin
175
for x in *; do [ -d "$x" ] && break; done
176
[ -d "$x" ] || { echo no source dir found.; exit 1; }
180
mkdir "$getsource" || fail "failed to create dir '$getsource'"
181
inside "$name" tar -C "$isrcd" -cf - . |
182
tar -C "$getsource" -xf - ||
183
fail "failed to copy source out to $getsource"
184
version=$(inside "$name" dpkg-parsechangelog \
185
"--file=$isrcd/debian/changelog" "--show-field=version")
186
inside "$name" rm -Rf "$isrcd" ||
187
fail "failed removal of extract dir"
188
debug 1 "put source for curtin at $version in $getsource"