From 0cc1080dee0c081423deffca0884193011ea399b Mon Sep 17 00:00:00 2001
From: James Meyer <james.meyer@operamail.com>
Date: Fri, 5 Dec 2008 13:17:48 -0600
Subject: add better error checking for the init scripts ncidd/xvfb/evrouter

---
 abs/core-testing/LinHES-config/PKGBUILD                    |   2 +-
 abs/core-testing/LinHES-config/systemconfig.sh             |   8 ++++++++
 abs/core-testing/runit-scripts/PKGBUILD                    |   2 +-
 .../runit-scripts/runitscripts/services/evrouter/finish    |  10 ++++++++--
 .../runit-scripts/runitscripts/services/evrouter/run       |  12 ++++++++++--
 .../runit-scripts/runitscripts/services/ncid/finish        |   9 +++++++++
 .../runit-scripts/runitscripts/services/ncid/run           |  11 +++++++++--
 .../runit-scripts/runitscripts/services/ncidd/finish       |   9 +++++++++
 .../runit-scripts/runitscripts/services/ncidd/run          |   6 +++++-
 abs/mv-core/MythVantage-config/systemconfig.sh             |   7 ++++++-
 .../runit-scripts-mv/runitscripts/services/evrouter/finish |  10 ++++++++--
 .../runit-scripts-mv/runitscripts/services/evrouter/run    |  12 ++++++++++--
 .../runitscripts/services/evrouter/supervise/lock          |   0
 .../runitscripts/services/evrouter/supervise/pid           |   0
 .../runitscripts/services/evrouter/supervise/stat          |   1 -
 .../runitscripts/services/evrouter/supervise/status        | Bin 20 -> 0 bytes
 .../runit-scripts-mv/runitscripts/services/ncid/finish     |   9 +++++++++
 .../runit-scripts-mv/runitscripts/services/ncid/run        |  11 +++++++++--
 .../runit-scripts-mv/runitscripts/services/ncidd/finish    |   9 +++++++++
 .../runit-scripts-mv/runitscripts/services/ncidd/run       |   6 +++++-
 20 files changed, 116 insertions(+), 18 deletions(-)
 create mode 100644 abs/core-testing/runit-scripts/runitscripts/services/ncid/finish
 create mode 100644 abs/core-testing/runit-scripts/runitscripts/services/ncidd/finish
 delete mode 100644 abs/mv-core/runit-scripts-mv/runitscripts/services/evrouter/supervise/lock
 delete mode 100644 abs/mv-core/runit-scripts-mv/runitscripts/services/evrouter/supervise/pid
 delete mode 100644 abs/mv-core/runit-scripts-mv/runitscripts/services/evrouter/supervise/stat
 delete mode 100644 abs/mv-core/runit-scripts-mv/runitscripts/services/evrouter/supervise/status
 create mode 100644 abs/mv-core/runit-scripts-mv/runitscripts/services/ncid/finish
 create mode 100644 abs/mv-core/runit-scripts-mv/runitscripts/services/ncidd/finish

diff --git a/abs/core-testing/LinHES-config/PKGBUILD b/abs/core-testing/LinHES-config/PKGBUILD
index 075c061..144d96e 100755
--- a/abs/core-testing/LinHES-config/PKGBUILD
+++ b/abs/core-testing/LinHES-config/PKGBUILD
@@ -1,6 +1,6 @@
 pkgname=LinHES-config
 pkgver=1.0
-pkgrel=63
+pkgrel=65
 conflicts=(MythVantage-config MythVantage-config-dev LinHES-config-dev )
 pkgdesc="Install and configure your system"
 depends=(bc libstatgrab  mysql-python expect curl dnsutils parted sg3_utils nmbscan )
diff --git a/abs/core-testing/LinHES-config/systemconfig.sh b/abs/core-testing/LinHES-config/systemconfig.sh
index 6c72b92..90405a7 100755
--- a/abs/core-testing/LinHES-config/systemconfig.sh
+++ b/abs/core-testing/LinHES-config/systemconfig.sh
@@ -658,6 +658,14 @@ then
            ser_remove="ncid $ser_remove"
  fi
 
