commit 3e475d9f0d2322e6a31dd70f4c1416e79a41aa76
Author: Christoph Lohmann <20h@r-36.net>
Date: Sat, 26 Feb 2011 17:59:27 +0100
Initial commit of rfkilld.
Diffstat:
5 files changed, 155 insertions(+), 0 deletions(-)
diff --git a/LICENSE b/LICENSE
@@ -0,0 +1,21 @@
+MIT/X Consortium License
+
+© 2011 Christoph Lohmann <20h@r-36.net>
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the "Software"),
+to deal in the Software without restriction, including without limitation
+the rights to use, copy, modify, merge, publish, distribute, sublicense,
+and/or sell copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+DEALINGS IN THE SOFTWARE.
diff --git a/Makefile b/Makefile
@@ -0,0 +1,29 @@
+# rfkilld - rfkill daemon
+# See LICENSE file for copyright and license details.
+
+include config.mk
+
+dist:
+ @echo creating dist tarball
+ @mkdir -p rfkilld-${VERSION}
+ @cp -R LICENSE README.md Makefile config.mk \
+ bin etc rfkilld-${VERSION}
+ @tar -cf rfkilld-${VERSION}.tar rfkilld-${VERSION}
+ @gzip rfkilld-${VERSION}.tar
+ @rm -rf rfkilld-${VERSION}
+
+install:
+ @echo installing rfkilld script to ${DESTDIR}${PREFIX}/bin
+ @cp bin/rfkilld ${DESTDIR}${PREFIX}/bin
+ @chmod 755 ${DESTDIR}${PREFIX}/bin/rfkilld
+ @echo installing etc files into ${DESTDIR}/etc/rfkilld
+ @mkdir -p ${DESTDIR}/etc/rfkilld
+ @cp -R etc/rfkilld ${DESTDIR}/etc/rfkilld
+
+uninstall:
+ @echo removing rfkilld script from ${DESTDIR}${PREFIX}/bin
+ @rm -f ${DESTDIR}${PREFIX}/bin/rfkilld
+ @echo removing etc files from ${DESTDIR}/etc/rfkilld
+ @rm -rf ${DESTDIR}/etc/rfkilld
+
+.PHONY: dist install uninstall
diff --git a/README.md b/README.md
diff --git a/bin/rfkilld b/bin/rfkilld
@@ -0,0 +1,96 @@
+#!/bin/sh
+
+usage() {
+ echo "usage: `basename $1` [-hbl] [-p pidfile] [-e etcdir] [-b]"
+}
+
+UDEVMONITORCMD="/usr/bin/nlmon -p -k"
+ETCDIR="/etc/rfkilld"
+PIDFILE="/var/run/rfkilld.pid"
+dobackground=0
+dodebug=0
+dolog=0
+
+while getopts "ldp:e:" opt;
+do
+ case $opt in
+ d)
+ dodebug=1
+ ;;
+ p)
+ PIDFILE="$OPTARG"
+ ;;
+ e)
+ ETCDIR="$OPTARG"
+ ;;
+ l)
+ dolog=1
+ ;;
+ *)
+ usage $0
+ exit 1
+ ;;
+ esac
+done
+shift $(($OPTIND - 1))
+
+debugcmd=""
+if [ $dodebug -eq 1 ];
+then
+ debugcmd="-d"
+ set -x
+fi
+
+echo $$ > $PIDFILE 2>&1 >/dev/null
+trap "[ -e $PIDFILE ] && rm $PIDFILE; exit 0;" 2 3 6 9 15
+
+name=
+type=
+state=
+
+$UDEVMONITORCMD | \
+while read status
+do
+ [[ "$status" =~ ^RFKILL_NAME=(.*)$ ]] \
+ && name="${BASH_REMATCH[1]}"
+ [[ "$status" =~ ^RFKILL_TYPE=(.*)$ ]] \
+ && type="${BASH_REMATCH[1]}"
+ [[ "$status" =~ ^RFKILL_STATE=(.*)$ ]] \
+ && state="${BASH_REMATCH[1]}"
+
+ if [ "$status" == "" ];
+ then
+ if [ "$name" == "" ] || [ "$type" == "" ] \
+ || [ "$state" == "" ];
+ then
+ continue
+ fi
+
+ [ $dodebug -eq 1 ] \
+ && logger -t rfkilld "req $name $type $state"
+
+ if [ -x $ETCDIR/$name.sh ];
+ then
+ $ETCDIR/$name.sh $state 2>&1 >/dev/null &
+
+ [ $dolog -eq 1 ] \
+ && logger -t rfkilld "ran $name.sh $state"
+ fi
+
+ if [ -x $ETCDIR/$type.sh ];
+ then
+ $ETCDIR/$type.sh $state $name 2>&1 >/dev/null &
+
+ [ $dolog -eq 1 ] \
+ && logger -t rfkilld \
+ "ran $type.sh $state $name"
+ fi
+
+ name=
+ type=
+ state=
+ fi
+done
+
+exit 0
+
diff --git a/config.mk b/config.mk
@@ -0,0 +1,9 @@
+# rfkilld version
+VERSION = 0.2
+
+# Customize below to fit your system
+
+# paths
+PREFIX = /usr
+MANPREFIX = ${PREFIX}/share/man
+