[Lxc-users] [PATCH] ubuntu templates cleanups

Serge Hallyn serge.hallyn at canonical.com
Mon Mar 12 16:21:37 UTC 2012


1. fix inconsistent use of '--auth-key' (not --auth_key) which broke their
   usage
2. add --debug option to lxc-ubuntu (which does set -x to show what broke)
   (idea from Idea from lifeless and benji)
3. fix incorrect assumption about group with -b option.  User's default group
   may not be the same as username.
---
 templates/lxc-ubuntu-cloud.in |   13 ++++++++++---
 templates/lxc-ubuntu.in       |   16 +++++++++++-----
 2 files changed, 21 insertions(+), 8 deletions(-)

diff --git a/templates/lxc-ubuntu-cloud.in b/templates/lxc-ubuntu-cloud.in
index 2dd163f..7aef57d 100644
--- a/templates/lxc-ubuntu-cloud.in
+++ b/templates/lxc-ubuntu-cloud.in
@@ -104,18 +104,19 @@ Generic Options
 [ -a | --arch ]: Arhcitecture of container, defaults to host arcitecture
 [ -C | --cloud ]: Configure container for use with meta-data service, defaults to no
 [ -T | --tarball ]: Location of tarball
+[ -d | --debug ]: Run with 'set -x' to debug errors
 
 Options, mutually exclusive of "-C" and "--cloud":
   [ -i | --hostid ]:    HostID for cloud-init, defaults to random string
   [ -u | --userdata ]:  Cloud-init user-data file to configure container on start
-  [ -S | --auth_key ]:  SSH Public key file to inject into container
+  [ -S | --auth-key ]:  SSH Public key file to inject into container
   [ -L | --nolocales ]: Do not copy host's locales into container
 
 EOF
     return 0
 }
 
-options=$(getopt -o a:hp:r:n:Fi:CLS:T: -l arch:,help,path:,release:,name:,flush-cache,hostid:,auth-key:,cloud,no_locales,tarball: -- "$@")
+options=$(getopt -o a:hp:r:n:Fi:CLS:T:d -l arch:,help,path:,release:,name:,flush-cache,hostid:,auth-key:,cloud,no_locales,tarball:,debug -- "$@")
 if [ $? -ne 0 ]; then
     usage $(basename $0)
     exit 1
@@ -150,6 +151,7 @@ else
     fi
 fi
 
+debug=0
 hostarch=$arch
 cloud=0
 locales=1
@@ -166,14 +168,19 @@ do
     -i|--hostid)       host_id=$2; shift 2;;
     -u|--userdata)     userdata=$2; shift 2;;
     -C|--cloud)        cloud=1; shift 1;;
-    -S|--auth_key)     auth_key=$2; shift 2;;
+    -S|--auth-key)     auth_key=$2; shift 2;;
     -L|--no_locales)   locales=0; shift 2;;
     -T|--tarball)      tarball=$2; shift 2;;
+    -d|--debug)        debug=1; shift 1;;
     --)                shift 1; break ;;
         *)              break ;;
     esac
 done
 
+if [ $debug -eq ]; then
+    set -x
+fi
+
 if [ "$arch" == "i686" ]; then
     arch=i386
 fi
diff --git a/templates/lxc-ubuntu.in b/templates/lxc-ubuntu.in
index 5a5a9d5..cbebb6b 100644
--- a/templates/lxc-ubuntu.in
+++ b/templates/lxc-ubuntu.in
@@ -519,18 +519,18 @@ do_bindhome()
 usage()
 {
     cat <<EOF
-$1 -h|--help [-a|--arch] [-b|--bindhome <user>] [--trim]
-   [-F | --flush-cache] [-r|--release <release>] [ -S | --auth_key <keyfile>]
+$1 -h|--help [-a|--arch] [-b|--bindhome <user>] [--trim] [-d|--debug]
+   [-F | --flush-cache] [-r|--release <release>] [ -S | --auth-key <keyfile>]
 release: lucid | maverick | natty | oneiric | precise
 trim: make a minimal (faster, but not upgrade-safe) container
 bindhome: bind <user>'s home into the container
 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
     return 0
 }
 
-options=$(getopt -o a:b:hp:r:xn:FS: -l arch:,bindhome:,help,path:,release:,trim,name:,flush-cache,auth-key: -- "$@")
+options=$(getopt -o a:b:hp:r:xn:FS:d -l arch:,bindhome:,help,path:,release:,trim,name:,flush-cache,auth-key:,debug -- "$@")
 if [ $? -ne 0 ]; then
     usage $(basename $0)
     exit 1
@@ -566,6 +566,7 @@ else
     fi
 fi
 
+debug=0
 trim_container=0
 hostarch=$arch
 flushcache=0
@@ -580,12 +581,17 @@ do
     -b|--bindhome)  bindhome=$2; shift 2;;
     -a|--arch)      arch=$2; shift 2;;
     -x|--trim)      trim_container=1; shift 1;;
-    -S|--auth_key)  auth_key=$2; shift 2;;
+    -S|--auth-key)  auth_key=$2; shift 2;;
+    -d|--debug)     debug=1; shift 1;;
     --)             shift 1; break ;;
         *)              break ;;
     esac
 done
 
+if [ $debug -eq 1 ]; then
+    set -x
+fi
+
 pwd=`getent passwd $bindhome`
 if [ $? -ne 0 ]; then
     echo "Error: no password entry found for $bindhome"
-- 
1.7.9.1





More information about the lxc-users mailing list