Add:Core:Adding a script to make shure navit is only started once on Linux
authortinloaf <tinloaf@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Sun, 30 Nov 2008 20:59:34 +0000 (20:59 +0000)
committertinloaf <tinloaf@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Sun, 30 Nov 2008 20:59:34 +0000 (20:59 +0000)
git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk@1766 ffa7fe5e-494d-0410-b361-a75ebd5db220

navit/navit/startonce.sh [new file with mode: 0755]

diff --git a/navit/navit/startonce.sh b/navit/navit/startonce.sh
new file mode 100755 (executable)
index 0000000..4053a11
--- /dev/null
@@ -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