first draft
authorThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Tue, 24 May 2011 09:51:25 +0000 (11:51 +0200)
committerThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Tue, 24 May 2011 09:51:25 +0000 (11:51 +0200)
scripts/create-vm.sh [new file with mode: 0755]

diff --git a/scripts/create-vm.sh b/scripts/create-vm.sh
new file mode 100755 (executable)
index 0000000..dfe3403
--- /dev/null
@@ -0,0 +1,41 @@
+#!/bin/bash
+
+COMMAND=$(basename $0)
+DIRNAME=$(dirname $0)
+
+BUILD="${HOME}/git-build"
+DOMAIN=pl.sophia.inria.fr
+
+function usage () {
+  message="$1" ; shift
+  echo "usage : $COMMAND hostname distro"
+  [ -n "$message" ] && echo $message
+  exit 1
+}
+
+[ -d "$BUILD" ] || usage "Could not find directory $BUILD"
+
+[[ -z "$@" ]] && usage "no hostname provided"
+hostname="$1" ; shift
+[[ -z "$@" ]] && usage "no distro provided"
+distro="$1" ; shift
+[[ -n "$@" ]] && usage "extra arguments"
+
+[ -d /vservers/$hostname ] && usage "vserver $hostname already exists in /vservers"
+[ -d /etc/vservers/.distributions/$distro ] || usage "distro $distro not known in /etc/vservers/.distributions/"
+
+fqdn=$hostname.$DOMAIN
+## compute IP
+host $fqdn | grep -q 'has address' || usage "hostname $fqdn not known to DNS"
+ip=$(host $fqdn | grep 'has address' | awk '{print $4}')
+
+cd $BUILD
+git pull
+cd -
+
+command="$BUILD/vtest-init-vserver.sh -p linux64 -f $distro $hostname none -- --netdev eth0 --interface $ip --hostname $fqdn"
+
+echo "Run $command OK ? "
+read _ ; case $_ in [nN]*) exit 1 ;; esac
+
+$command