From 71fef603911d15fd30b1033e565aecb01c4a1c11 Mon Sep 17 00:00:00 2001
From: Michael Hanson <hansonorders@verison.net>
Date: Thu, 1 Apr 2010 23:28:58 +0000
Subject: bluez: Add runit support. Needs testing. Ref #676

---
 abs/extra-testing/bluez/PKGBUILD        |  26 ++++++--
 abs/extra-testing/bluez/__Changelog     |   7 +++
 abs/extra-testing/bluez/bluez.install   |  15 +++++
 abs/extra-testing/bluez/rc.bluetooth    | 106 --------------------------------
 abs/extra-testing/bluez/run.bluetoothd  |  12 ++++
 abs/extra-testing/bluez/run.dund        |  14 +++++
 abs/extra-testing/bluez/run.hid2hci     |  15 +++++
 abs/extra-testing/bluez/run.hidd        |  14 +++++
 abs/extra-testing/bluez/run.pand        |  14 +++++
 abs/extra-testing/bluez/run.rfcomm      |  17 +++++
 abs/extra-testing/bluez/run.sdpd        |  14 +++++
 abs/extra-testing/bluez/runit.bluetooth |  65 --------------------
 12 files changed, 142 insertions(+), 177 deletions(-)
 create mode 100644 abs/extra-testing/bluez/bluez.install
 delete mode 100644 abs/extra-testing/bluez/rc.bluetooth
 create mode 100644 abs/extra-testing/bluez/run.bluetoothd
 create mode 100644 abs/extra-testing/bluez/run.dund
 create mode 100644 abs/extra-testing/bluez/run.hid2hci
 create mode 100644 abs/extra-testing/bluez/run.hidd
 create mode 100644 abs/extra-testing/bluez/run.pand
 create mode 100644 abs/extra-testing/bluez/run.rfcomm
 create mode 100644 abs/extra-testing/bluez/run.sdpd
 delete mode 100644 abs/extra-testing/bluez/runit.bluetooth

diff --git a/abs/extra-testing/bluez/PKGBUILD b/abs/extra-testing/bluez/PKGBUILD
index 46af613..f39539a 100644
--- a/abs/extra-testing/bluez/PKGBUILD
+++ b/abs/extra-testing/bluez/PKGBUILD
@@ -1,7 +1,7 @@
 # Maintainer: Geoffroy Carrier <geoffroy@archlinux.org>
 pkgname=bluez
 pkgver=4.62
-pkgrel=1
+pkgrel=2
 pkgdesc="Libraries and tools for the Bluetooth protocol stack"
 url="http://www.bluez.org/"
 arch=('i686' 'x86_64')
@@ -12,11 +12,13 @@ optdepends=('gstreamer0.10-base' 'alsa-lib' 'libusb')
 conflicts=('bluez-libs' 'bluez-utils')
 provides=('bluez-libs' 'bluez-utils')
 replaces=('bluez-libs' 'bluez-utils')
