Commit ce5dbd82 by Serge Hallyn Committed by Daniel Lezcano

ubuntu template: if a user is bound in, don't define ubuntu user

It might have a conflicting uid, and isn't needed. Also put the bound user into sudo group. Signed-off-by: 's avatarSerge Hallyn <serge.hallyn@ubuntu.com> Signed-off-by: 's avatarDaniel Lezcano <dlezcano@fr.ibm.com>
parent 93f29214
...@@ -54,11 +54,7 @@ EOF ...@@ -54,11 +54,7 @@ EOF
127.0.0.1 localhost $hostname 127.0.0.1 localhost $hostname
EOF EOF
if [ "$release" = "precise" ]; then if [ "$release" != "precise" ]; then
groups="sudo"
else
groups="sudo admin"
# suppress log level output for udev # suppress log level output for udev
sed -i "s/=\"err\"/=0/" $rootfs/etc/udev/udev.conf sed -i "s/=\"err\"/=0/" $rootfs/etc/udev/udev.conf
...@@ -67,22 +63,40 @@ EOF ...@@ -67,22 +63,40 @@ EOF
rm -f $rootfs/etc/init/tty{5,6}.conf rm -f $rootfs/etc/init/tty{5,6}.conf
fi fi
chroot $rootfs useradd --create-home -s /bin/bash ubuntu if [ -z "$bindhome" ]; then
echo "ubuntu:ubuntu" | chroot $rootfs chpasswd chroot $rootfs useradd --create-home -s /bin/bash ubuntu
echo "ubuntu:ubuntu" | chroot $rootfs chpasswd
fi
return 0
}
# finish setting up the user in the container by injecting ssh key and
# adding sudo group membership.
# passed-in user is either 'ubuntu' or the user to bind in from host.
finalize_user()
{
user=$1
if [ "$release" = "precise" ]; then
groups="sudo"
else
groups="sudo admin"
fi
for group in $groups; do for group in $groups; do
chroot $rootfs groupadd --system $group >/dev/null 2>&1 || true chroot $rootfs groupadd --system $group >/dev/null 2>&1 || true
chroot $rootfs adduser ubuntu $group >/dev/null 2>&1 || true chroot $rootfs adduser ${user} $group >/dev/null 2>&1 || true
done done
if [ -n "$auth_key" -a -f "$auth_key" ]; then if [ -n "$auth_key" -a -f "$auth_key" ]; then
u_path="/home/ubuntu/.ssh" u_path="/home/${user}/.ssh"
root_u_path="$rootfs/$u_path" root_u_path="$rootfs/$u_path"
mkdir -p $root_u_path mkdir -p $root_u_path
cp $auth_key "$root_u_path/authorized_keys" cp $auth_key "$root_u_path/authorized_keys"
chroot $rootfs chown -R ubuntu: "$u_path" chroot $rootfs chown -R ${user}: "$u_path"
echo "Inserted SSH public key from $auth_key into /home/ubuntu/.ssh/authorized_keys" echo "Inserted SSH public key from $auth_key into /home/${user}/.ssh/authorized_keys"
fi fi
return 0 return 0
} }
...@@ -546,6 +560,8 @@ $1 -h|--help [-a|--arch] [-b|--bindhome <user>] [--trim] [-d|--debug] ...@@ -546,6 +560,8 @@ $1 -h|--help [-a|--arch] [-b|--bindhome <user>] [--trim] [-d|--debug]
release: lucid | maverick | natty | oneiric | precise release: lucid | maverick | natty | oneiric | precise
trim: make a minimal (faster, but not upgrade-safe) container trim: make a minimal (faster, but not upgrade-safe) container
bindhome: bind <user>'s home into the container bindhome: bind <user>'s home into the container
The ubuntu user will not be created, and <user> will have
sudo access.
arch: amd64 or i386: defaults to host arch arch: amd64 or i386: defaults to host arch
auth-key: SSH Public key file to inject into container auth-key: SSH Public key file to inject into container
EOF EOF
...@@ -667,8 +683,12 @@ if [ $? -ne 0 ]; then ...@@ -667,8 +683,12 @@ if [ $? -ne 0 ]; then
fi fi
post_process $rootfs $release $trim_container post_process $rootfs $release $trim_container
if [ ! -z $bindhome ]; then
do_bindhome $rootfs $bindhome if [ -n "$bindhome" ]; then
do_bindhome $rootfs $bindhome
finalize_user $bindhome
else
finalize_user ubuntu
fi fi
echo "" echo ""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment