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 <serge.hallyn@ubuntu.com>
This commit is contained in:
Scott Moser 2012-09-04 15:44:25 -05:00 committed by Stéphane Graber
parent fbef4590b7
commit b942e67226

View File

@ -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" <<EOF
instance_id: lxc-$host_id
cat > "$seed_d/meta-data" <<EOF
instance-id: lxc-$host_id
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
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" <<EOF
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
fi
else
chroot $rootfs /usr/sbin/usermod -U ubuntu
echo "ubuntu:ubuntu" | chroot $rootfs chpasswd
echo "Please login as user ubuntu with password ubuntu."
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."
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