+install='bluez.install'
 backup=(etc/bluetooth/{main,rfcomm,audio,network,input}.conf
         etc/conf.d/bluetooth)
 source=("http://www.kernel.org/pub/linux/bluetooth/$pkgname-$pkgver.tar.bz2"
-        'bluetooth.conf.d'
-        'runit.bluetooth')
+        bluetooth.conf.d run.bluetoothd run.sdpd run.hidd run.dund run.pand
+        run.rfcomm run.hid2hci)
+
 build() {
   cd "$srcdir/$pkgname-$pkgver"
   ./configure --prefix=/usr \
@@ -45,9 +47,21 @@ build() {
   install -D -m644 "$srcdir/$pkgname-$pkgver/network/network.conf" "$pkgdir/etc/bluetooth/" || return 1
   install -D -m644 "$srcdir/$pkgname-$pkgver/input/input.conf"     "$pkgdir/etc/bluetooth/" || return 1
   install -D -m644 "$srcdir/$pkgname-$pkgver/audio/audio.conf"     "$pkgdir/etc/bluetooth/" || return 1
-  install -D -m755 "$srcdir/runit.bluetooth"                       "$pkgdir/etc/sv/bluetooth/run" || return 1
-  install -D -m644 "$srcdir/bluetooth.conf.d"                      "$pkgdir/etc/conf.d/bluetooth" || return 1
+  install -D -m644 "$srcdir/bluetooth.conf.d"                     "$pkgdir/etc/conf.d/bluetooth" || return 1
+  install -D -m755 "$srcdir/run.bluetoothd"                       "$pkgdir/etc/sv/bluetoothd/run" || return 1
+  install -D -m755 "$srcdir/run.sdpd"                             "$pkgdir/etc/sv/sdpd/run" || return 1
+  install -D -m755 "$srcdir/run.hidd"                             "$pkgdir/etc/sv/hidd/run" || return 1
+  install -D -m755 "$srcdir/run.dund"                             "$pkgdir/etc/sv/dund/run" || return 1
+  install -D -m755 "$srcdir/run.pand"                             "$pkgdir/etc/sv/pand/run" || return 1
+  install -D -m755 "$srcdir/run.rfcomm"                           "$pkgdir/etc/sv/rfcomm/run" || return 1
+  install -D -m755 "$srcdir/run.hid2hci"                          "$pkgdir/etc/sv/hid2hci/run" || return 1
 }
 md5sums=('3c2187a97f5b43ae84b4bbd4b34671e0'
          'd12be5b494525bb1ba6eac5c3983dd3e'
-         'af1037c8e96dda60a1fea29140afb8f4')
+         '1c88fcd455920ad8ee0c7cae3fe15771'
+         'fc8cdfd1fb0044a674b79c41d5d88388'
+         '2483128d1cb93aeaf15d66058c052dc2'
+         '95bfe0ff91559d719e5feecb0388b4e1'
+         'b130f90a3cab7dd8a40c558d95c540a2'
+         'a416cdf7cc7c954f6b09d6c2a1d1c0d3'
+         'dd046ee5a232ba7cdbe8006d90b479e5')
diff --git a/abs/extra-testing/bluez/__Changelog b/abs/extra-testing/bluez/__Changelog
index af8c597..124d0eb 100644
--- a/abs/extra-testing/bluez/__Changelog
+++ b/abs/extra-testing/bluez/__Changelog
@@ -2,3 +2,10 @@
 I really have no idea how this bluetooth stuff works.  If anyone wants to
 take a stab at getting this working properly with runit, feel free.  I
 only need this package to get mythpywii working.
