[Lunar-commits] r23907 - in moonbase: branches/crater/net/net-tools trunk/net/ifplugd
Moritz Heiber
moe at lunar-linux.org
Tue Apr 3 19:19:34 CEST 2007
Author: moe
Date: 2007-04-03 19:19:34 +0200 (Tue, 03 Apr 2007)
New Revision: 23907
Added:
moonbase/trunk/net/ifplugd/ifplugd-lunar.action
Modified:
moonbase/branches/crater/net/net-tools/network
moonbase/trunk/net/ifplugd/BUILD
Log:
Adding this action script for ifplugd. Currently, it does nothing
as long as we don't use the new network script. Just making sure its
there.
Also check-in the latest version of the network script. Moved around some
code, dhcp related mostly, to be able to call dhcp through the network
script directly to avoid duplicating code (concerning ifplugd)
Modified: moonbase/branches/crater/net/net-tools/network
===================================================================
--- moonbase/branches/crater/net/net-tools/network 2007-04-03 17:13:38 UTC (rev 23906)
+++ moonbase/branches/crater/net/net-tools/network 2007-04-03 17:19:34 UTC (rev 23907)
@@ -26,6 +26,94 @@
fi
}
+function start_dhcp()
+{
+ # include config file for interface
+ source $CONFIGS/$1
+
+ case $DHCP_CLIENT in
+ [dD][hH][cC][pP][cC][dD])
+ PIDFILE=/var/run/dhcpcd-$1.pid
+ RUNFILE=/usr/sbin/dhcpcd
+ ;;
+
+ [dD][hH][cC][lL][iI][eE][nN][tT])
+ PIDFILE=/var/run/dhclient-$1.pid
+ RUNFILE=/sbin/dhclient
+ DHCP_OPTIONS="$DHCP_OPTIONS -pf $PIDFILE -lf /var/state/dhcp/dhclient-$1.leases"
+ ;;
+
+ [uU][dD][hH][cC][pP][cC])
+ PIDFILE=/var/run/udhcpc-$1.pid
+ RUNFILE=/sbin/udhcpc
+ DHCP_OPTIONS="$DHCP_OPTIONS -p $PIDFILE -i"
+ ;;
+ esac
+
+ if [ ! -x $RUNFILE ]; then
+ echo -n " $DHCP_CLIENT not installed"
+ return -1
+ fi
+
+ if [ -e $PIDFILE ]; then
+ if [ $(ps ax | grep `cat $PIDFILE` | grep $DHCP_CLIENT | grep -v grep | wc -l) -ge 1 ]; then
+ echo -n " $DHCP_CLIENT already started"
+ return -3
+ else
+ rm -f $PIDFILE
+ fi
+ fi
+
+ # This is where the magic happens
+ $RUNFILE $DHCP_OPTIONS $1 > /dev/null 2>&1
+ DHCP_EXIT=$?
+ sleep 1
+
+ if [ ! -e $PIDFILE ]; then
+ if [ $DHCP_EXIT -eq 0 ]; then
+ echo -n "DHCP exited cleanly"
+ return -3
+ else
+ echo -n "DHCP failed"
+ return -1
+ fi
+ fi
+}
+
+function stop_dhcp()
+{
+ # Include configuration file
+ source $CONFIGS/$1
+
+ case $DHCP_CLIENT in
+ [dD][hH][cC][pP][cC][dD])
+ KILLCMD="dhcpcd -k $1"
+ PIDFILE=/var/run/dhcpcd-$1.pid
+ ;;
+
+ [dD][hH][cC][lL][iI][eE][nN][tT])
+ PIDFILE=/var/run/dhclient-$1.pid
+ ;;
+
+ [uU][dD][hH][cC][pP][cC])
+ PIDFILE=/var/run/udhcpc-$1.pid
+ ;;
+ esac
+
+ if [ -e $PIDFILE ]; then
+ if [ -z "$KILLCMD" ]; then
+ kill `cat $PIDFILE`
+ else
+ $KILLCMD
+ fi
+
+ if [ -e $PIDFILE ]; then
+ rm -f $PIDFILE
+ fi
+ sleep 1
+ fi
+}
+
function device_start()
{
if [ ! -e "$CONFIGS/$1" ]; then
@@ -40,6 +128,7 @@
if [ "$2" == "auto" ] ; then
case "$AUTO" in
[!yY])
+ echo -n "not started automatically"
return -2
;;
esac
@@ -50,13 +139,13 @@
modprobe $MODULE $MODULE_OPTIONS
fi
- if [ "$MANAGER" == "wpa_supplicant" ] ; then
+ if [ "$MANAGER" == "wpa_supplicant" ] ; then
if [ -x $WPA_SUPPLICANT ] && [ -x $IFPLUGD ] ; then
# we start ifplugd prior to wpa_supplicant because then it brings up the interface
# but doesn't call the dhcp client since there's no connection yet
# Please don't fail here because ifplugd is already running
- if ! ifplugd -c -i $1 &> /dev/null ; then
- $IFPLUGD -I -i $1 -f
+ if ! $IFPLUGD -c -i $1 &> /dev/null ; then
+ $IFPLUGD -I -i $1 -f -r /etc/ifplugd/ifplugd-lunar.action
fi
# FIXME: Make the config file configurable.
@@ -70,8 +159,8 @@
elif [ "$MANAGER" == "ifplugd" ] ; then
if [ -x $IFPLUGD ] ; then
- if ! ifplugd -c -i $1 &> /dev/null ; then
- $IFPLUGD -I -i $1 -f
+ if ! $IFPLUGD -c -i $1 &> /dev/null ; then
+ $IFPLUGD -I -i $1 -f -r /etc/ifplugd/ifplugd-lunar.action
fi
else
echo -n " ERROR: ifplugd is missing!"
@@ -101,55 +190,7 @@
# Assume direct DHCP/static IPs if no manager/manual is set
if [ "$ADDRESS" == "dhcp" ] && [ ! "x${DHCP_CLIENT}" == "x" ] ; then
- case $DHCP_CLIENT in
- [dD][hH][cC][pP][cC][dD])
- PIDFILE=/var/run/dhcpcd-$1.pid
- RUNFILE=/sbin/dhcpcd
- ;;
-
- [dD][hH][cC][lL][iI][eE][nN][tT])
- PIDFILE=/var/run/dhclient-$1.pid
- RUNFILE=/sbin/dhclient
- DHCP_OPTIONS="$DHCP_OPTIONS -pf $PIDFILE -lf /var/state/dhcp/dhclient-$1.leases"
- ;;
-
- [uU][dD][hH][cC][pP][cC])
- PIDFILE=/var/run/udhcpc-$1.pid
- RUNFILE=/sbin/udhcpc
- DHCP_OPTIONS="$DHCP_OPTIONS -p $PIDFILE -i"
- ;;
- esac
-
- if [ ! -x $RUNFILE ]; then
- echo -n " $DHCP_CLIENT not installed"
- return -1
- fi
-
- if [ -e $PIDFILE ]; then
- if [ $(ps ax | grep `cat $PIDFILE` | grep $DHCP_CLIENT | grep -v grep | wc -l) -ge 1 ]; then
- echo -n " $DHCP_CLIENT already started"
- return -3
- else
- rm -f $PIDFILE
- fi
- fi
-
- # This is where the magic happens
- $RUNFILE $DHCP_OPTIONS $1 > /dev/null 2>&1
- DHCP_EXIT=$?
- sleep 1
-
- if [ ! -e $PIDFILE ]; then
- if [ $DHCP_EXIT -eq 0 ]; then
- echo -n "DHCP exited cleanly"
- return -3
- else
- echo -n "DHCP failed"
- return -1
- fi
- fi
-
- # Set a static IP if its there
+ start_dhcp $1
elif [ ! "x${ADDRESS}" == "x" ] ; then
if [ ! "x$NETMASK" == "x" ]; then
NETMASK="netmask $NETMASK"
@@ -186,7 +227,8 @@
return -1
fi
- . $CONFIGS/$1
+ # Source configuration file
+ source $CONFIGS/$1
for ROUTECMD in "$ROUTE_4" "$ROUTE_3" "$ROUTE_2" "$ROUTE_1" ; do
if [ -n "$ROUTECMD" ] ; then
@@ -212,50 +254,19 @@
if [ "$MANAGER" == "ifplugd" ] || [ "$MANAGER" == "wpa_supplicant" ]; then
case $MANAGER in
ifplugd)
- ifplugd -i $1 -k
+ $IFPLUGD -r /etc/ifplugd/ifplugd-lunar.action -i $1 -k
sleep 1
;;
wpa_supplicant)
- ifplugd -i $1 -k
+ $IFPLUGD -r /etc/ifplugd/ifplugd-lunar.action -i $1 -k
kill `ps ax | grep wpa_supplicant | grep "-i$1" | awk '{print $1}'`
sleep 1
;;
esac
fi
-
- if [ "$ADDRESS" == "dhcp" ] ; then
- case $DHCP_CLIENT in
- [dD][hH][cC][pP][cC][dD])
- KILLCMD="dhcpcd -k $1"
- PIDFILE=/var/run/dhcpcd-$1.pid
- ;;
- [dD][hH][cC][lL][iI][eE][nN][tT])
- PIDFILE=/var/run/dhclient-$1.pid
- ;;
-
- [uU][dD][hH][cC][pP][cC])
- PIDFILE=/var/run/udhcpc-$1.pid
- ;;
- esac
-
- if [ -e $PIDFILE ]; then
- if [ -z "$KILLCMD" ]; then
- kill `cat $PIDFILE`
- else
- $KILLCMD
- fi
-
- rm -f $PIDFILE
- sleep 1
- else
- case $AUTO in
- [!yY])
- echo -n " not started"
- return -1
- ;;
- esac
- fi
+ if [ "$ADDRESS" == "dhcp" ] && [ ! "x${DHCP_CLIENT}" == "x" ] ; then
+ stop_dhcp $1
fi
$IFCONFIG $1 down
@@ -265,7 +276,7 @@
fi
}
-export -f device_start device_stop
+export -f device_start device_stop start_dhcp stop_dhcp
start()
{
@@ -311,9 +322,9 @@
{
if [ -z "$2" ]; then
echo "Stopping network:"
- for device in `$IFCONFIG | cut -d" " -f1 | uniq | grep -E [a-z0-9]+ | grep -v lo | sort -r`; do
+ for device in `/sbin/ifconfig | cut -d" " -f1 | uniq | grep -E [a-z0-9]+ | grep -v lo | sort -r`; do
echo -n " * Stopping $device: "
- device_stop $device
+ device_stop $device auto
chkresult
done
else
@@ -329,26 +340,34 @@
echo "Restarting network:"
for device in `ls -1 $CONFIGS | cut -d"-" -f1 | uniq`; do
echo -n " * Stopping $device: "
- device_stop $device
+ device_stop $device auto
chkresult
- sleep 1
echo -n " * Starting $device: "
- device_start $device
+ device_start $device auto
chkresult
done
else
echo -n " * Stopping $2: "
device_stop $2
chkresult
- sleep 1
echo -n " * Starting $2: "
device_start $2
chkresult
fi
}
+dhcp_up()
+{
+ start_dhcp $2
+}
+
+dhcp_down()
+{
+ stop_dhcp $2
+}
+
case "$1" in
- start|stop|restart)
+ start|stop|dhcp_up|dhcp_down|restart)
;;
*)
Modified: moonbase/trunk/net/ifplugd/BUILD
===================================================================
--- moonbase/trunk/net/ifplugd/BUILD 2007-04-03 17:13:38 UTC (rev 23906)
+++ moonbase/trunk/net/ifplugd/BUILD 2007-04-03 17:19:34 UTC (rev 23907)
@@ -1,7 +1,7 @@
(
- sedit 's:/sbin/ifup:/etc/init.d/network start:' conf/ifplugd.action &&
- sedit 's:/sbin/ifdown:/etc/init.d/network stop:' conf/ifplugd.action &&
- default_build
+ default_build &&
+ install -m0750 $SCRIPT_DIRECTORY/ifplugd-lunar.action /etc/ifplugd/
+
) > $C_FIFO 2>&1
Added: moonbase/trunk/net/ifplugd/ifplugd-lunar.action
===================================================================
--- moonbase/trunk/net/ifplugd/ifplugd-lunar.action (rev 0)
+++ moonbase/trunk/net/ifplugd/ifplugd-lunar.action 2007-04-03 17:19:34 UTC (rev 23907)
@@ -0,0 +1,15 @@
+#!/bin/bash
+# This network script takes care of running your favourite dhcp client
+# on the interface you requested it to run on
+
+NSCRIPT="/etc/init.d/network"
+
+if [ -n "$1" ] && [ -n "$2" ] ; then
+ if [ "$2" == "up" ]; then
+ exec $NSCRIPT dhcp_up $1
+ elif [ "$2" == "down" ]; then
+ exec $NSCRIPT dhcp_down $1
+ fi
+fi
+
+exit 0
More information about the Lunar-commits
mailing list