#!/bin/bash # # ifplugd daemon script for Arch Linux . /etc/rc.conf . /etc/rc.d/functions # env vars daemonname=ifplugd cfg=/etc/ifplugd/ifplugd.conf ifplugd=/usr/sbin/ifplugd PID=$(pidof -o %PPID $ifplugd) err=0 # source configuration file [[ -r $cfg ]] && . "$cfg" # discover interfaces to monitor # (replacing INTERFACES with net_ifs, since AL # already uses it in /etc/rc.conf) if [[ -z $net_ifs ]]; then net_ifs=(/sys/class/net/!(lo)) net_ifs=("${net_ifs##*/}") fi case "$1" in start) stat_busy "Starting $daemonname" if [[ $PID ]]; then stat_fail exit 1 fi for nic in "${net_ifs[@]}"; do args=ARGS_$nic [[ -z ${!args} ]] && args=$ARGS || args=${!args} $ifplugd -i $nic $args || (( ++err )) echo -n " $nic" done unset nic if (( err )); then stat_fail exit 1 else add_daemon $daemonname stat_done fi ;; stop) stat_busy "Stopping $daemonname" if [[ -z $PID ]]; then stat_fail exit 1 fi for nic in "${net_ifs[@]}"; do $ifplugd -k -i $nic || (( ++err )) echo -n " $nic" done if (( err )); then stat_fail exit 1 else rm_daemon $daemonname stat_done fi ;; restart) $0 stop sleep 1 $0 start ;; status) for nic in "${net_ifs[@]}"; do $ifplugd -c -i $nic done unset nic ;; suspend) stat_busy "Suspending $daemonname" for nic in "${net_ifs[@]}"; do $ifplugd -S -i $IF || (( ++err )) echo -n " $IF" done unset nic if (( err )); then stat_fail exit 1 else stat_done fi ;; resume) stat_busy "Resuming $daemonname" for nic in "${net_ifs[@]}"; do $ifplugd -R -i $nic || (( ++err )) echo -n " $nic" done if (( err )); then stat_fail exit 1 else stat_done fi ;; *) echo "usage: $0 {start|stop|restart|status|suspend|resume}" esac exit 0