#!/bin/bash SCENARIO="test.scenario" PROGRAM=$0 ERR_INVALID_ARGUMENT=1 ERR_NOT_DEFINED_ATTRIBUTE=2 ERR_NOT_FOUND_FILE=72 usage() { echo "Usage: $0 [command] [command-arguments]" echo echo "Commands:" echo " install [RC NUMBER] Deploy all necessary files." echo " start Starts peers and UAs." echo " stop Stops peers and UAs." echo " clean Remove all installed files." echo echo "Edit $SCENARIO file to set sites configuration." exit $ERR_INVALID_ARGUMENT } getproperty() { attribute=$1 value=`grep "^ *$attribute" $SCENARIO | awk -F '=' '{ print $2 }'` if [ -z "$value" ]; then exit $ERR_NOT_DEFINED_ATTRIBUTE fi echo $value } getnumberofgums() { site=$1 value=`grep "^ *$site\.gum\..*\.name" $SCENARIO | wc -l` echo value } # NOT USED IN OUR TEST SCENARIO # #createcorepeerproperties() { # # name=`getproperty corepeer.name` # port=`getproperty corepeer.port` # # corepeerfile="core-peer.properties" # # echo "# CorePeer properties file." > $corepeerfile # echo >> $corepeerfile # echo "peer.corepeername=$name" >> $corepeerfile # echo "peer.corepeerport=$port" >> $corepeerfile # #} createsitepeerproperties() { site=$1 corepeername=`getproperty corepeer.name` corepeerport=`getproperty corepeer.port` name=`getproperty $site.peer.name` port=`getproperty $site.peer.port` peerfile="$site/peer.properties" echo "# $site Peer proeprties." > $peerfile echo >> $peerfile defaultproppeerlist=`grep "^ *$site\.peer\." $SCENARIO | awk -F '.' '{ print $3 }' | awk -F '=' '{ print $1 }'` for defaultproppeer in $defaultproppeerlist; do defaultproppeervalue=`getproperty $site.peer.$defaultproppeer` echo "peer.$defaultproppeer=$defaultproppeervalue" >> $peerfile done echo "peer.corepeername=$corepeername" >> $peerfile echo "peer.corepeerport=$corepeerport" >> $peerfile } createsdf() { site=$1 numberofgums=`getnumberofgums $site` gumslist=`grep "^ *$site\.gum\..*\.name" $SCENARIO | awk -F '.' '{ print $3 }'` sdffile="$site/peer.sdf" echo "gumdefaults:" > $sdffile echo " type : ualinux" >> $sdffile echo " os : linux" >> $sdffile echo ' remExec : ssh -x $machine $command' >> $sdffile echo ' copyFrom : scp $machine:$remotefile $localfile' >> $sdffile echo ' copyTo : scp $localfile $machine:$remotefile' >> $sdffile defaultproplist=`grep "^ *$site\.gum\.default\." $SCENARIO | awk -F '.' '{ print $4 }' | awk -F '=' '{ print $1 }'` for defaultprop in $defaultproplist; do defaultpropvalue=`getproperty $site.gum.default.$defaultprop` echo " $defaultprop : $defaultpropvalue" >> $sdffile done for gum in $gumslist; do proplist=`grep "^ *$site\.gum\.$gum\." $SCENARIO | awk -F '.' '{ print $4 }' | awk -F '=' '{ print $1 }'` echo "gum : " >> $sdffile for prop in $proplist; do propvalue=`getproperty $site.gum.$gum.$prop` echo " $prop : $propvalue" >> $sdffile done done } siteslist() { list=`grep "^ *site.*\.gum\..*\.name" $SCENARIO | awk -F '.' '{ print $1 }' | uniq` echo $list } createsitessdfs() { sites=`siteslist` # corepeerallow="core-peers.allows" # echo -n > $corepeerallow for a in $sites; do # echo $a >> $corepeerallow mkdir $a createsitepeerproperties $a createsdf $a cp peerscript.sh "$a/peerscript.sh" done } # COREPEER IS NOT INSTALLED HERE. # #installcorepeer() { # #} install() { echo "Creating site's files..." createsitessdfs #> /dev/null distfilepeer=$1 distfileuser=$2 sites=`siteslist` for a in $sites; do installdir=`getproperty $a.install` peername=`getproperty $a.peer.name` peeruser=`getproperty $a.user` ssh $peeruser@$peername -x "mkdir -p $installdir; cd $installdir; rm peer*.tar.gz" & scp $distfilepeer $distfileuser $a/* $peeruser@$peername:$installdir ssh $peeruser@$peername -x "cd $installdir; ./peerscript.sh install" & done } start() { sites=`siteslist` for a in $sites; do installdir=`getproperty $a.install` peername=`getproperty $a.peer.name` peeruser=`getproperty $a.user` ssh $peeruser@$peername -x "cd $installdir; ./peerscript.sh start" & done } stop() { sites=`siteslist` for a in $sites; do installdir=`getproperty $a.install` peername=`getproperty $a.peer.name` peeruser=`getproperty $a.user` ssh $peeruser@$peername -x "cd $installdir; ./peerscript.sh stop" & done } clean() { sites=`siteslist` for a in $sites; do installdir=`getproperty $a.install` peername=`getproperty $a.peer.name` peeruser=`getproperty $a.user` ssh $peeruser@$peername -x "cd $installdir; ./peerscript.sh clean" & ssh $peeruser@$peername -x "rm -rf $installdir" & done } if [ $# -lt 1 ] || [ $# -gt 2 ]; then usage fi command=$1 version=$2 distrdir="." #mygriddistr="$distrdir/mygrid-3.3.1-RC$version.tar.gz" peerdistr="$distrdir/peer-3.3.1-RC$version.tar.gz" userdistr="$distrdir/useragent-3.3.1-RC$version.tar.gz" if [ ! -f $peerdistr ] || [ ! -f $userdistr ]; then echo "You must have the files:" echo "- $peerdistr" echo "- $userdistr" exit $ERR_NOT_FOUND_FILE fi case $command in install) if [ $# -ne 2 ]; then usage fi echo "Installing all sites..." install $peerdistr $userdistr &#> /dev/null ;; start) echo "Starting all sites..." start &#> /dev/null ;; stop) echo "Stopping all sites..." stop &#> /dev/null ;; clean) echo "Cleaning all sites..." clean &#> /dev/null ;; *) echo "$0 $1: Invalid Command." echo usage ;; esac