Description: add --debug option to ubuntu templates
 It does 'set -x' to help debug problems with container creation
 Idea from lifeless and benji.
Author: Serge Hallyn <serge.hallyn@ubuntu.com>
Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/lxc/+bug/942847
Forwarded: yes

Index: lxc/templates/lxc-ubuntu-cloud.in
===================================================================
--- lxc.orig/templates/lxc-ubuntu-cloud.in	2012-02-23 16:21:13.750796000 -0600
+++ lxc/templates/lxc-ubuntu-cloud.in	2012-02-28 14:42:06.271423928 -0600
@@ -104,6 +104,7 @@
 [ -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
@@ -115,7 +116,7 @@
     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 @@
     fi
 fi
 
+debug=0
 hostarch=$arch
 cloud=0
 locales=1
@@ -169,11 +171,16 @@
     -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
Index: lxc/templates/lxc-ubuntu.in
===================================================================
--- lxc.orig/templates/lxc-ubuntu.in	2012-02-28 11:54:27.285544110 -0600
+++ lxc/templates/lxc-ubuntu.in	2012-02-28 14:39:26.674632535 -0600
@@ -527,7 +527,7 @@
 usage()
 {
     cat <<EOF
-$1 -h|--help [-a|--arch] [-b|--bindhome <user>] [--trim]
+$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
@@ -540,7 +540,7 @@
     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
@@ -576,6 +576,7 @@
     fi
 fi
 
+debug=0
 trim_container=0
 hostarch=$arch
 flushcache=0
@@ -591,11 +592,16 @@
     -a|--arch)      arch=$2; shift 2;;
     -x|--trim)      trim_container=1; shift 1;;
     -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"
