]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
ubuntu template: install bound user's shell
authorSerge Hallyn <serge.hallyn@ubuntu.com>
Tue, 31 Jul 2012 14:01:28 +0000 (16:01 +0200)
committerDaniel Lezcano <daniel.lezcano@free.fr>
Tue, 31 Jul 2012 14:01:28 +0000 (16:01 +0200)
If a host user is bound into the container (-b), make sure that his
shell is installed in the container.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
templates/lxc-ubuntu.in

index f3fb8dcc4de8f184769f1a9f9619fac0deb1c3de..f31bc789c55a67b856cb1f9292737b61d652e7c5 100644 (file)
@@ -506,20 +506,31 @@ do_bindhome()
     user=$2
 
     # copy /etc/passwd, /etc/shadow, and /etc/group entries into container
-    pwd=`getent passwd $user`
-    if [ $? -ne 0 ]; then
-        echo 'Warning: failed to copy password entry for $user'
-       return
-    else
-        echo $pwd >> $rootfs/etc/passwd
+    pwd=`getent passwd $user` || { echo "Failed to copy password entry for $user"; false; }
+    echo $pwd >> $rootfs/etc/passwd
+
+    # make sure user's shell exists in the container
+    shell=`echo $pwd | cut -d: -f 7`
+    if [ ! -x $rootfs/$shell ]; then
+        echo "shell $shell for user $user was not found in the container."
+        pkg=`dpkg -S $(readlink -m $shell) | cut -d ':' -f1`
+        echo "Installing $pkg"
+        chroot $rootfs apt-get --force-yes -y install $pkg
     fi
+
     shad=`getent shadow $user`
-    echo $shad >> $rootfs/etc/shadow
+    echo "$shad" >> $rootfs/etc/shadow
 
     # bind-mount the user's path into the container's /home
     h=`getent passwd $user | cut -d: -f 6`
     mkdir -p $rootfs/$h
     echo "$h $rootfs/$h none bind 0 0" >> $path/fstab
+
+    # Make sure the group exists in container
+    chroot $rootfs getent group $user || { \
+        grp=`getent group $user`
+        echo "$grp" >> $rootfs/etc/group
+    }
 }
 
 usage()