diff options
Diffstat (limited to 'templates/lxc-ubuntu.in')
-rw-r--r-- | templates/lxc-ubuntu.in | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/templates/lxc-ubuntu.in b/templates/lxc-ubuntu.in index 26db686..391ee55 100644 --- a/templates/lxc-ubuntu.in +++ b/templates/lxc-ubuntu.in @@ -68,6 +68,15 @@ EOF chroot $rootfs groupadd --system $group >/dev/null 2>&1 || true chroot $rootfs useradd --create-home -s /bin/bash -G $group ubuntu echo "ubuntu:ubuntu" | chroot $rootfs chpasswd + if [ -n "$auth_key" -a -f "$auth_key" ]; then + u_path="/home/ubuntu/.ssh" + root_u_path="$rootfs/$u_path" + mkdir -p $root_u_path + cp $auth_key "$root_u_path/authorized_keys" + chroot $rootfs chown -R ubuntu: "$u_path" + + echo "Inserted SSH public key from $auth_key into /home/ubuntu/.ssh/authorized_keys" + fi return 0 } @@ -284,6 +293,15 @@ copy_configuration() ttydir=" lxc" fi + # if there is exactly one veth network entry, make sure it has an + # associated hwaddr. + nics=`grep -e '^lxc\.network\.type[ \t]*=[ \t]*veth' $path/config | wc -l` + if [ $nics -eq 1 ]; then + grep -q "^lxc.network.hwaddr" $path/config || cat <<EOF >> $path/config +lxc.network.hwaddr= 00:16:3e:$(openssl rand -hex 3| sed 's/\(..\)/\1:/g; s/.$//') +EOF + fi + cat <<EOF >> $path/config lxc.utsname = $name @@ -502,16 +520,17 @@ usage() { cat <<EOF $1 -h|--help [-a|--arch] [-b|--bindhome <user>] [--trim] - [-F | --flush-cache] [-r|--release <release>] + [-F | --flush-cache] [-r|--release <release>] [ -S | --auth_key <keyfile>] release: lucid | maverick | natty | oneiric | precise trim: make a minimal (faster, but not upgrade-safe) container bindhome: bind <user>'s home into the container arch: amd64 or i386: defaults to host arch +auth_key: SSH Public key file to inject into container EOF return 0 } -options=$(getopt -o a:b:hp:r:xn:F -l arch:,bindhome:,help,path:,release:,trim,name:,flush-cache -- "$@") +options=$(getopt -o a:b:hp:r:xn:FS: -l arch:,bindhome:,help,path:,release:,trim,name:,flush-cache,auth-key: -- "$@") if [ $? -ne 0 ]; then usage $(basename $0) exit 1 @@ -561,6 +580,7 @@ do -b|--bindhome) bindhome=$2; shift 2;; -a|--arch) arch=$2; shift 2;; -x|--trim) trim_container=1; shift 1;; + -S|--auth_key) auth_key=$2; shift 2;; --) shift 1; break ;; *) break ;; esac |