From: Thierry Parmentelat Date: Thu, 26 May 2011 09:54:08 +0000 (+0200) Subject: usage now is $0 [-i] [-f f12] [-p linux32] hostname X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;ds=sidebyside;h=d42bab2443e72a3cf9969a7c688b8e2f0c35809f;p=infrastructure.git usage now is $0 [-i] [-f f12] [-p linux32] hostname --- diff --git a/scripts/create-vm.sh b/scripts/create-vm.sh index dfe3403..8672d67 100755 --- a/scripts/create-vm.sh +++ b/scripts/create-vm.sh @@ -6,25 +6,41 @@ DIRNAME=$(dirname $0) BUILD="${HOME}/git-build" DOMAIN=pl.sophia.inria.fr +DEFAULT_DISTRO=f14 +DEFAULT_PERSO=linux64 + +INTERACTIVE= +DISTRO=$DEFAULT_DISTRO +PERSO=$DEFAULT_PERSO function usage () { message="$1" ; shift - echo "usage : $COMMAND hostname distro" + echo "usage : $COMMAND [-i] [-f distro] [-p perso] hostname" + echo " default distro is $DEFAULT_DISTRO" + echo " default perso is $DEFAULT_PERSO" [ -n "$message" ] && echo $message exit 1 } -[ -d "$BUILD" ] || usage "Could not find directory $BUILD" - +while getopts "fp:ih" flag; do + case $flag in + f) DISTRO=$OPTARG;; + p) PERSO=$OPTARG;; + i) INTERACTIVE=true ;; + ?|h) usage "" ;; + esac +done +shift $((OPTIND-1)) [[ -z "$@" ]] && usage "no hostname provided" -hostname="$1" ; shift -[[ -z "$@" ]] && usage "no distro provided" -distro="$1" ; shift +HOSTNAME="$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 +[ -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/" + +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}') @@ -33,9 +49,12 @@ cd $BUILD git pull cd - -command="$BUILD/vtest-init-vserver.sh -p linux64 -f $distro $hostname none -- --netdev eth0 --interface $ip --hostname $fqdn" +command="$BUILD/vtest-init-vserver.sh -p $PERSO -f $DISTRO $HOSTNAME none -- --netdev eth0 --interface $ip --hostname $fqdn" -echo "Run $command OK ? " -read _ ; case $_ in [nN]*) exit 1 ;; esac +if [ -n "$INTERACTIVE" ] ; then + echo "Run $command OK ? " + read _ ; case $_ in [nN]*) exit 1 ;; esac +fi +echo YES $command ; exit $command