[Lunar-commits] r23919 - in moonbase/branches/crater: . testing testing/lunar-init
Moritz Heiber
moe at lunar-linux.org
Wed Apr 4 22:29:27 CEST 2007
Author: moe
Date: 2007-04-04 22:29:27 +0200 (Wed, 04 Apr 2007)
New Revision: 23919
Added:
moonbase/branches/crater/testing/
moonbase/branches/crater/testing/lunar-init/
moonbase/branches/crater/testing/lunar-init/BUILD
moonbase/branches/crater/testing/lunar-init/DEPENDS
moonbase/branches/crater/testing/lunar-init/DETAILS
moonbase/branches/crater/testing/lunar-init/hostname
moonbase/branches/crater/testing/lunar-init/mount
moonbase/branches/crater/testing/lunar-init/netmount
moonbase/branches/crater/testing/lunar-init/network
Log:
Checking in the new lunar-init module .. not done yet. Just so
sofar can take a look at it.
Added: moonbase/branches/crater/testing/lunar-init/BUILD
===================================================================
--- moonbase/branches/crater/testing/lunar-init/BUILD (rev 0)
+++ moonbase/branches/crater/testing/lunar-init/BUILD 2007-04-04 20:29:27 UTC (rev 23919)
@@ -0,0 +1,15 @@
+(
+
+ prepare_install &&
+
+ cd $SCRIPT_DIRECTORY/ &&
+
+ for SCRIPT in network hostname mount netmount ; do
+ if [ ! -f /etc/init.d/${SCRIPT} ] ; then
+ install -m0750 ${SCRIPT_DIRECTORY}/${SCRIPT} /etc/init.d/{$SCRIPT}
+ else
+ message "${PROBLEM_COLOR}Another copy of the script ${QUERY_COLOR}${SCRIPT}${PROBLEM_COLOR}"
+ message "in /etc/init.d/ detected. Aborting install of ${QUERY_COLOR}${SCRIPT}${PROBLEM_COLOR}.${DEFAULT_COLOR}"
+ done
+
+) > $C_FIFO 2>&1
Added: moonbase/branches/crater/testing/lunar-init/DEPENDS
===================================================================
--- moonbase/branches/crater/testing/lunar-init/DEPENDS (rev 0)
+++ moonbase/branches/crater/testing/lunar-init/DEPENDS 2007-04-04 20:29:27 UTC (rev 23919)
@@ -0,0 +1,3 @@
+depends net-tools &&
+depends sysvinit &&
+depends e2fsprogs
Added: moonbase/branches/crater/testing/lunar-init/DETAILS
===================================================================
--- moonbase/branches/crater/testing/lunar-init/DETAILS (rev 0)
+++ moonbase/branches/crater/testing/lunar-init/DETAILS 2007-04-04 20:29:27 UTC (rev 23919)
@@ -0,0 +1,14 @@
+ MODULE=lunar-init
+ VERSION=0.1
+ WEB_SITE=http://lunar-linux.org
+ ENTERED=20070404
+ SHORT="the Lunar init scripts vital to any system"
+cat << EOF
+This package contains vital init scripts needed to run a Lunar Linux
+powered computer. For now, these scripts are:
+
+network - takes care of your network connections
+hostname - sets your hostname during boottime
+netmount - mounts your network filesystems on boot
+mount - mounts all your filesystems at boottime
+EOF
Copied: moonbase/branches/crater/testing/lunar-init/hostname (from rev 23849, moonbase/trunk/net/net-tools/init.d/hostname)
===================================================================
--- moonbase/branches/crater/testing/lunar-init/hostname (rev 0)
+++ moonbase/branches/crater/testing/lunar-init/hostname 2007-04-04 20:29:27 UTC (rev 23919)
@@ -0,0 +1,24 @@
+#!/bin/sh
+#
+# hostname: set the system's host and domain name
+#
+
+case $1 in
+ start)
+ if [ ! -e "/etc/hostname" ]; then
+ HOSTNAME=localhost
+ else
+ HOSTNAME=$(cat /etc/hostname)
+ fi
+ hostname "$HOSTNAME"
+ echo "Hostname set to \"$HOSTNAME\""
+
+ if [ ! -e "/etc/domainname" ]; then
+ echo "Domainname not set"
+ else
+ domainname -F /etc/domainname
+ echo "System Domainname set to \"$(cat /etc/domainname)\""
+ fi
+ ;;
+esac
+
Copied: moonbase/branches/crater/testing/lunar-init/mount (from rev 23849, moonbase/trunk/filesys/e2fsprogs/init.d/mount)
===================================================================
--- moonbase/branches/crater/testing/lunar-init/mount (rev 0)
+++ moonbase/branches/crater/testing/lunar-init/mount 2007-04-04 20:29:27 UTC (rev 23919)
@@ -0,0 +1,393 @@
+#!/bin/bash
+#
+# mount - mount and umount filesystems
+
+wait_some()
+{
+ if [ -n "$1" ]; then
+ sleep $1
+ fi
+}
+
+
+run_without_msg()
+{
+ if [ -z "$1" ]; then
+ echo -n "run_without_msg: missing command."
+ echo -e $RESULT_FAIL
+ return
+ fi
+
+ if [ -n "$DEBUG" ]; then
+ echo -e "< $1 >\n"
+ eval $1
+ else
+ eval $1 &> /dev/null
+ fi
+
+ local exit_status=$?
+
+ wait_some "$2"
+
+ return $exit_status
+}
+
+
+run_with_msg_and_exit_codes()
+{
+ # $1 : message
+ # $2 : command
+ # $3 : white space separated list of OK exit values
+ # $4 : white space separated list of WARNING exit values
+ # $5 : white separated list of FAILURE exit values
+
+ if [ ! ${#} -eq 5 ]; then
+ echo "run_with_special_exit_codes: wrong parameter count. 5 params expected"
+ return 1
+ fi
+
+ echo -n "$1"
+
+ if [ -n "${DEBUG}" ]; then
+ echo -e "\n< run_with_special_exit_codes >"
+ echo -e "\n< command : $2 >"
+ echo -e "\n< valid : $3 >"
+ echo -e "\n< warn : $4 >"
+ echo -e "\n< fail : $5 >"
+ eval $2
+ else
+ eval $2 &> /dev/null
+ fi
+
+ local exit_status=$?
+
+ for i in "$3"
+ do
+ if [ "$exit_status" = "$i" ]; then
+ echo -e $RESULT_OK
+ return $exit_status
+ fi
+ done
+
+ for i in "$4"
+ do
+ if [ "$exit_status" = "$i" ]; then
+ echo -e $RESULT_WARN
+ return $exit_status
+ fi
+ done
+
+ for i in "$5"
+ do
+ if [ "$exit_status" = "$i" ]; then
+ echo -e $RESULT_FAIL
+ return $exit_status
+ fi
+ done
+
+ warn_msg "result $exit_status did not match any supplied exit code value"
+ return $exit_status
+}
+
+
+run_with_msg()
+{
+ # message == $1
+ # cmd == $2
+
+ if [ -z "$1" ]; then
+ echo -n "run_cmd_with_msg: missing message."
+ echo -e $RESULT_WARN
+ return
+ fi
+
+ if [ -z "$2" ]; then
+ echo -n "run_cmd_with_msg: missing command."
+ echo -e $RESULT_WARN
+ return
+ fi
+
+ echo -n "$1"
+
+ if [ -n "$DEBUG" ]; then
+ echo -n "< $2 >"
+ eval $2
+ else
+ eval $2 &> /dev/null
+ fi
+
+ if [ $? -eq 0 ]; then
+ echo -e $RESULT_OK
+ wait_some $3
+ return 0
+ else
+ echo -e $RESULT_FAIL
+ wait_some $3
+ return 1
+ fi
+}
+
+
+warn_msg()
+{
+ echo -ne "$1$RESULT_WARN"
+}
+
+
+kernel_is_26()
+{
+ uname -r | grep -q "^2\.6"
+}
+
+
+kernel_is_24()
+{
+ uname -r | grep -q "^2\.4"
+}
+
+
+start()
+{
+ echo -e "Mounting filesystems:"
+
+ run_with_msg " * Mounting /proc" "mount -n -t proc proc /proc"
+ if ! grep -qw "ro" /proc/cmdline; then
+ run_with_msg " * Remounting root read-only" "mount -n -o remount,ro /"
+ fi
+
+ DEVNODES=`grep -o "dev=.*" /proc/cmdline | cut -d" " -f1 | sed -e "s/dev=//g"`
+
+ case $DEVNODES in
+ static|devfs)
+ ;;
+ udev)
+ if kernel_is_24 ; then
+ warn_message "No udev for 2.4 kernels. Kernel commandline parameter ignored."
+ DEVNODES=""
+ fi
+ ;;
+ ?*)
+ warn_msg "Wrong device nodes parameter \"$DEVNODES\" on kernel line. Valid are: devfs, udev, static\nFalling back to default behaviour"
+ DEVNODES=""
+ ;;
+ esac
+
+ # default bahaviour if the user did not choose himself
+ if [ -z "$DEVNODES" ]; then
+ if kernel_is_26 && [ -x "/sbin/udevd" ] ; then
+ DEVNODES="udev"
+ if [ -n "$DEBUG" ] ; then
+ echo -e "\n< Found udev >"
+ fi
+ elif [ -x "/sbin/devfsd" ] ; then
+ DEVNODES="devfs"
+ if [ -n "$DEBUG" ] ; then
+ echo -e "\n< Found devfs >"
+ fi
+ else
+ warn_msg "Assuming a static /dev"
+ DEVNODES="static"
+ fi
+ fi
+
+ kernel_is_26 && run_with_msg " * Mounting /sys" "mount -n -t sysfs sysfs /sys"
+
+ if [ "$DEVNODES" = "devfs" ]; then
+ run_with_msg " * Mounting /dev" "mount -n -t devfs devfs /dev"
+ run_with_msg "Starting devfsd" "devfsd /dev"
+ elif [ "$DEVNODES" = "udev" ]; then
+ run_with_msg " * Mounting tmpfs on /dev" "mount -t tmpfs tmpfs /dev -o size=6m,mode=0755"
+ run_without_msg "echo > /proc/sys/kernel/hotplug" # Hotplug agents are deprecated!
+ run_with_msg "Creating udev device nodes on /dev" "/sbin/udevstart"
+ run_with_msg "Starting udev device handling daemon" "/sbin/udevd --daemon"
+ run_without_msg "mkdir -p /dev/{pts,shm}"
+ if [ ! -h /dev/fd ]; then
+ ln -sf /proc/self/fd /dev/fd
+ fi
+
+ ln -snf /proc/self/fd/0 /dev/stdin
+ ln -snf /proc/self/fd/1 /dev/stdout
+ ln -snf /proc/self/fd/2 /dev/stderr
+ fi
+
+ # or do we want to explicitly _not_ fsck at all
+ if ! grep -qw nofsck /proc/cmdline ; then
+ # force fsck run?
+ if [ -f /forcefsck ] || grep -qw forcefsck /proc/cmdline ; then
+ FORCE="-f"
+ fi
+
+ # check filesystems
+ FSCKLEVELS=$(sed 's/#.*$//g' /etc/fstab | awk '($6>0){print$6}' | sort -n | uniq)
+ if [ -n "$FSCKLEVELS" ]; then
+ echo "Checking file systems:"
+ for FSCKLEVEL in $FSCKLEVELS; do
+ for FS in $(sed 's/#.*$//g' /etc/fstab | awk "(\$6==$FSCKLEVEL){print\$1}"); do
+
+ run_with_msg_and_exit_codes " * Checking $FS" "fsck -T -C -y -V $FORCE $FS" "0" "1" ""
+ if [ $? -ge 2 ]; then
+ echo ""
+ echo " *** fsck failed! ***"
+ echo ""
+ echo " Please repair your file system manually by"
+ echo " running /sbin/fsck without the -p option."
+ echo ""
+ sulogin
+ reboot -f
+ fi
+ done
+ done
+ fi
+ fi
+
+ run_with_msg " * Remounting root read-write" "mount -n -o remount,rw /"
+ if [ "$FORCE" == "-f" ]; then
+ rm -f /forcefsck
+ fi
+
+ run_without_msg "> /etc/mtab"
+ # hack to get it into /etc/mtab
+ run_without_msg "mount -f -o remount,rw /"
+ run_with_msg "Turning on swap" "swapon -a"
+
+ echo "Mounting remaining filesystems: "
+
+ # hack to get it into /etc/mtab
+ if [ "$DEVNODES" == "devfs" ]; then
+ run_without_msg "mount -f -t devfs devfs /dev"
+ fi
+
+ # sort the filesystems, swapfiles at bottom, squeeze separators into spaces
+ sed 's/#.*$//g' /etc/fstab | tr '\t' ' ' | tr -s '[:space:]' | grep -v -e '^$\|noauto' | LC_ALL=C sort -k2 | while read DEVICE MOUNTPOINT FSTYPE OPTS REST
+ do
+ case $MOUNTPOINT in
+ /|/proc|/sys|/dev) # been mounted previously
+ continue
+ ;;
+ none)
+ continue
+ ;;
+ esac
+
+ case $FSTYPE in
+ nfs|nfs4|smbfs) # we don't do networked fs's yet!
+ continue
+ ;;
+ esac
+
+ if [ -n "$OPTS" ]; then
+ OPTS="-o $OPTS"
+ fi
+
+ run_with_msg " * Mounting $MOUNTPOINT" "mount $MOUNTPOINT $OPTS"
+
+ done
+}
+
+
+stop()
+{
+ # Establish where to get mount table from, save these since the files change if we unmount something
+ if [ -r /proc/mounts ] ; then
+ MOUNTS=/proc/mounts
+ else
+ MOUNTS=/etc/mtab
+ fi
+
+ # write wtmp in /var before umounting /var
+ run_without_msg "reboot -w"
+
+ echo "Unmounting all filesystems:"
+
+ cat $MOUNTS | tac | while read TYPE PNT FS REST ; do
+
+ case $FS in
+ nfs|nfs4|smbfs) # we don't do net filesystems
+ continue
+ ;;
+ esac
+
+ case $PNT in
+ /|/proc|/dev|/sys) # no need to unmount these
+ continue
+ ;;
+ esac
+
+ echo -n " * Umounting $PNT"
+ run_without_msg "sync ; sync" # Flush buffers
+
+ ITERATION=1
+ UNMOUNT_ERROR=0
+
+ until [ -z `grep -w $PNT $MOUNTS | awk '{ print $1 }'` ] || [ $UNMOUNT_ERROR -eq 1 ];
+ do
+ case $ITERATION in
+ 1)
+ run_without_msg "umount $PNT"
+ ;;
+ 2)
+ sleep 1
+ run_without_msg "fuser -s -km -3 $PNT" "1"
+ run_without_msg "umount $PNT"
+ ;;
+ 3)
+ sleep 1
+ run_without_msg "fuser -s -km -9 $PNT" "1"
+ run_without_msg "umount $PNT" "1"
+ ;;
+ 4)
+ sleep 1
+ run_without_msg "fuser -s -km -9 $PNT" "1"
+ run_without_msg "umount -lf $PNT" "4"
+ run_without_msg "sync; sync"
+ ;;
+ 5)
+ UNMOUNT_ERROR=1 # warn that it hasn't been able to unmount the easy way
+ ;;
+ esac
+
+ (( ITERATION++ ))
+ done
+
+ if [ $UNMOUNT_ERROR -eq 1 ]; then # haven't been able to unmount the point, so be drastic
+ echo -e $RESULT_WARN
+ run_with_msg " * Attempting to remount $PNT read-only" "mount $PNT -o remount,ro"
+ else
+ echo -e $RESULT_OK
+ fi
+
+ if [ "$TYPE" == "/dev/loop*" -a -f $PNT ] ; then
+ # unhook loopback device too
+ run_with_msg "Detaching loopback device $TYPE" "losetup -d $TYPE"
+ fi
+
+ done
+
+ run_with_msg "Turning off swap" "swapoff -a"
+
+ run_without_msg "sync; sync;" "2" # might take some time so we wait here for a couple of seconds
+
+ if ! run_with_msg " * Remounting root read-only" "mount -n -o remount,ro /" ; then
+ if ! run_with_msg " * Trying again to remount root read-only" "umount -l -O remount,ro /" "4" ; then
+ read -n 1 -t 30 -p "Do you want to login? (y/n) " CONFIRM
+ echo ""
+ case $CONFIRM in
+ y|Y) sulogin ;;
+ esac
+ fi
+ fi
+}
+
+
+# to avoid confusion we force only these options as being valid:
+case "$1" in
+ start|stop)
+ ;;
+
+ *)
+ echo "Warning: $0 should never be called directly";
+ exit 1
+ ;;
+esac
+
+. /lib/lsb/init-functions
Copied: moonbase/branches/crater/testing/lunar-init/netmount (from rev 23849, moonbase/trunk/net/net-tools/init.d/netmount)
===================================================================
--- moonbase/branches/crater/testing/lunar-init/netmount (rev 0)
+++ moonbase/branches/crater/testing/lunar-init/netmount 2007-04-04 20:29:27 UTC (rev 23919)
@@ -0,0 +1,28 @@
+#!/bin/bash
+#
+# netmount - mounts network shares on nfs and smbfs
+#
+# description: mount and umount the filesystem
+# chkconfig: 345 15 85
+
+
+start() {
+ mount -t nfs,nfs4,smbfs -a &&
+ echo -e "Mounting network shares:$RESULT_OK" ||
+ echo -e "Mounting network shares:$RESULT_FAIL"
+}
+
+stop() {
+ umount -t nfs,nfs4,smbfs -a -f -l &&
+ echo -e "Unmounting network shares:$RESULT_OK" ||
+ echo -e "Unmounting network shares:$RESULT_FAIL"
+}
+
+# to avoid confusion we force only these options as being valid:
+case "$1" in
+ start|stop|uninstall|install) ;;
+ *) echo "Usage: $0 {start|stop}" ;;
+esac
+
+. /lib/lsb/init-functions
+
Copied: moonbase/branches/crater/testing/lunar-init/network (from rev 23849, moonbase/trunk/net/net-tools/init.d/network)
===================================================================
--- moonbase/branches/crater/testing/lunar-init/network (rev 0)
+++ moonbase/branches/crater/testing/lunar-init/network 2007-04-04 20:29:27 UTC (rev 23919)
@@ -0,0 +1,379 @@
+#! /bin/bash
+#
+# network Bring up/down networking
+#
+# chkconfig: 345 15 90
+# description: Activates/Deactivates all network interfaces configured to \
+# start at boot time.
+# probe: true
+
+shopt -s extglob
+CONFIGS="/etc/config.d/network"
+IFPLUGD="/usr/sbin/ifplugd"
+WPA_SUPPLICANT="/usr/sbin/wpa_supplicant"
+IFCONFIG="/sbin/ifconfig"
+IWCONFIG="/usr/sbin/iwconfig"
+ROUTE="/sbin/route"
+
+chkresult()
+{
+ if [ $? -eq "-1" ] ; then
+ echo -e $RESULT_FAIL
+ elif [ $? -eq "-3" ]; then
+ echo -e $RESULT_WARN
+ else
+ echo -e $RESULT_OK
+ 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
+ echo -n "missing config file"
+ exit 1
+ fi
+
+ # include config file for interface
+ source $CONFIGS/$1
+
+ # be sure that the interface is ment to be started on boot
+ if [ "$2" == "auto" ] ; then
+ case "$AUTO" in
+ [!yY])
+ echo -n "not started automatically"
+ return -2
+ ;;
+ esac
+ fi
+
+ # load module if specified
+ if [ -n "$MODULE" ]; then
+ modprobe $MODULE $MODULE_OPTIONS
+ fi
+
+ 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 -r /etc/ifplugd/ifplugd-lunar.action
+ fi
+
+ # FIXME: Make the config file configurable.
+ # Also, rely on the configuration to determine whether or not the interface is enabled
+ $WPA_SUPPLICANT -B -w -Dwext -i${1} -c/etc/wpa_supplicant.conf
+
+ else
+ echo -n " ERROR: wpa_supplicant and/or ifplugd are missing!"
+ return -1
+ fi
+
+ elif [ "$MANAGER" == "ifplugd" ] ; then
+ if [ -x $IFPLUGD ] ; then
+ 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!"
+ fi
+
+ elif [ "$MANAGER" == "manual" ] || [ -z "$MANAGER" ] ; then
+ if [ "$WIRELESS" == "Y" ] && [ -x $IWCONFIG ] ; then
+ if [ ! "x$WIRELESS_MODE" == "x" ] ; then
+ $IWCONFIG $1 mode $WIRELESS_MODE
+ fi
+
+ if [ ! "x$WIRELESS_KEY" == "x" ] ; then
+ $IWCONFIG $1 key $WIRELESS_KEY
+ fi
+
+ if [ ! "x$WIRELESS_RATE" == "x" ] ; then
+ $IWCONFIG $1 rate $WIRELESS_RATE
+ fi
+
+ if [ ! "x$WIRELESS_ESSID" == "x" ] ; then
+ $IWCONFIG $1 essid $WIRELESS_ESSID
+ fi
+ elif [ "$WIRELESS" == "Y" ] ; then
+ echo -n " ERROR: wireless_tools not installed!"
+ return -1
+ fi
+
+ # Assume direct DHCP/static IPs if no manager/manual is set
+ if [ "$ADDRESS" == "dhcp" ] && [ ! "x${DHCP_CLIENT}" == "x" ] ; then
+ start_dhcp $1
+ elif [ ! "x${ADDRESS}" == "x" ] ; then
+ if [ ! "x$NETMASK" == "x" ]; then
+ NETMASK="netmask $NETMASK"
+ fi
+
+ if [ ! "x$BROADCAST" == "x" ]; then
+ BROADCAST="broadcast $BROADCAST"
+ fi
+
+ # If there is an address then ifconfig will be able to bring up the device anyway
+ # so no error handling here
+ $IFCONFIG $1 ${ADDRESS} $IFCONF_OPTS $NETMASK $BROADCAST up >/dev/null 2>&1
+ fi
+ else
+ echo -n " ERROR: No address specified and DHCP not configured!"
+ return -1
+ fi
+
+ # Now for the static routes
+ # FIXME: This is not configurable through lnet anymore
+
+ for ROUTECMD in "$ROUTE_1" "$ROUTE_2" "$ROUTE_3" "$ROUTE_4" ; do
+ if [ ! "x$ROUTECMD" == "x" ] ; then
+ echo -e "\n adding route: $ROUTECMD"
+ $ROUTE $ROUTECMD
+ fi
+ done
+}
+
+function device_stop()
+{
+ if [ ! -e "$CONFIGS/$1" ]; then
+ echo -n " missing config for $1"
+ return -1
+ fi
+
+ # Source configuration file
+ source $CONFIGS/$1
+
+ for ROUTECMD in "$ROUTE_4" "$ROUTE_3" "$ROUTE_2" "$ROUTE_1" ; do
+ if [ -n "$ROUTECMD" ] ; then
+ if $(echo $ROUTECMD | grep -q "^add ") ; then
+ ROUTECMD=$(echo $ROUTECMD | sed 's/^add /del /')
+ elif $(echo $ROUTECMD | grep -q "^del ") ; then
+ ROUTECMD=$(echo $ROUTECMD | sed 's/^del /add /')
+ fi
+ echo -e "\n deleting route: $ROUTECMD"
+ $ROUTE $ROUTECMD
+ fi
+ done
+
+ if [ `ifconfig | grep $1 | wc -l` -ne 1 ]; then
+ case $AUTO in
+ [!yY])
+ echo -n " not started"
+ return -1
+ ;;
+ esac
+ fi
+
+ if [ "$MANAGER" == "ifplugd" ] || [ "$MANAGER" == "wpa_supplicant" ]; then
+ case $MANAGER in
+ ifplugd)
+ $IFPLUGD -r /etc/ifplugd/ifplugd-lunar.action -i $1 -k
+ sleep 1
+ ;;
+ wpa_supplicant)
+ $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" ] && [ ! "x${DHCP_CLIENT}" == "x" ] ; then
+ stop_dhcp $1
+ fi
+
+ $IFCONFIG $1 down
+
+ if [ -n "$MODULE" ]; then
+ modprobe -r $MODULE
+ fi
+}
+
+export -f device_start device_stop start_dhcp stop_dhcp
+
+start()
+{
+ # Do startup for all interfaces if none is specified
+ if [ -z "$2" ]; then
+ echo "Starting network:"
+ # Add routing entry for loopback interface
+ if [ ! $($ROUTE -n | grep 127.0.0.0 | wc -l) -ge 1 ]; then
+ echo -n " * Starting lo: "
+ $IFCONFIG lo 127.0.0.1 netmask 255.0.0.0
+ $ROUTE add -net 127.0.0.0 netmask 255.0.0.0 dev lo
+ echo -e $RESULT_OK
+ fi
+
+ for device in `ls -1 $CONFIGS | cut -d"-" -f1 | uniq`; do
+ echo -n " * Starting $device: "
+ device_start $device auto
+ chkresult
+ done
+
+ if [ -e /etc/config.d/gateway ]; then
+ GATEWAY=`cat /etc/config.d/gateway`
+ if [ -n "$GATEWAY" ] && ! ($ROUTE -n | grep -q "^0\.0\.0\.0.*UG.*$") ; then
+ echo -n " * setting default route: "
+ $ROUTE add default gateway $GATEWAY
+ fi
+
+ if [ `route -n | grep $GATEWAY | wc -l` -lt 1 ]; then
+ echo -n "failed to set gateway"
+ echo -e $RESULT_FAIL
+ else
+ echo -e $RESULT_OK
+ fi
+ fi
+ else
+ echo -n " * Starting $2: "
+ device_start $2
+ chkresult
+ fi
+}
+
+stop()
+{
+ if [ -z "$2" ]; then
+ echo "Stopping network:"
+ 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 auto
+ chkresult
+ done
+ else
+ echo -n " * Stopping $2: "
+ device_stop $2
+ chkresult
+ fi
+}
+
+restart()
+{
+ if [ -z "$2" ]; then
+ echo "Restarting network:"
+ for device in `ls -1 $CONFIGS | cut -d"-" -f1 | uniq`; do
+ echo -n " * Stopping $device: "
+ device_stop $device auto
+ chkresult
+ echo -n " * Starting $device: "
+ device_start $device auto
+ chkresult
+ done
+ else
+ echo -n " * Stopping $2: "
+ device_stop $2
+ chkresult
+ echo -n " * Starting $2: "
+ device_start $2
+ chkresult
+ fi
+}
+
+dhcp_up()
+{
+ start_dhcp $2
+}
+
+dhcp_down()
+{
+ stop_dhcp $2
+}
+
+case "$1" in
+ start|stop|dhcp_up|dhcp_down|restart)
+ ;;
+
+ *)
+ echo "Usage: $0 {start|stop|restart} [device]"
+ exit 0
+ ;;
+esac
+
+. /lib/lsb/init-functions
More information about the Lunar-commits
mailing list