PKGBUILDs/extra/ifplugd/ifplugd
2009-10-09 21:23:22 -05:00

89 lines
1.6 KiB
Bash

#!/bin/bash
#
# ifplugd daemon script for Arch Linux
. /etc/rc.conf
. /etc/rc.d/functions
# env vars
NAME=ifplugd
CFG=/etc/ifplugd/ifplugd.conf
IFPLUGD=/usr/sbin/ifplugd
PID=`pidof -o %PPID $IFPLUGD`
# source configuration file
[ -f $CFG ] && . $CFG
# discover interfaces to monitor
# (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)
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_fail
else
add_daemon $NAME
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_fail
else
rm_daemon $NAME
stat_done
fi
;;
restart)
$0 stop
sleep 1
$0 start
;;
status)
for IF in $NET_IFS; do
$IFPLUGD -c -i $IF
done
;;
suspend)
stat_busy "Suspending $NAME"
for IF in $NET_IFS; do
$IFPLUGD -S -i $IF
echo -n " $IF"
done
if [ $? -gt 0 ]; then
stat_fail
else
stat_done
fi
;;
resume)
stat_busy "Resuming $NAME"
for IF in $NET_IFS; do
$IFPLUGD -R -i $IF
echo -n " $IF"
done
if [ $? -gt 0 ]; then
stat_fail
else
stat_done
fi
;;
*)
echo "usage: $0 {start|stop|restart|status|suspend|resume}"
esac
exit 0