first draft
[infrastructure.git] / scripts / create-vm.sh
1 #!/bin/bash
2
3 COMMAND=$(basename $0)
4 DIRNAME=$(dirname $0)
5
6 BUILD="${HOME}/git-build"
7 DOMAIN=pl.sophia.inria.fr
8
9 function usage () {
10   message="$1" ; shift
11   echo "usage : $COMMAND hostname distro"
12   [ -n "$message" ] && echo $message
13   exit 1
14 }
15
16 [ -d "$BUILD" ] || usage "Could not find directory $BUILD"
17
18 [[ -z "$@" ]] && usage "no hostname provided"
19 hostname="$1" ; shift
20 [[ -z "$@" ]] && usage "no distro provided"
21 distro="$1" ; shift
22 [[ -n "$@" ]] && usage "extra arguments"
23
24 [ -d /vservers/$hostname ] && usage "vserver $hostname already exists in /vservers"
25 [ -d /etc/vservers/.distributions/$distro ] || usage "distro $distro not known in /etc/vservers/.distributions/"
26
27 fqdn=$hostname.$DOMAIN
28 ## compute IP
29 host $fqdn | grep -q 'has address' || usage "hostname $fqdn not known to DNS"
30 ip=$(host $fqdn | grep 'has address' | awk '{print $4}')
31
32 cd $BUILD
33 git pull
34 cd -
35
36 command="$BUILD/vtest-init-vserver.sh -p linux64 -f $distro $hostname none -- --netdev eth0 --interface $ip --hostname $fqdn"
37
38 echo "Run $command OK ? "
39 read _ ; case $_ in [nN]*) exit 1 ;; esac
40
41 $command