summaryrefslogtreecommitdiff
path: root/extra/ifplugd
diff options
context:
space:
mode:
authorroot <root@rshg054.dnsready.net>2012-04-30 00:01:38 +0000
committerroot <root@rshg054.dnsready.net>2012-04-30 00:01:38 +0000
commitb7cd4b184f75d3d2b54b356e08f296df3a9afb38 (patch)
treedc5e84c1f7271cf0c8ec0221b5a22e48a884081a /extra/ifplugd
parent4412991f6b4fd655fc1f51f8d79a0be0c10158b7 (diff)
Mon Apr 30 00:01:38 UTC 2012
Diffstat (limited to 'extra/ifplugd')
-rw-r--r--extra/ifplugd/PKGBUILD17
-rw-r--r--extra/ifplugd/ifplugd107
-rw-r--r--extra/ifplugd/ifplugd.action17
3 files changed, 84 insertions, 57 deletions
diff --git a/extra/ifplugd/PKGBUILD b/extra/ifplugd/PKGBUILD
index cc6cd83c1..cde1a503b 100644
--- a/extra/ifplugd/PKGBUILD
+++ b/extra/ifplugd/PKGBUILD
@@ -1,23 +1,26 @@
-# $Id: PKGBUILD 150402 2012-02-17 12:01:52Z allan $
+# $Id: PKGBUILD 157472 2012-04-28 18:54:17Z dreisner $
# Contributor: Manolis Tzanidakis
# Contributor: kevin <kevin@archlinux.org>
# Maintainer:
pkgname=ifplugd
pkgver=0.28
-pkgrel=8
+pkgrel=10
pkgdesc="A daemon which brings up/down network interfaces upon cable insertion/removal."
arch=('i686' 'x86_64')
url="http://0pointer.de/lennart/projects/ifplugd"
license=('GPL2')
-depends=('libdaemon' 'bash')
+depends=('libdaemon' 'bash' 'net-tools')
backup=('etc/ifplugd/ifplugd.conf' 'etc/ifplugd/ifplugd.action')
options=('!makeflags')
source=($url/${pkgname}-${pkgver}.tar.gz 'ifplugd' 'ifplugd.action' 'ifplugd-0.28-interface.patch' 'ifdown.01-route.sh' 'ifup.01-route.sh' 'ifup.02-ntpdate.sh')
-md5sums=('df6f4bab52f46ffd6eb1f5912d4ccee3' '70d66121ae5163348855236951e069a2'\
- 'e91a3d77d707ae79fbc10146848032dc' '54eb22844b5aeed161c0b80aa9008570'\
- 'd6ce6c7bd481a0b3944c944c5b277c0b' 'c35f0a637911b747f8dc3bd3c6156a1b'\
- 'f8690ee18a5ca72555585ee96826c2cf')
+md5sums=('df6f4bab52f46ffd6eb1f5912d4ccee3'
+ 'ef27f40434ca85ccaf57a7e388eb001e'
+ '6f98767c4ea2cf0580f73ced81efd21a'
+ '54eb22844b5aeed161c0b80aa9008570'
+ 'd6ce6c7bd481a0b3944c944c5b277c0b'
+ 'c35f0a637911b747f8dc3bd3c6156a1b'
+ 'f8690ee18a5ca72555585ee96826c2cf')
build() {
cd ${srcdir}/${pkgname}-${pkgver}
diff --git a/extra/ifplugd/ifplugd b/extra/ifplugd/ifplugd
index 44019d0ee..667fc1f53 100644
--- a/extra/ifplugd/ifplugd
+++ b/extra/ifplugd/ifplugd
@@ -5,47 +5,64 @@
. /etc/rc.conf
. /etc/rc.d/functions
+shopt -s extglob
+
# env vars
-NAME=ifplugd
-CFG=/etc/ifplugd/ifplugd.conf
-IFPLUGD=/usr/sbin/ifplugd
-PID=`pidof -o %PPID $IFPLUGD`
+daemonname=ifplugd
+cfg=/etc/ifplugd/ifplugd.conf
+PID=$(pidof -o %PPID ifplugd)
# source configuration file
-[ -f $CFG ] && . $CFG
+[[ -r $cfg ]] && . "$cfg"
# discover interfaces to monitor
-# (replacing INTERFACES with NET_IFS, since AL
+# (replacing INTERFACES with net_ifs, since AL
# already uses it in /etc/rc.conf)
-[ -z "$NET_IFS" ] &&
- NET_IFS=$(sed -ne 's/.*\<\(eth[0-9]*\):.*/\1/p' /proc/net/dev)
+if [[ -z $net_ifs ]]; then
+ net_ifs=(/sys/class/net/!(lo))
+ net_ifs=("${net_ifs[@]##*/}")
+fi
-case "$1" in
+case $1 in
start)
- stat_busy "Starting $NAME"
- [ -z "$PID" ] && ( for IF in $NET_IFS ; do
- A="`eval echo \$\{ARGS_${IF}\}`"
- [ -z "$A" ] && A="$ARGS"
- $IFPLUGD -i $IF $A
- echo -n " $IF"
- done )
- if [ $? -gt 0 ]; then
+ stat_busy "Starting $daemonname: ${net_ifs[*]}"
+
+ for nic in "${net_ifs[@]}"; do
+ # only start if a PID doesn't already exist
+ if [[ ! -f /var/run/ifplugd.$nic.pid ]]; then
+ args=ARGS_$nic
+ [[ -z ${!args} ]] && args=$ARGS || args=${!args}
+ ifplugd -i "$nic" $args
+
+ # use presence of PID file to check for start success
+ [[ -f /var/run/ifplugd.$nic.pid ]] || (( ++err ))
+ fi
+ done
+ unset nic
+
+ if (( err )); then
stat_fail
+ exit 1
else
- add_daemon $NAME
+ add_daemon $daemonname
stat_done
fi
;;
stop)
- stat_busy "Stopping $NAME"
- [ ! -z "$PID" ] && ( for IF in $NET_IFS ; do
- $IFPLUGD -k -i $IF
- echo -n " $IF"
- done )
- if [ $? -gt 0 ]; then
+ stat_busy "Stopping $daemonname: ${net_ifs[*]}"
+
+ for nic in /var/run/ifplugd.*.pid; do
+ [[ -f $nic ]] || { (( ++err )); break; }
+ nic=${nic%.pid}
+ nic=${nic##*.}
+ ifplugd -k -i "$nic" || (( ++err ))
+ done
+
+ if (( err )); then
stat_fail
+ exit 1
else
- rm_daemon $NAME
+ rm_daemon $daemonname
stat_done
fi
;;
@@ -55,35 +72,41 @@ case "$1" in
$0 start
;;
status)
- for IF in $NET_IFS; do
- $IFPLUGD -c -i $IF
+ for nic in "${net_ifs[@]}"; do
+ ifplugd -c -i "$nic"
done
+ unset nic
;;
suspend)
- stat_busy "Suspending $NAME"
- for IF in $NET_IFS; do
- $IFPLUGD -S -i $IF
- echo -n " $IF"
- done
- if [ $? -gt 0 ]; then
+ stat_busy "Suspending $daemonname: ${net_ifs[*]}"
+ for nic in "${net_ifs[@]}"; do
+ ifplugd -S -i $nic || (( ++err ))
+ done
+ unset nic
+
+ if (( err )); then
stat_fail
+ exit 1
else
stat_done
- fi
+ fi
;;
resume)
- stat_busy "Resuming $NAME"
- for IF in $NET_IFS; do
- $IFPLUGD -R -i $IF
- echo -n " $IF"
+ stat_busy "Resuming $daemonname ${net_ifs[*]}"
+
+ for nic in "${net_ifs[@]}"; do
+ ifplugd -R -i $nic || (( ++err ))
done
- if [ $? -gt 0 ]; then
+ unset nic
+
+ if (( err )); then
stat_fail
+ exit 1
else
stat_done
- fi
- ;;
+ fi
+ ;;
*)
- echo "usage: $0 {start|stop|restart|status|suspend|resume}"
+ echo "usage: $0 {start|stop|restart|status|suspend|resume}"
esac
exit 0
diff --git a/extra/ifplugd/ifplugd.action b/extra/ifplugd/ifplugd.action
index 23b74c60d..07895bcad 100644
--- a/extra/ifplugd/ifplugd.action
+++ b/extra/ifplugd/ifplugd.action
@@ -1,28 +1,29 @@
-#!/bin/sh
+#!/bin/bash
#
# ifplugd.action script for Arch Linux
+#
. /etc/rc.conf
. /etc/rc.d/functions
-plugscript(){ #argumets are ifup|ifdown, interface_name
+plugscript() { # arguments are ifup|ifdown, interface_name
for script in /etc/ifplugd/$1.d/*.sh; do
- [ -x $script ] && $script $2
+ [[ -x $script ]] && "$script" $2
done
return 0
}
-case "$2" in
+case $2 in
up)
- /etc/rc.d/network ifup $1
- plugscript ifup $1
+ /etc/rc.d/network ifup "$1"
+ plugscript ifup "$1"
;;
down)
- plugscript ifdown $1
+ plugscript ifdown "$1"
/etc/rc.d/network ifdown $1
;;
*)
- echo "Wrong arguments" > /dev/stderr
+ echo "Wrong arguments" >&2
;;
esac