#!/bin/sh # Install/uninstall, start/stop/restart, testrun frewe-client if [ -x /usr/bin/dirname ] && [ -x /usr/bin/readlink ] then if [ -L $0 ] then DIR=$(dirname $(readlink -f $0)) ; else DIR=$(dirname $0) ; fi else DIR="/var/media/ftp/frewe" fi if [ "$DIR" == "." ] then DIR="`pwd`" fi PRONAME="frewe-client" BINFILE="$DIR/$PRONAME" CFGFILE="$DIR/$PRONAME.cfg" LOGFILE="/dev/null" # Uncomment to enable local data logging #LOGFILE="$DIR/$PRONAME.csv" if [ ! -f "$BINFILE" ] then echo "File $BINFILE not found. " echo "Please upload this file. Aborted" exit 1 fi if [ ! -f "$CFGFILE" ] then echo "File $CFGFILE not found." echo "Please upload this file. Aborted" exit 1 fi chmod 755 $BINFILE # Print version info of currently installed frewe-client $BINFILE -H case "$1" in install) if [ -e /var/flash/debug.cfg ] && [ "`cat /var/flash/debug.cfg | grep $PRONAME`" != "" ] then echo "$PRONAME is already installed. Here is the content of debug.cfg:" cat /var/flash/debug.cfg echo "Nothing to install" exit 1 fi echo "(max=12; i=0; while [ \$i -lt \$max ]; do if [ -x "$BINFILE" ]; then $BINFILE -c $CFGFILE >> $LOGFILE & break; fi; let i=\$i+1; echo Waiting for $PRONAME... \$i; sleep 5; done) &" > /var/tmp/debug.cfg if [ -e /var/flash/debug.cfg ] then cat /var/flash/debug.cfg >> /var/tmp/debug.cfg fi cat /var/tmp/debug.cfg > /var/flash/debug.cfg echo "$PRONAME installed. Here is the content of the new debug.cfg:" cat /var/flash/debug.cfg ;; uninstall) if [ -e /var/flash/debug.cfg ] then cat /var/flash/debug.cfg | grep -v $PRONAME > /var/tmp/debug.cfg cat /var/tmp/debug.cfg > /var/flash/debug.cfg echo "$PRONAME uninstalled. Here is the content of the new debug.cfg:" cat /var/flash/debug.cfg else echo "debug.cfg not found, nothing was installed..." fi ;; start) if [ "`pidof $PRONAME`" != "" ] then echo "$PRONAME is already running with PID `pidof $PRONAME`" exit 1 fi $BINFILE -c $CFGFILE >> $LOGFILE & echo "$PRONAME started with PID `pidof $PRONAME`" ;; stop) if [ "`pidof $PRONAME`" == "" ] then echo "$PRONAME is not running. Nothing to stop" exit 1 fi kill `pidof $PRONAME` echo "$PRONAME stopped" ;; restart) if [ "`pidof $PRONAME`" == "" ] then echo "$PRONAME is not running. Nothing to stop" else kill `pidof $PRONAME` echo "$PRONAME stopped" fi if [ "`pidof $PRONAME`" != "" ] then echo "$PRONAME is already running with PID `pidof $PRONAME`" exit 1 fi $BINFILE -c $CFGFILE >> $LOGFILE & echo "$PRONAME started with PID `pidof $PRONAME`" ;; stat) if [ "`cat /var/flash/debug.cfg | grep $PRONAME`" != "" ] then echo "$PRONAME is installed. Here is content of debug.cfg:" cat /var/flash/debug.cfg else echo "$PRONAME is not installed" fi echo if [ "`pidof $PRONAME`" != "" ] then echo "$PRONAME is running with PID `pidof $PRONAME`" ps | grep "`pidof $PRONAME`" else echo "$PRONAME is not running" fi ;; testrun) $BINFILE -v ;; testruncfg) $BINFILE -v -c $CFGFILE -r 0 ;; *) echo "Usage: $0 {install|uninstall|start|stop|restart|stat|testrun|testruncfg}" exit 1 ;; esac exit 0