view scripts/launcher/launch.sh @ 4:a6af040be754

add screenshot for v0.5, Libervia's overview
author souliane <souliane@mailoo.org>
date Wed, 02 Jul 2014 19:54:12 +0200
parents 73d3b94b7364
children 19448ad3a7d9
line wrap: on
line source

#!/bin/bash

# This is a helping script to do some tasks like installing, cleaning, starting sat and/or libervia.

# Python dist-packages where project are installed
PACKAGES=/usr/local/lib/python2.7/dist-packages

# Paths to the projects
WORKSPACE=~/workspace
SAT=$WORKSPACE/sat
PYJS=$WORKSPACE/pyjamas
LIBERVIA=$WORKSPACE/libervia
PROSODY=$WORKSPACE/prosody-hg
SATPUBSUB=$WORKSPACE/sat_pubsub
URWID_SATEXT=$WORKSPACE/urwid_satext

# PIDs of the processes
LOCAL_DIR=~/.local/share/sat
SAT_PID=$LOCAL_DIR/sat.pid
LIB_PID=$LOCAL_DIR/libervia.pid
SER_PID=$PROSODY/prosody.pid
SPS_PID=$SATPUBSUB/twistd.pid

# Connection information for sat_pubsub
SPS_JID=sat-pubsub.souliane.org
SPS_PWD=password

# Informations for a concurrent sat instance
# For this to work, you have to follow the instructions in:
# http://wiki.goffi.org/wiki/Howto_launch_several_S%C3%A0T_instances
# Also:
#     - modify const_INT_PREFIX in the two DBus.py files
#     - set DAEMON="" in the sat.sh to launch sat as a daemon
SAT_MAIN=$WORKSPACE/sat_main
SAT_MAIN_PID=~/.sat_main/sat.pid

# 4 Firefox profiles names for testing
FF_PROFILES=(test1 test2 test3 test4)
# 4 S�T profiles names for testing
SAT_PROFILES=(Peter Steven Dave Dino)
# Passwords for these profiles
SAT_PROFILES_PASSWD=(xxxxxx xxxxxx xxxxxx xxxxxx)

# Launch sat in debug mode?
SAT_DEBUG=1
# Launch sat pubsub in debug mode?
SPS_DEBUG=0
# Launch libervia in debug mode?
LIB_DEBUG=1
# Force killing processes?
KILL_FORCE=1

kill_process() {
    # $1 is the file containing the PID to kill
    if [ -f $1 ]; then
        PID=`cat $1`
        if ps -p $PID > /dev/null; then
            if [[ $KILL_FORCE = 1 ]]; then
                kill -9 $PID
            else
                kill -INT $PID
            fi
        fi
        rm -f $1
    fi
}

