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}')
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 answer ; case $answer in [nN]*) exit 1 ;; esac
+fi
$command