#!/usr/bin/sh # This is a script to help configure a developper workstation. # See the developper guide for more information. DEVSERVER=test.bolixo.org DEVDIR=$HOME/bolixo/dev LOCALOVERRIDES=$DEVDIR/overrides.conf LOCALMANAGER=$HOME/bolixo/dev/manager.conf if [ -f $DEVDIR/devconfig.conf ] ; then . $DEVDIR/devconfig.conf fi # Shows components on which you can act showcomponents(){ echo " "all for comp in `cat $LOCALOVERRIDES` do echo " "$comp done echo " "blackhole, horizon or conproxy } # Stop all components if there is any overriden stop_all_if(){ if [ -s $LOCALOVERRIDES ] ; then $0 stop all fi } if [ "$1" = "" -o "$1" = "--tlmpdoc" -o "$1" = "--manpage" ] ; then if [ -x /usr/sbin/menutest ] ; then /usr/sbin/menutest -s $0 $1 if [ "$1" = "" ] ; then echo echo DEVSERVER=$DEVSERVER fi else echo "No menutest, can't display help" fi elif [ "$1" = "status" ] ; then # dev: shows services currently overriden cat $LOCALOVERRIDES elif [ "$1" = "override" ] ; then # dev: define the service you want to override if [ "$2" = "" ] ; then echo override none echo override service1 ... echo Service are: "bod documentd keysd publishd sessiond writed" echo echo Currently overriden services cat $LOCALOVERRIDES exit 1 elif [ "$2" = "none" ] ; then stop_all_if truncate -s0 $LOCALOVERRIDES truncate -s0 $LOCALMANAGER ssh root@$DEVSERVER truncate -s0 /etc/bolixo/overrides.conf $0 remoteconfig PASS=$HOME/bolixo/$DEVSERVER.pass if [ -f $PASS ] ; then scp $PASS root@$DEVSERVER:/root/keysd.pass fi ssh root@$DEVSERVER bo restart most else stop_all_if shift OVER= while [ "$1" != "" ] do case $1 in bod|documentd|keysd|publishd|sessiond|writed) OVER="$OVER $1" ;; *) echo "Invalid service $1, can't be overriden" exit 1 ;; esac shift done scp utils/set_overrides root@$DEVSERVER:/root echo $OVER | tr ' ' '\n' | sort | ssh root@$DEVSERVER /root/set_overrides $0 remoteconfig echo $OVER | tr ' ' '\n' | sort >$LOCALOVERRIDES ssh root@$DEVSERVER cat /etc/bolixo/secrets.client | utils/patch-secrets --devdir $HOME/bolixo/dev/comps >$HOME/bolixo/dev/secrets.client ssh root@$DEVSERVER cat /etc/bolixo/secrets.admin | utils/patch-secrets --devdir $HOME/bolixo/dev/comps >$HOME/bolixo/dev/secrets.admin scp root@$DEVSERVER:/root/bolixo.conf ~/bolixo/dev/. $0 localconfig $0 restart blackhole sleep 3 # Let blackhole $0 start all fi elif [ "$1" = "localconfig" ] ; then # dev: generate all the configuration for the workstation side # We copy the flle /root/data/manager.conf from the remote server # So we have all its secrets mkdir -p ~/bolixo/dev echo server localhost \"ssh server1\" \"cp %s %d\" 127.0.0.1 >$LOCALMANAGER echo server override \"ssh $DEVSERVER\" \"cp %s %d\" $DEVSERVER >>$LOCALMANAGER echo nodename https://$DEVSERVER >>$LOCALMANAGER echo blackhole localhost /tmp/blackhole.conf 8000 >>$LOCALMANAGER # Generate entries for overriden services OVERS= for over in `cat $LOCALOVERRIDES` do OVERS="$OVERS $over" ssh root@$DEVSERVER cat /root/data/manager.conf | grep ^$over >>$LOCALMANAGER done # Generate entries for the other services, showing they are on DEVSERVER ssh root@$DEVSERVER cat /root/data/manager.conf | while read service server rest do found=0 for over in $OVERS do if [ "$service" = "$over" -o "$service" = "iptables" -o "$service" = "" ] ; then found=1 break fi done if [ "$found" = "0" ] ; then echo $service $DEVSERVER $rest >>$LOCALMANAGER fi done # Create a small script to control the overriden processes for over in $OVERS do CONTROL=$DEVDIR/$over-control PROG=$over if [ "$over" = "writed" ] ; then PROG=bo-writed fi cat <<-EOF >$CONTROL #!/usr/bin/sh for sock in $DEVDIR/comps/$over/rootfs/var/run/blackhole/$PROG*.sock do ./$PROG-control --control \$sock \$* done EOF chmod 755 $CONTROL done . $DEVDIR/bolixo.conf ./bo-manager --overridemode -c $LOCALMANAGER \ --boduser $BOD_DBUSER --writeduser $BO_WRITED_DBUSER \ printconfig localhost elif [ "$1" = "remoteconfig" ] ; then # remote: generate all the configuration for the remote side ssh root@$DEVSERVER bo config ssh root@$DEVSERVER bo restart blackhole horizon elif [ "$1" = "remotestatus" ] ; then # remote: test system status on the remote side ssh root@$DEVSERVER bo test-system elif [ "$1" = "stopoverrides" ] ; then # remote: stop overriden services on the remote side ssh root@$DEVSERVER bo stop `cat $LOCALOVERRIDES` elif [ "$1" = "startoverrides" ] ; then # remote: start overriden services on the remote side ssh root@$DEVSERVER bo start `cat $LOCALOVERRIDES` elif [ "$1" = "control" ] ; then # admin: control a running component if [ "$2" = "" ] ; then echo Name of the component to control else CMD=$2 shift; shift if [ "$CMD" = "blackhole" ] ; then $HOME/bolixo/dev/bkcontrol.sh blackhole $* elif [ "$CMD" = "horizon" ] ; then $HOME/bolixo/dev/bkcontrol.sh horizon $* elif [ "$CMD" = "conproxy" ] ; then $HOME/bolixo/dev/bkcontrol.sh conproxy $* else SCRIPT=$HOME/bolixo/dev/$CMD-control if [ ! -x $SCRIPT ] ; then echo No script $SCRIPT exit 1 else $SCRIPT $* fi fi fi elif [ "$1" = "start" ] ; then # admin: start an overriden component shift if [ "$1" = "" ] ; then echo Name of the component to start showcomponents else for comp in $* do if [ "$comp" = "blackhole" ] ;then $DEVDIR/blackhole.sh $DEVDIR/blackhole-rules.sh elif [ "$comp" = "horizon" ] ;then $DEVDIR/horizon.sh $DEVDIR/horizon-rules.sh for comp in `cat $LOCALOVERRIDES` do echo execute component $comp horizon script $DEVDIR/comps/$comp/horizon-start.sh done elif [ "$comp" = "conproxy" ] ;then $DEVDIR/conproxy.sh elif [ "$comp" = "all" ] ;then $0 start `cat $LOCALOVERRIDES` else START=$DEVDIR/comps/$comp/$comp.start if [ ! -x "$START" ] ; then echo No start file: $START else echo Starting $comp $START fi fi done # Check for delayed script SLEEPDONE=0 for comp in $* do DELAYED=$DEVDIR/comps/$comp/$comp.start-delayed if [ -x "$DELAYED" ] ; then if [ "$SLEEPDONE" = "0" ] ; then echo sleep 2 seconds for delayed tasks sleep 2 SLEEPDONE=1 fi echo Executing delayed task for $comp $DELAYED fi done fi elif [ "$1" = "stop" ] ; then # admin: stop an overriden component shift if [ "$1" = "" ] ; then echo Name of the component to start showcomponents else while [ "$1" != "" ] do if [ "$1" = "blackhole" ] ;then /usr/sbin/blackhole-control -p /home/jacques/bolixo/dev/socks/blackhole.sock quit elif [ "$1" = "horizon" ] ;then /usr/sbin/horizon-control -p /home/jacques/bolixo/dev/socks/horizon.sock quit elif [ "$1" = "conproxy" ] ;then /usr/sbin/conproxy-control -p /home/jacques/bolixo/dev/socks/conproxy.sock quit elif [ "$1" = "all" ] ;then $0 stop `cat $LOCALOVERRIDES` else STOP=$DEVDIR/comps/$1/$1.stop if [ ! -x "$STOP" ] ; then echo No stop file: $STOP else echo Stopping $1 $STOP fi fi shift done fi elif [ "$1" = "restart" ] ; then # admin: restart an overriden component shift if [ "$1" = "" ] ; then echo Name of the component to restart showcomponents else $0 stop $* $0 start $* fi elif [ "$1" = "restartif" ] ; then # admin: restart an overriden component if needed shift if [ "$1" = "" ] ; then echo Name of the component to restart showcomponents else while [ "$1" != "" ] do if [ "$1" = "blackhole" ] ;then if [ $DEVDIR/blackhole-rules.sh -nt $DEVDIR/pid/blackhole.pid ] ; then echo Restarting $1 $0 restart blackhole fi elif [ "$1" = "horizon" ] ;then if [ $DEVDIR/hotizon-rules.sh -nt $DEVDIR/pid/horizon.pid ] ; then echo Restarting $1 $0 restart horizon fi elif [ "$1" = "all" ] ;then $0 restartif blackhole horizon `cat $LOCALOVERRIDES` elif [ "$1" = "writed" ] ; then if [ bo-writed -nt $DEVDIR/pid/writed-0.pid ] ; then echo Restarting $1 $0 restart writed fi elif [ "$1" = "bod" ] ; then if [ bod -nt $DEVDIR/pid/bod-0.pid ] ; then echo Restarting $1 $0 restart bod fi else echo "Don't know how to restartif $1" exit 1 fi shift done fi elif [ "$1" = "install-msgs" ] ; then # admin: install dictionnaries for translations if [ "$2" != "fr" -a "$2" != "eng" -o "$3" = "" ] ; then echo install-msgs lang dictionary exit 1 else DIR=$DEVDIR/comps/help.$2 mkdir -p $DIR install -m 644 $3 $DIR/. fi else echo devconfig command ... exit 1 fi