From: tinloaf Date: Sun, 30 Nov 2008 20:59:34 +0000 (+0000) Subject: Add:Core:Adding a script to make shure navit is only started once on Linux X-Git-Tag: navit-0.5.0.5194svn~3392 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c2cf6c5b9616d95a36c0145ac324724e234a051d;p=profile%2Fivi%2Fnavit.git Add:Core:Adding a script to make shure navit is only started once on Linux git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk@1766 ffa7fe5e-494d-0410-b361-a75ebd5db220 --- diff --git a/navit/navit/startonce.sh b/navit/navit/startonce.sh new file mode 100755 index 0000000..4053a11 --- /dev/null +++ b/navit/navit/startonce.sh @@ -0,0 +1,81 @@ +#!/bin/sh + +# This script is part of navit, a navigation system. +# It can be used to make shure that navit is only started +# once. If navit is already running it will be brought to +# the front. + +# Set this to a place where a pidfile should be stored. +# Make shure you have write access... +PIDFILE="/var/run/navit/navit.pid" + +# Set this to navit's executable. +NAVIT="./navit" + +# Optional: Set this to an alternative configuration file +#CONFIG="./navit.xml" + +############################################################ +### You should not need to edit anything below this line ### +############################################################ + +function check_wmctrl() +{ + which wmctrl > /dev/null + + if [ $? -ne 0 ] ; then + echo "I need the 'wmctrl' program. Exit." + exit 1 + fi +} + +function start_navit() +{ + if [ "x" != "x$CONFIG" ] ; then + $NAVIT -c $CONFIG & + else + $NAVIT & + fi + + pid=$! + + echo -n "$pid" > $PIDFILE + + if [ $? -eq 0 ] ; then + echo "Started navit with PID $pid." + else + kill $pid + echo "Could not create pidfile!" + exit 1 + fi + + # Waiting for navit to close... + wait $pid + + rm $PIDFILE +} + +function check_navit() +{ + if [ -f $PIDFILE ] ; then + pid=`cat $PIDFILE` + kill -0 $pid 2>/dev/null + if [ $? -eq 0 ] ; then + echo "Bringing Navit to front" + + winid=`wmctrl -l -p | grep -e "^[^:blank:]*[:blank:]*[^:blank:]*[:blank:]*$pid[:blank:]*" | sed 's/ .*//'` + wmctrl -i -R $winid + + exit 0 + fi + fi +} + + +### Start of the main script ### + +check_wmctrl + +check_navit + +start_navit \ No newline at end of file