From b942e67226af9e690bd63ac440b99aedb6becbb3 Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Tue, 4 Sep 2012 15:44:25 -0500 Subject: [PATCH] ubuntu-cloud template cleanups Fix for quantal images which do not have the user 'ubuntu' present. Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/lxc/+bug/1045955 Signed-off-by: Serge Hallyn --- templates/lxc-ubuntu-cloud.in | 100 ++++++++++++++++++---------------- 1 file changed, 52 insertions(+), 48 deletions(-) diff --git a/templates/lxc-ubuntu-cloud.in b/templates/lxc-ubuntu-cloud.in index ab8040f2d..349830999 100644 --- a/templates/lxc-ubuntu-cloud.in +++ b/templates/lxc-ubuntu-cloud.in @@ -230,6 +230,15 @@ if [ -n "$userdata" ]; then fi fi +if [ -n "$auth_key" ]; then + if [ ! -f "$auth_key" ]; then + echo "--auth-key=${auth_key} must reference a file" + exit 1 + fi + auth_key=$(readlink -f "${auth_key}") || + { echo "failed to get full path for auth_key"; exit 1; } +fi + if [ -z "$path" ]; then echo "'path' parameter is required" exit 1 @@ -252,17 +261,17 @@ cache="/var/cache/lxc/cloud-$release" mkdir -p $cache if [ -n "$tarball" ]; then - url2="$tarball" + url2="$tarball" else - url1=`ubuntu-cloudimg-query $release $stream $arch --format "%{url}\n"` - url2=`echo $url1 | sed -e 's/.tar.gz/-root\0/'` + url1=`ubuntu-cloudimg-query $release $stream $arch --format "%{url}\n"` + url2=`echo $url1 | sed -e 's/.tar.gz/-root\0/'` fi filename=`basename $url2` wgetcleanup() { - rm -f $filename + rm -f $filename } buildcleanup() @@ -315,7 +324,7 @@ mkdir -p /var/lock/subsys/ trap wgetcleanup EXIT SIGHUP SIGINT SIGTERM if [ ! -f $filename ]; then - wget $url2 || build_root_tgz $url1 $filename + wget $url2 || build_root_tgz $url1 $filename fi trap EXIT trap SIGHUP @@ -329,67 +338,62 @@ mkdir -p /var/lock/subsys/ if [ $cloud -eq 0 ]; then - echo "Configuring for running outside of a cloud environment" - echo "If you want to configure for a cloud evironment, please use '-- -C' to create the container" + echo "Configuring for running outside of a cloud environment" + echo "If you want to configure for a cloud evironment, please use '-- -C' to create the container" - seed_d=$rootfs/var/lib/cloud/seed/nocloud-net - rhostid=$(uuidgen | cut -c -8) - host_id=${hostid:-$rhostid} - mkdir -p $seed_d + seed_d=$rootfs/var/lib/cloud/seed/nocloud-net + rhostid=$(uuidgen | cut -c -8) + host_id=${hostid:-$rhostid} + mkdir -p $seed_d - cat > "$seed_d/meta-data" < "$seed_d/meta-data" <> "$seed_d/meta-data" + [ $? -eq 0 ] || + { echo "failed to write public keys to metadata"; exit 1; } + fi - rm $rootfs/etc/hostname + rm $rootfs/etc/hostname - if [ $locales -eq 1 ]; then - cp /usr/lib/locale/locale-archive $rootfs/usr/lib/locale/locale-archive - fi + if [ $locales -eq 1 ]; then + cp /usr/lib/locale/locale-archive $rootfs/usr/lib/locale/locale-archive + fi + if [ -f "$userdata" ]; then + echo "Using custom user-data" + cp $userdata $seed_d/user-data + else - 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" + if [ -z "$MIRROR" ]; then + MIRROR="http://archive.ubuntu.com/ubuntu" + fi - echo "Inserted SSH public key from $auth_key into /home/ubuntu/.ssh/authorized_keys" - fi - - if [ -f "$userdata" ]; then - echo "Using custom user-data" - cp $userdata $seed_d/user-data - else - - if [ -z "$MIRROR" ]; then - MIRROR="http://archive.ubuntu.com/ubuntu" - fi - - cat > "$seed_d/user-data" < "$seed_d/user-data" </var/lock/subsys/lxc-ubucloud copy_configuration $path $rootfs $name $arch $release echo "Container $name created." exit 0 + +# vi: ts=4 expandtab