+
+2010-04-01:
+Make this package work with runit.  All daemons were seperated into their
+own run scripts.  Of particular interest is rfcomm and hid2hci utilities.
+They are not daemons and I added "/sbin/sv <executable> down ." in their
+respective run files.  All based on this thread:
+http://article.gmane.org/gmane.comp.sysutils.supervision.general/1585/
diff --git a/abs/extra-testing/bluez/bluez.install b/abs/extra-testing/bluez/bluez.install
new file mode 100644
index 0000000..30bd262
--- /dev/null
+++ b/abs/extra-testing/bluez/bluez.install
@@ -0,0 +1,15 @@
+post_install() {
+    add_service.sh bluetoothd
+    echo ">>> Only the bluetoothd daemon is started by default."
+    echo ">>> You can optionally add the following as required:"
+    echo ">>> hidd dund pand sdpd rfcomm hid2hci"
+    echo ">>> $ sudo add_service.sh <service_name>"
+}
+
+pre_remove() {
+    for d in { bluetoothd,hidd,dund,pand,sdpd,rfcomm,hid2hci } ; do
+      if [ -d /var/service/${d} ] ; then
+        remove_servcie.sh $d
+      fi
+    done
+}
diff --git a/abs/extra-testing/bluez/rc.bluetooth b/abs/extra-testing/bluez/rc.bluetooth
deleted file mode 100644
index 38b6216..0000000
--- a/abs/extra-testing/bluez/rc.bluetooth
+++ /dev/null
@@ -1,106 +0,0 @@
-#!/bin/sh
-#
-# Start/stop the Bluetooth daemons
-#
-
-. /etc/rc.conf
-. /etc/rc.d/functions
-
-DAEMON_NAME="bluetoothd"
-HID2HCI_NAME="hid2hci"
-HIDD_NAME="hidd"
-RFCOMM_NAME="rfcomm"
-PAND_NAME="pand"
-DUND_NAME="dund"
-
-DAEMON_EXEC="/usr/sbin/bluetoothd"
-HID2HCI_EXEC="/usr/sbin/hid2hci"
-HIDD_EXEC="/usr/bin/hidd"
-RFCOMM_EXEC="/usr/bin/rfcomm"
-PAND_EXEC="/usr/bin/pand"
-DUND_EXEC="/usr/bin/dund"
-
-DAEMON_ENABLE="true"
-HID2HCI_ENABLE="false"
-HIDD_ENABLE="false"
-RFCOMM_ENABLE="false"
-DUND_ENABLE="false"
-PAND_ENABLE="false"
-
-RFCOMM_CONFIG="/etc/bluetooth/rfcomm.conf"
-
-HIDD_OPTIONS=""
-DUND_OPTIONS=""
-PAND_OPTIONS=""
-
-[ -f /etc/conf.d/bluetooth ] && . /etc/conf.d/bluetooth
-
-case "$1" in
-  start)
-    stat_busy "Starting bluetooth subsystem:"
-    if [ "$DAEMON_ENABLE" = "true" -a -x "$DAEMON_EXEC" ] ; then
-      stat_append " $DAEMON_NAME"
-      $DAEMON_EXEC
-    fi
-    if [ "$HID2HCI_ENABLE" = "true" -a -x "$HID2HCI_EXEC" ] ; then
-      stat_append " $HID2HCI_NAME"
-      $HID2HCI_EXEC --tohci > /dev/null 2>&1 || true
-    fi
-    if [ "$SDPD_ENABLE" = "true" -a -x "$SDPD_EXEC" ] ; then
-      stat_append " $SDPD_NAME"
-      $SDPD_EXEC
-    fi
-    if [ "$HIDD_ENABLE" = "true" -a -x "$HIDD_EXEC" ]; then
-      stat_append " $HIDD_NAME"
-      $HIDD_EXEC $HIDD_OPTIONS --server
-    fi
-    if [ "$RFCOMM_ENABLE" = "true" -a -x "$RFCOMM_EXEC" -a -f "$RFCOMM_CONFIG" ]; then
-      stat_append " $RFCOMM_NAME"
-      $RFCOMM_EXEC -f $RFCOMM_CONFIG bind all
-    fi
-    if [ "$DUND_ENABLE" = "true" -a -x "$DUND_EXEC" -a -n "$DUND_OPTIONS" ]; then
-      stat_append " $DUND_NAME"
-      $DUND_EXEC $DUND_OPTIONS
-    fi
-    if [ "$PAND_ENABLE" = "true" -a -x "$PAND_EXEC" -a -n "$PAND_OPTIONS" ]; then
-      stat_append " $PAND_NAME"
-      $PAND_EXEC $PAND_OPTIONS
-    fi
-    add_daemon bluetooth
-    stat_done
-    ;;
-  stop)
-    stat_busy "Stopping bluetooth subsystem:"
-
-    stat_append " $PAND_NAME"
-    killall $PAND_NAME >/dev/null 2>&1
-
-    stat_append " $DUND_NAME"
-    killall $DUND_NAME >/dev/null 2>&1
-
-    if [ -x "$RFCOMM_EXEC" ]; then
-      stat_append " $RFCOMM_NAME"
-      $RFCOMM_EXEC release all >/dev/null 2>&1
-    fi
-
-    stat_append " $HIDD_NAME"
-    killall $HIDD_NAME >/dev/null 2>&1
-
-    stat_append " $SDPD_NAME"
-    killall $SDPD_NAME >/dev/null 2>&1
-
-    stat_append " $DAEMON_NAME"
-    killall $DAEMON_NAME >/dev/null 2>&1
-
-    rm_daemon bluetooth
-    stat_done
-    ;;
-  restart)
-    $0 stop
-    sleep 1
-    $0 start
-    ;;
-  *)
-    echo "usage: $0 {start|stop|restart}"  
-esac
-exit 0
diff --git a/abs/extra-testing/bluez/run.bluetoothd b/abs/extra-testing/bluez/run.bluetoothd
new file mode 100644
index 0000000..7a92437
--- /dev/null
+++ b/abs/extra-testing/bluez/run.bluetoothd
@@ -0,0 +1,12 @@
+#!/bin/sh
+#
+# Start/stop the Bluetooth daemons
+#
+
+. /etc/rc.conf
+. /etc/rc.d/functions
+
+[ -f /etc/conf.d/bluetooth ] && . /etc/conf.d/bluetooth
+
+    stat_runit "Starting bluetooth subsystem:"
+      exec /usr/sbin/bluetoothd -n
diff --git a/abs/extra-testing/bluez/run.dund b/abs/extra-testing/bluez/run.dund
new file mode 100644
index 0000000..2991813
--- /dev/null
+++ b/abs/extra-testing/bluez/run.dund
@@ -0,0 +1,14 @@
+#!/bin/sh
+#
+# Start/stop the Bluetooth daemons
+#
+
+. /etc/rc.conf
+. /etc/rc.d/functions
+
+[ -f /etc/conf.d/bluetooth ] && . /etc/conf.d/bluetooth
+
+svwaitup 3 /var/service/bluetoothd || exit 1
+
+    stat_runit "Starting BlueZ Bluetooth dial-up networking daemon"
+      exec /usr/bin/dund -n
diff --git a/abs/extra-testing/bluez/run.hid2hci b/abs/extra-testing/bluez/run.hid2hci
new file mode 100644
index 0000000..6ef1f47
--- /dev/null
+++ b/abs/extra-testing/bluez/run.hid2hci
@@ -0,0 +1,15 @@
+#!/bin/sh
+#
+# Start/stop the Bluetooth daemons
+#
+
+. /etc/rc.conf
+. /etc/rc.d/functions
+
+[ -f /etc/conf.d/bluetooth ] && . /etc/conf.d/bluetooth
+
+svwaitup 3 /var/service/bluetoothd || exit 1
+
+    stat_runit "Starting Bluetooth HID to HCI mode switching utility"
+      /usr/bin/hid2hci --tohci > /dev/null 2>&1 || true
+      /sbin/sv down .
diff --git a/abs/extra-testing/bluez/run.hidd b/abs/extra-testing/bluez/run.hidd
new file mode 100644
index 0000000..0887333
--- /dev/null
+++ b/abs/extra-testing/bluez/run.hidd
@@ -0,0 +1,14 @@
+#!/bin/sh
+#
+# Start/stop the Bluetooth daemons
+#
+
+. /etc/rc.conf
+. /etc/rc.d/functions
+
+[ -f /etc/conf.d/bluetooth ] && . /etc/conf.d/bluetooth
+
+svwaitup 3 /var/service/bluetoothd || exit 1
+
+    stat_runit "Starting Bluetooth HID daemon:"
+      exec /usr/bin/hidd -n --server
diff --git a/abs/extra-testing/bluez/run.pand b/abs/extra-testing/bluez/run.pand
new file mode 100644
index 0000000..937419f
--- /dev/null
+++ b/abs/extra-testing/bluez/run.pand
@@ -0,0 +1,14 @@
+#!/bin/sh
+#
+# Start/stop the Bluetooth daemons
+#
+
+. /etc/rc.conf
+. /etc/rc.d/functions
+
+[ -f /etc/conf.d/bluetooth ] && . /etc/conf.d/bluetooth
+
+svwaitup 3 /var/service/bluetoohd || exit 1
+
+    stat_runit "Starting BlueZ Bluetooth PAN daemon"
+      exec /usr/bin/pand -n
diff --git a/abs/extra-testing/bluez/run.rfcomm b/abs/extra-testing/bluez/run.rfcomm
new file mode 100644
index 0000000..72b3e0f
--- /dev/null
+++ b/abs/extra-testing/bluez/run.rfcomm
@@ -0,0 +1,17 @@
+#!/bin/sh
+#
+# Start/stop the Bluetooth daemons
+#
+
+. /etc/rc.conf
+. /etc/rc.d/functions
+
+[ -f /etc/conf.d/bluetooth ] && . /etc/conf.d/bluetooth
+
+RFCOMM_CONFIG="/etc/bluetooth/rfcomm.conf"
+
+svwaitup 3 /var/service/bluetoothd || exit 1
+
+    stat_runit "Starting RFCOMM for the bluetooth subsystem"
+      /usr/bin/rfcomm  -f $RFCOMM_CONFIG bind all
+      /sbin/sv down .
diff --git a/abs/extra-testing/bluez/run.sdpd b/abs/extra-testing/bluez/run.sdpd
new file mode 100644
index 0000000..aff51ac
--- /dev/null
+++ b/abs/extra-testing/bluez/run.sdpd
@@ -0,0 +1,14 @@
+#!/bin/sh
+#
+# Start/stop the Bluetooth daemons
+#
+
+. /etc/rc.conf
+. /etc/rc.d/functions
+
+[ -f /etc/conf.d/bluetooth ] && . /etc/conf.d/bluetooth
+
+svwaitup 3 /var/service/bluetoothd || exit 1
+
+    stat_runit "Starting bluetooth SDP daemon"
+      exec /usr/bin/sdpd -n
diff --git a/abs/extra-testing/bluez/runit.bluetooth b/abs/extra-testing/bluez/runit.bluetooth
deleted file mode 100644
index 4b443db..0000000
--- a/abs/extra-testing/bluez/runit.bluetooth
+++ /dev/null
@@ -1,65 +0,0 @@
-#!/bin/sh
-#
-# Start/stop the Bluetooth daemons
-#
-
-. /etc/rc.conf
-. /etc/rc.d/functions
-
-DAEMON_NAME="bluetoothd"
-HID2HCI_NAME="hid2hci"
-HIDD_NAME="hidd"
-RFCOMM_NAME="rfcomm"
-PAND_NAME="pand"
-DUND_NAME="dund"
-
-DAEMON_EXEC="/usr/sbin/bluetoothd -n"
-HID2HCI_EXEC="/usr/sbin/hid2hci"
-HIDD_EXEC="/usr/bin/hidd"
-RFCOMM_EXEC="/usr/bin/rfcomm"
-PAND_EXEC="/usr/bin/pand"
-DUND_EXEC="/usr/bin/dund"
-
-DAEMON_ENABLE="true"
-HID2HCI_ENABLE="false"
-HIDD_ENABLE="false"
-RFCOMM_ENABLE="false"
-DUND_ENABLE="false"
-PAND_ENABLE="false"
-
-RFCOMM_CONFIG="/etc/bluetooth/rfcomm.conf"
-
-HIDD_OPTIONS="-n"
-DUND_OPTIONS="-n"
-PAND_OPTIONS="-n"
-
-[ -f /etc/conf.d/bluetooth ] && . /etc/conf.d/bluetooth
-
-    stat_runit "Starting bluetooth subsystem:"
-    if [ "$DAEMON_ENABLE" = "true" -a -x "$DAEMON_EXEC" ] ; then
-      exec $DAEMON_EXEC
-    fi
-#    if [ "$HID2HCI_ENABLE" = "true" -a -x "$HID2HCI_EXEC" ] ; then
-#      stat_append " $HID2HCI_NAME"
-#      $HID2HCI_EXEC --tohci > /dev/null 2>&1 || true
-#    fi
-#    if [ "$SDPD_ENABLE" = "true" -a -x "$SDPD_EXEC" ] ; then
-#      stat_append " $SDPD_NAME"
-#      $SDPD_EXEC
-#    fi
-#    if [ "$HIDD_ENABLE" = "true" -a -x "$HIDD_EXEC" ]; then
-#      stat_append " $HIDD_NAME"
-#      $HIDD_EXEC $HIDD_OPTIONS --server
-#    fi
-#    if [ "$RFCOMM_ENABLE" = "true" -a -x "$RFCOMM_EXEC" -a -f "$RFCOMM_CONFIG" ]; then
-#      stat_append " $RFCOMM_NAME"
-#      $RFCOMM_EXEC -f $RFCOMM_CONFIG bind all
-#    fi
-#    if [ "$DUND_ENABLE" = "true" -a -x "$DUND_EXEC" -a -n "$DUND_OPTIONS" ]; then
-#      stat_append " $DUND_NAME"
-#      $DUND_EXEC $DUND_OPTIONS
-#    fi
-#    if [ "$PAND_ENABLE" = "true" -a -x "$PAND_EXEC" -a -n "$PAND_OPTIONS" ]; then
-#      stat_append " $PAND_NAME"
-#      $PAND_EXEC $PAND_OPTIONS
-#    fi
-- 
cgit v0.12