stop_lib() {
    echo "############ Stopping libervia ############"
    libervia stop
    kill_process $LIB_PID
}
stop_sat() {
    echo "############### Stopping sat ##############"
    sat stop
    kill_process $SAT_PID
}
stop_ser() {
    echo "############# Stopping Prosody ############"
    cd $PROSODY && if [[ -f $SER_PID ]]; then ./prosodyctl stop; fi
    kill_process $SER_PID
    echo "########### Stopping sat_pubsub ###########"
    kill_process $SPS_PID
}
start_ser() {
    echo "############# Starting Prosody ############"
    cd $PROSODY && ./prosodyctl start
    echo "########## Installing sat_pubsub ##########"
    cd $SATPUBSUB && sudo python setup.py install
    echo "########### Starting sat-pubsub ###########"
    if [[ $SPS_DEBUG = 1 ]]; then
        mate-terminal -e "twistd -n -b sat_pubsub --jid=$SPS_JID --secret=$SPS_PWD" &
    else
        twistd sat_pubsub --jid=$SPS_JID --secret=$SPS_PWD
    fi
}
start_sat() {
    echo "############## Installing sat #############"
    cd $SAT && sudo python setup.py install
    echo "############### Starting sat ##############"
    if [[ $SAT_DEBUG = 1 ]]; then
        mate-terminal -e "sat debug" &
    else
        sat
    fi
}
start_lib() {
    echo "########### Installing libervia ###########"
    cd $LIBERVIA && sudo python setup.py install
    echo "############ Starting libervia ############"
    cd src
    if [[ $LIB_DEBUG = 1 ]]; then
        mate-terminal -e "libervia debug" &
    else
        libervia
    fi
}
4foxes() {
    # Starts 4 instances of firefox and connect S�T profiles with Libervia
    # Assumes the HTTPS port for local server is 8443
    echo "####### Starting 4 libervia clients #######"
    for I in `seq 0 3`; do
        URL="https://localhost:8443/libervia.html?login=${SAT_PROFILES[$I]}&passwd=${SAT_PROFILES_PASSWD[$I]}"
        firefox -no-remote -P ${FF_PROFILES[$I]} "$URL" &
    done
}
clean() {
    echo "############ Cleaning log files ###########"
    rm -f $LOCAL_DIR/*.log*
    rm -f $SATPUBSUB/twistd.log*
    rm -f $PROSODY/prosody.log* $PROSODY/prosody.err*
}
purge() {
    echo "######## Purging installed packages #######"
    rm -rf $PACKAGES/sat
    rm -rf $PACKAGES/sat_frontends
    rm -rf $PACKAGES/libervia
    rm -rf $PACKAGES/libervia_server
}
main() {
    echo "######## Starting S�T main instance #######"
    export PYTHONPATH=$SAT_MAIN/lib
    cd $SAT_MAIN/lib/sat && hg pull -u && ./sat.sh
    echo "#### Starting primitivus main instance ####"
    cd $SAT_MAIN/lib/sat_frontends/primitivus && ./primitivus
}
bridge() {
    echo "######### Generating DBus.py files ########"
    cd $SAT/src/bridge/bridge_constructor
    ./bridge_constructor.py --force && cp generated/DBus.py ../DBus.py
    ./bridge_constructor.py -s frontend --force && cp generated/DBus.py ../../../frontends/src/bridge/DBus.py
    cd $SAT_MAIN/src/bridge/bridge_constructor
    SAT_BRIDGE_CONST_INT_PREFIX='"org.goffi.sat_main"' ./bridge_constructor.py --force && cp generated/DBus.py ../DBus.py
    SAT_BRIDGE_CONST_INT_PREFIX='"org.goffi.sat_main"' ./bridge_constructor.py -s frontend  --force && cp generated/DBus.py ../../../frontends/src/bridge/DBus.py
}
monitor() {
    echo "## Monitoring DBus for S�T main instance ##"
    killall -q dbus-monitor
    nohup dbus-monitor "sender='org.goffi.sat_main', interface='org.goffi.sat_main.core'" >> /tmp/sat_xml_core_`date +%y.%m.%d`&
    nohup dbus-monitor "sender='org.goffi.sat_main', interface='org.goffi.sat_main.plugin'" >> /tmp/sat_xml_plugin_`date +%y.%m.%d`&
}
case "$1" in
    stop_lib) stop_lib ;;
    stop_sat) stop_sat ;;
    stop_ser) stop_ser ;;
    start_ser) start_ser ;;
    start_sat) start_sat ;;
    start_lib) start_lib ;;
    stop) stop_lib && stop_sat && stop_ser ;;
    start) start_ser && start_sat && start_lib;;
    restart_sat) stop_sat && stop_ser && start_ser && start_sat ;;
    restart_lib) stop_lib && start_lib ;;
    4foxes) 4foxes ;;
    clean) clean ;;
    purge) clean && purge;;
    main) main ;;
    bridge) bridge;;
    monitor) monitor;;
    *)
        # default: reinstall and restart all
        stop_lib && stop_sat && stop_ser
        clean
        start_ser && start_sat && start_lib
        ;;
esac

echo "Done."