summaryrefslogtreecommitdiff
path: root/navit/startonce.sh
diff options
context:
space:
mode:
authortinloaf <tinloaf@ffa7fe5e-494d-0410-b361-a75ebd5db220>2008-11-30 20:59:34 +0000
committertinloaf <tinloaf@ffa7fe5e-494d-0410-b361-a75ebd5db220>2008-11-30 20:59:34 +0000
commitc6e2191c7903924197250e01f5889cf419630a97 (patch)
tree399ab9954dfa0ac2e6d55e4ec213aac355aa863d /navit/startonce.sh
parentb27e18ec035f8b7ef71aad3fb981d8a3b9076119 (diff)
downloadnavit-svn-c6e2191c7903924197250e01f5889cf419630a97.tar.gz
Add:Core:Adding a script to make shure navit is only started once on Linux
git-svn-id: http://svn.code.sf.net/p/navit/code/trunk/navit@1766 ffa7fe5e-494d-0410-b361-a75ebd5db220
Diffstat (limited to 'navit/startonce.sh')
-rwxr-xr-xnavit/startonce.sh81
1 files changed, 81 insertions, 0 deletions
diff --git a/navit/startonce.sh b/navit/startonce.sh
new file mode 100755
index 00000000..4053a11b
--- /dev/null
+++ b/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