create-vm.sh: add option -I image - to specify the location of the rootfs
[infrastructure.git] / scripts / create-vm.sh
index f4e18d8..b879490 100755 (executable)
@@ -4,57 +4,63 @@ COMMAND=$(basename $0)
 DIRNAME=$(dirname $0)
 
 BUILD="${HOME}/git-build"
+
+echo "Updating $BUILD"
+cd $BUILD
+git pull
+cd -
+
+LOGS=$HOME/machines
+
+[ -d $LOGS ] || { echo "Creating logs dir $LOGS" ; mkdir -p $LOGS; } 
+
 DOMAIN=pl.sophia.inria.fr
 
-DEFAULT_DISTRO=f14
-DEFAULT_PERSO=linux64
+DEFAULT_DISTRO=f20
+# do not care about 32 bits anymore
+#DEFAULT_PERSO=linux64
 
 INTERACTIVE=
 DISTRO=$DEFAULT_DISTRO
-PERSO=$DEFAULT_PERSO
 function usage () {
-  message="$1" ; shift
-  echo "usage : $COMMAND [-i] [-f distro] [-p perso] hostname"
+  message="$@" 
+  echo "usage : $COMMAND [-i] [-f distro] [-I Image] hostname"
   echo "  default distro is $DEFAULT_DISTRO"
-  echo "  default perso is $DEFAULT_PERSO"
   [ -n "$message" ] && echo $message
   exit 1
 }
 
-while getopts "fp:ih" flag; do
+while getopts "f:I:ih" flag; do
     case $flag in
        f) DISTRO=$OPTARG;;
-       p) PERSO=$OPTARG;;
        i) INTERACTIVE=true ;;
+        I) IMAGE=$OPTARG;;
        ?|h) usage "" ;;
     esac
 done
 shift $((OPTIND-1))
 [[ -z "$@" ]] && usage "no hostname provided"
-HOSTNAME="$1" ; shift
-[[ -n "$@" ]] && usage "extra arguments"
+container="$1" ; shift
+[[ -n "$@" ]] && usage "extra arguments"  "$@" "(hostname=$container)"
 
 
 [ -d "$BUILD" ] || usage "Could not find directory $BUILD"
 
-[ -d /vservers/$HOSTNAME ] && usage "vserver $HOSTNAME already exists in /vservers"
-[ -d /etc/vservers/.distributions/$DISTRO ] || usage "distro $DISTRO not known in /etc/vservers/.distributions/"
+[ -d /vservers/$container ] && usage "container $container already exists in /vservers"
 
-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}')
+fqdn=$container.$DOMAIN
 
-cd $BUILD
-git pull
-cd -
-
-# single_ip needs to be turned off, vtest-init-vserver now takes care of that
-command="$BUILD/vtest-init-vserver.sh -p $PERSO -f $DISTRO $HOSTNAME none -- --interface nodev:$ip --hostname $fqdn"
+if [ -n "$IMAGE" ]; then
+  command="$BUILD/lbuild-initvm.sh -f $DISTRO -n $fqdn -i $IMAGE $container"
+else
+  command="$BUILD/lbuild-initvm.sh -f $DISTRO -n $fqdn $container"
+fi
 
 if [ -n "$INTERACTIVE" ] ; then
     echo -n "Run $command OK ? "
     read answer ; case $answer in [nN]*) exit 1 ;; esac
 fi
 
-$command
+echo "Storing output in $LOGS/$container.log"
+$command >& $LOGS/$container.log
+