+
+if [ x$UseEvrouter = x1 ]
+then
+           ser_install="evrouter Xvfb $ser_install"
+  else
+           ser_remove="evrouter $ser_remove"
+fi
+
 #Setting the default, just to avoid the or statement..
 #if [ x$UseHobbit = x ]
 #then
diff --git a/abs/core-testing/runit-scripts/PKGBUILD b/abs/core-testing/runit-scripts/PKGBUILD
index 3792572..6df1bae 100755
--- a/abs/core-testing/runit-scripts/PKGBUILD
+++ b/abs/core-testing/runit-scripts/PKGBUILD
@@ -1,6 +1,6 @@
 pkgname=runit-scripts
 pkgver=1.8.0
-pkgrel=15
+pkgrel=18
 pkgdesc="collection of startup scripts for runit"
 url="http://smarden.org/runit/"
 license="BSD"
diff --git a/abs/core-testing/runit-scripts/runitscripts/services/evrouter/finish b/abs/core-testing/runit-scripts/runitscripts/services/evrouter/finish
index 0dd33de..5ebda4c 100755
--- a/abs/core-testing/runit-scripts/runitscripts/services/evrouter/finish
+++ b/abs/core-testing/runit-scripts/runitscripts/services/evrouter/finish
@@ -1,4 +1,10 @@
 #!/bin/bash
 . /etc/profile
-DISPLAY=localhost:50 evrouter -q 
-rm -rf /tmp/.evrouter*
+which evrouter >/dev/null 2>/dev/null
+if [ $? = 0 ]
+then
+	DISPLAY=localhost:50 evrouter -q 
+	rm -rf /tmp/.evrouter*
+else
+	sv down evrouter
+fi
\ No newline at end of file
diff --git a/abs/core-testing/runit-scripts/runitscripts/services/evrouter/run b/abs/core-testing/runit-scripts/runitscripts/services/evrouter/run
index 1d7389a..5697f6f 100755
--- a/abs/core-testing/runit-scripts/runitscripts/services/evrouter/run
+++ b/abs/core-testing/runit-scripts/runitscripts/services/evrouter/run
@@ -1,5 +1,13 @@
 #!/bin/bash
 . /etc/profile
-sv start Xvfb
-su mythtv -c "DISPLAY=localhost:50 evrouter -c /etc/evrouter.cfg -f /dev/input/event*"
+which evrouter >/dev/null 2>/dev/null
+if [ $? = 0 ]
+then
+	ps -ef |grep -v grep|grep -q "Xvfb :50"
+	if [ ! $?  = 0 ]
+	then
+		sv start Xvfb
+	fi
+	su mythtv -c "DISPLAY=localhost:50 evrouter -c /etc/evrouter.cfg -f /dev/input/event*"
+fi
 
diff --git a/abs/core-testing/runit-scripts/runitscripts/services/ncid/finish b/abs/core-testing/runit-scripts/runitscripts/services/ncid/finish
new file mode 100644
index 0000000..953a4a1
--- /dev/null
+++ b/abs/core-testing/runit-scripts/runitscripts/services/ncid/finish
@@ -0,0 +1,9 @@
+#!/bin/bash
+exec 2>&1
+which ncid 2>/dev/null >/dev/null
+if [ ! $?  = 0 ]
+then
+	sv down ncid
+fi
+
+
diff --git a/abs/core-testing/runit-scripts/runitscripts/services/ncid/run b/abs/core-testing/runit-scripts/runitscripts/services/ncid/run
index 8a90707..7dbc8ba 100755
--- a/abs/core-testing/runit-scripts/runitscripts/services/ncid/run
+++ b/abs/core-testing/runit-scripts/runitscripts/services/ncid/run
@@ -1,5 +1,12 @@
 #!/bin/sh
 exec 2>&1
-sv start ncidd
-exec /usr/bin/ncid --no-gui --all  --call-prog --program /usr/bin/ncid.py 127.0.0.1 3333
+which ncid 2>/dev/null >/dev/null
+if [ $? = 0 ]
+then
+	if [ -f /var/service/ncidd/run ]
+	then
+		sv start ncidd
+	fi
+	exec /usr/bin/ncid --no-gui --all  --call-prog --program /usr/bin/ncid.py 127.0.0.1 3333
+fi
 
