configurable hostname as optional third param
authorDobrica Pavlinusic <dpavlin@rot13.org>
Wed, 21 Oct 2009 12:06:10 +0000 (12:06 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Wed, 21 Oct 2009 12:06:10 +0000 (12:06 +0000)
git-svn-id: svn://svn.rot13.org/sysadmin-cookbook@151 191e9f34-6774-4a6d-acfc-7664dacd4a2a

recepies/lxc/ve2lxc.sh

index fd55681..854f643 100755 (executable)
@@ -1,14 +1,15 @@
 #!/bin/sh -x
 
-test -z "$1" && echo "usage: $0 /path/to/ve/private [10.60.0.253]" && exit
+test -z "$1" && echo "usage: $0 /path/to/ve/private [10.60.0.253 [hostname]]" && exit
 
 dir=$1
-hostname=ve2lxc
 ip=$2
+hostname=$3
 netmask=`grep netmask /etc/network/interfaces | head -1 | sed 's/^.*netmask *//'`
 gateway=`grep gateway /etc/network/interfaces | head -1 | sed 's/^.*gateway *//'`
 
-test -z "$ip" && ip=10.60.0.253
+test -z "$ip" && ip=10.60.0.252
+test -z "$hostname" && hostname=ve2lxc
 
 path=/$dir/etc/inittab
 tmp=/tmp/inittab
@@ -32,8 +33,8 @@ if ! diff -uw $path $tmp ; then
        cp $path $path.old && mv $tmp $path
 fi
 
-lxc-stop -n ve2lxc
-lxc-destroy -n ve2lxc
+lxc-stop -n $hostname
+lxc-destroy -n $hostname
 
 test -d /cgroup || mkdir /cgroup
 grep /cgroup /etc/fstab || echo "cgroup /cgroup cgroup rw 0 0" >> /etc/fstab
@@ -54,7 +55,7 @@ echo $hostname > $dir/etc/hostname
 
 echo "$ip $hostname" >> $dir/etc/hosts
 
-conf=/tmp/ve2lxc.conf
+conf=/tmp/$hostname.conf
 
 cat << __lxc__ > $conf
 lxc.utsname = $hostname
@@ -89,4 +90,4 @@ cp -v /etc/resolv.conf /$dir/etc/resolv.conf
 
 mount | grep /cgroup || mount /cgroup || exit
 
-lxc-create -n ve2lxc -f $conf && lxc-start -n ve2lxc
+lxc-create -n $hostname -f $conf && lxc-start -n $hostname