fix redirection
[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
8 echo "Updating $BUILD"
9 cd $BUILD
10 git pull
11 cd -
12
13 LOGS=$HOME/machines
14
15 [ -d $LOGS ] || { echo "Creating logs dir $LOGS" ; mkdir -p $LOGS; } 
16
17 DOMAIN=pl.sophia.inria.fr
18
19 DEFAULT_DISTRO=f20
20 # do not care about 32 bits anymore
21 #DEFAULT_PERSO=linux64
22
23 INTERACTIVE=
24 DISTRO=$DEFAULT_DISTRO
25 function usage () {
26   message="$@" 
27   echo "usage : $COMMAND [-i] [-f distro] hostname"
28   echo "  default distro is $DEFAULT_DISTRO"
29   [ -n "$message" ] && echo $message
30   exit 1
31 }
32
33 while getopts "f:ih" flag; do
34     case $flag in
35         f) DISTRO=$OPTARG;;
36         i) INTERACTIVE=true ;;
37         ?|h) usage "" ;;
38     esac
39 done
40 shift $((OPTIND-1))
41 [[ -z "$@" ]] && usage "no hostname provided"
42 container="$1" ; shift
43 [[ -n "$@" ]] && usage "extra arguments"  "$@" "(hostname=$container)"
44
45
46 [ -d "$BUILD" ] || usage "Could not find directory $BUILD"
47
48 [ -d /vservers/$container ] && usage "container $container already exists in /vservers"
49
50 fqdn=$container.$DOMAIN
51
52 command="$BUILD/lbuild-initvm.sh -f $DISTRO -n $fqdn $container"
53
54 if [ -n "$INTERACTIVE" ] ; then
55     echo -n "Run $command OK ? "
56     read answer ; case $answer in [nN]*) exit 1 ;; esac
57 fi
58
59 $command >& $LOGS/$container.log
60