diff --git a/abs/core-testing/runit-scripts/runitscripts/services/ncidd/finish b/abs/core-testing/runit-scripts/runitscripts/services/ncidd/finish
new file mode 100644
index 0000000..ab39d39
--- /dev/null
+++ b/abs/core-testing/runit-scripts/runitscripts/services/ncidd/finish
@@ -0,0 +1,9 @@
+#!/bin/bash
+exec 2>&1
+which ncidd 2>/dev/null >/dev/null
+if [ ! $?  = 0 ]
+then
+	sv down ncid
+fi
+
+
diff --git a/abs/core-testing/runit-scripts/runitscripts/services/ncidd/run b/abs/core-testing/runit-scripts/runitscripts/services/ncidd/run
index 6b032db..f1c710a 100755
--- a/abs/core-testing/runit-scripts/runitscripts/services/ncidd/run
+++ b/abs/core-testing/runit-scripts/runitscripts/services/ncidd/run
@@ -1,3 +1,7 @@
 #!/bin/sh
 exec 2>&1
-exec /usr/sbin/ncidd -D 2>&1 
+which ncidd > /dev/null 2>/dev/null
+if [ $? = 0 ]
+then
+	exec /usr/sbin/ncidd -D 2>&1 
+fi
diff --git a/abs/mv-core/MythVantage-config/systemconfig.sh b/abs/mv-core/MythVantage-config/systemconfig.sh
index a038286..3fbf9b1 100755
--- a/abs/mv-core/MythVantage-config/systemconfig.sh
+++ b/abs/mv-core/MythVantage-config/systemconfig.sh
@@ -639,7 +639,12 @@ then
            ser_daemon_remove="ncidd ncid $ser_daemon_remove"
            ser_remove="ncid $ser_remove"
  fi
-
+if [ x$UseEvrouter = x1 ]
+then
+           ser_install="evrouter Xvfb $ser_install"
+  else
+           ser_remove="evrouter $ser_remove"
+fi
 #Setting the default, just to avoid the or statement..
 if [ x$UseHobbit = x ]
 then
diff --git a/abs/mv-core/runit-scripts-mv/runitscripts/services/evrouter/finish b/abs/mv-core/runit-scripts-mv/runitscripts/services/evrouter/finish
index 0dd33de..5ebda4c 100755
--- a/abs/mv-core/runit-scripts-mv/runitscripts/services/evrouter/finish
+++ b/abs/mv-core/runit-scripts-mv/runitscripts/services/evrouter/finish
@@ -1,4 +1,10 @@
 #!/bin/bash
 . /etc/profile
-DISPLAY=localhost:50 evrouter -q 
-rm -rf /tmp/.evrouter*
+which evrouter >/dev/null 2>/dev/null
+if [ $? = 0 ]
+then
+	DISPLAY=localhost:50 evrouter -q 
+	rm -rf /tmp/.evrouter*
+else
+	sv down evrouter
+fi
\ No newline at end of file
diff --git a/abs/mv-core/runit-scripts-mv/runitscripts/services/evrouter/run b/abs/mv-core/runit-scripts-mv/runitscripts/services/evrouter/run
index 1d7389a..5697f6f 100755
--- a/abs/mv-core/runit-scripts-mv/runitscripts/services/evrouter/run
+++ b/abs/mv-core/runit-scripts-mv/runitscripts/services/evrouter/run
@@ -1,5 +1,13 @@
 #!/bin/bash
 . /etc/profile
-sv start Xvfb
-su mythtv -c "DISPLAY=localhost:50 evrouter -c /etc/evrouter.cfg -f /dev/input/event*"
+which evrouter >/dev/null 2>/dev/null
+if [ $? = 0 ]
+then
+	ps -ef |grep -v grep|grep -q "Xvfb :50"
+	if [ ! $?  = 0 ]
+	then
+		sv start Xvfb
+	fi
+	su mythtv -c "DISPLAY=localhost:50 evrouter -c /etc/evrouter.cfg -f /dev/input/event*"
+fi
 
