From:  Scott Moser <smo...@ubuntu.com>
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 <serge.hal...@ubuntu.com>
---
 templates/lxc-ubuntu-cloud.in |  109 +++++++++++++++++++++--------------------
 1 file changed, 57 insertions(+), 52 deletions(-)

diff --git a/templates/lxc-ubuntu-cloud.in b/templates/lxc-ubuntu-cloud.in
index a87a979..722d47f 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
@@ -258,17 +267,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()
@@ -321,7 +330,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
@@ -335,67 +344,63 @@ 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" <<EOF
-instance_id: lxc-$host_id
+        cat > "$seed_d/meta-data" <<EOF
+instance-id: lxc-$host_id
 EOF
-
-       rm $rootfs/etc/hostname
-
-       if [ $locales -eq 1 ]; then
-               cp /usr/lib/locale/locale-archive 
$rootfs/usr/lib/locale/locale-archive
-       fi
-
-
-       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
-
-       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" <<EOF
+        if [ -n "$auth_key" ]; then
+            {
+            echo "public-keys:" &&
+            sed -e '/^$/d' -e 's,^,- ,' "$auth_key" "$auth_key"
+            } >> "$seed_d/meta-data"
+            [ $? -eq 0 ] ||
+                { echo "failed to write public keys to metadata"; exit 1; }
+        fi
+
+        rm $rootfs/etc/hostname
+
+        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 [ -z "$MIRROR" ]; then
+                MIRROR="http://archive.ubuntu.com/ubuntu";
+            fi
+
+            cat > "$seed_d/user-data" <<EOF
 #cloud-config
 output: {all: '| tee -a /var/log/cloud-init-output.log'}
-apt-mirror: $MIRROR
+apt_mirror: $MIRROR
 manage_etc_hosts: localhost
 locale: $(/usr/bin/locale | awk -F= '/LANG=/ {print$NF}')
+password: ubuntu
+chpasswd: { expire: False }
 EOF
-       fi
-
-       chroot $rootfs /usr/sbin/usermod -U ubuntu
-       echo "ubuntu:ubuntu" | chroot $rootfs chpasswd
-       echo "Please login as user ubuntu with password ubuntu."
+        fi
 
-   else
-
-       echo "Configured for running in a cloud environment."
-       echo "If you do not have a meta-data service, this container will 
likely be useless."
+    else
 
-   fi
+        echo "Configured for running in a cloud environment."
+        echo "If you do not have a meta-data service, this container will 
likely be useless."
 
+    fi
 ) 200>/var/lock/subsys/lxc-ubucloud
 
 copy_configuration $path $rootfs $name $arch $release
 
 echo "Container $name created."
 exit 0
+
+# vi: ts=4 expandtab
-- 
1.7.10.4


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel

Reply via email to