Ubuntu Pastebin

Paste from smoser at Thu, 16 Mar 2017 14:52:51 +0000

Download as text
 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
#!/bin/bash
src=${1:-ubuntu-daily:zesty}
deb=${2}
name=$3
cfg=$4
CONTAINER=""

cleanup() {
   set -x
   [ -n "$CONTAINER" ] || return;
   lxc delete --force "$CONTAINER";
}
error() { echo "$@" 1>&2; }
fail() { echo "$@" 1>&2; exit 1; }

trap cleanup EXIT
[ -n "$name" ] &&
   error "creating $name from $src" ||
   error "creating container from $src"

out=$(lxc init $src $name) || fail "failed create $src $name"
[ -z "$name" ] && name=${out##*: }
error "created $name"
CONTAINER="$name"

if [ -n "$deb" ]; then
   error "installing $deb into $name"
   out=$(lxc-chroot "$name" sh -ec \
      'deb=my.deb; cat > $deb; dpkg -i $deb; rm -f $deb' < "$deb" 2>&1) ||
   fail "failed install of $deb: $out"
fi

path="var/lib/cloud/seed/nocloud-net/network-config"
if [ -n "$cfg" ]; then
   error "pushing $cxfg to $path"
   lxc file push "$cfg" "$name/$path"
else
   error "pushing default net2 yaml to $path"
   lxc file push - "$name/$path" <<EOF
version: 2
ethernets:
    eth0:
        dhcp4: true
        dhcp6: true
EOF
fi

lxc start "$name" || fail "failed start '$name'"
CONTAINER=""
Download as text