#!/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
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
echo "$ip $hostname" >> $dir/etc/hosts
-conf=/tmp/ve2lxc.conf
+conf=/tmp/$hostname.conf
cat << __lxc__ > $conf
lxc.utsname = $hostname
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