diff --git a/abs/mv-core/runit-scripts-mv/runitscripts/services/evrouter/supervise/lock b/abs/mv-core/runit-scripts-mv/runitscripts/services/evrouter/supervise/lock
deleted file mode 100644
index e69de29..0000000
diff --git a/abs/mv-core/runit-scripts-mv/runitscripts/services/evrouter/supervise/pid b/abs/mv-core/runit-scripts-mv/runitscripts/services/evrouter/supervise/pid
deleted file mode 100644
index e69de29..0000000
diff --git a/abs/mv-core/runit-scripts-mv/runitscripts/services/evrouter/supervise/stat b/abs/mv-core/runit-scripts-mv/runitscripts/services/evrouter/supervise/stat
deleted file mode 100644
index eb0e904..0000000
--- a/abs/mv-core/runit-scripts-mv/runitscripts/services/evrouter/supervise/stat
+++ /dev/null
@@ -1 +0,0 @@
-down
diff --git a/abs/mv-core/runit-scripts-mv/runitscripts/services/evrouter/supervise/status b/abs/mv-core/runit-scripts-mv/runitscripts/services/evrouter/supervise/status
deleted file mode 100644
index 742989c..0000000
Binary files a/abs/mv-core/runit-scripts-mv/runitscripts/services/evrouter/supervise/status and /dev/null differ
diff --git a/abs/mv-core/runit-scripts-mv/runitscripts/services/ncid/finish b/abs/mv-core/runit-scripts-mv/runitscripts/services/ncid/finish
new file mode 100644
index 0000000..953a4a1
--- /dev/null
+++ b/abs/mv-core/runit-scripts-mv/runitscripts/services/ncid/finish
@@ -0,0 +1,9 @@
+#!/bin/bash
+exec 2>&1
+which ncid 2>/dev/null >/dev/null
+if [ ! $?  = 0 ]
+then
+	sv down ncid
+fi
+
+
diff --git a/abs/mv-core/runit-scripts-mv/runitscripts/services/ncid/run b/abs/mv-core/runit-scripts-mv/runitscripts/services/ncid/run
index 8a90707..7dbc8ba 100755
--- a/abs/mv-core/runit-scripts-mv/runitscripts/services/ncid/run
+++ b/abs/mv-core/runit-scripts-mv/runitscripts/services/ncid/run
@@ -1,5 +1,12 @@
 #!/bin/sh
 exec 2>&1
-sv start ncidd
-exec /usr/bin/ncid --no-gui --all  --call-prog --program /usr/bin/ncid.py 127.0.0.1 3333
+which ncid 2>/dev/null >/dev/null
+if [ $? = 0 ]
+then
+	if [ -f /var/service/ncidd/run ]
+	then
+		sv start ncidd
+	fi
+	exec /usr/bin/ncid --no-gui --all  --call-prog --program /usr/bin/ncid.py 127.0.0.1 3333
+fi
 
diff --git a/abs/mv-core/runit-scripts-mv/runitscripts/services/ncidd/finish b/abs/mv-core/runit-scripts-mv/runitscripts/services/ncidd/finish
new file mode 100644
index 0000000..ab39d39
--- /dev/null
+++ b/abs/mv-core/runit-scripts-mv/runitscripts/services/ncidd/finish
@@ -0,0 +1,9 @@
+#!/bin/bash
+exec 2>&1
+which ncidd 2>/dev/null >/dev/null
+if [ ! $?  = 0 ]
+then
+	sv down ncid
+fi
+
+
diff --git a/abs/mv-core/runit-scripts-mv/runitscripts/services/ncidd/run b/abs/mv-core/runit-scripts-mv/runitscripts/services/ncidd/run
index 6b032db..f1c710a 100755
--- a/abs/mv-core/runit-scripts-mv/runitscripts/services/ncidd/run
+++ b/abs/mv-core/runit-scripts-mv/runitscripts/services/ncidd/run
@@ -1,3 +1,7 @@
 #!/bin/sh
 exec 2>&1
-exec /usr/sbin/ncidd -D 2>&1 
+which ncidd > /dev/null 2>/dev/null
+if [ $? = 0 ]
+then
+	exec /usr/sbin/ncidd -D 2>&1 
+fi
-- 
cgit v0.12

