[Lunar-commits] <lunar-tools> lnet: Properly set dhcp defaults when adding a new device

Stefan Wold ratler at lunar-linux.org
Tue Jul 31 11:37:39 CEST 2012


commit b1f03fc97510bc5c4d0c6273943517a60db006f7
Author: Stefan Wold <ratler at lunar-linux.org>
Date: Mon, 25 Jun 2012 10:53:52 -0700
URL: https://github.com/lunar-linux/lunar-tools/commit/b1f03fc97510bc5c4d0c6273943517a60db006f7

lnet: Properly set dhcp defaults when adding a new device

- A new ethX file is now created immediately when adding a new device
  with dhcpcd as default instead of fooling the user into believing
  the options actually have been set while they actually were not
- Removed some annoying default texts
---
  lnet/lnet                                                    +55/-41   
  1 files changed, 55 insertions (+), 41 deletions (-)

--- a/lnet/lnet
+++ b/lnet/lnet
@@ -1,6 +1,6 @@
 #!/bin/bash
 ############################################################
-# Copyright 2002-2005 The Lunar Linux Team                 #
+# Copyright 2002-2012 The Lunar Linux Team                 #
 ############################################################
 # lnet is a menu driven configurator for the networking    #
 # init script                                              #
@@ -10,6 +10,8 @@
 # Just kidding.  This is an adaption of the network config #
 # contained within the Lunar install script.               #
 #                                                          #
+# Copyright 2012 by Stefan Wold                            #
+#                                                          #
 # this code is GPLv2                                       #
 ############################################################
 
@@ -299,11 +301,46 @@ unset WIRELESS DEVICE AUTO MODULE MODULE_OPTIONS ADDRESS MANAGER
 unset NETMASK BROADCAST GATEWAY DHCP_CLIENT DHCP_OPTIONS
 unset WIRELESS_KEY WIRELESS_RATE WIRELESS_MODE WIRELESS_ESSID
 
+if_template() {
+    cat > $CONFIG_DIR/$DEVICE << EOF
+#
+# configuration for "$DEVICE"
+# automatically generated by lnet - do not edit, run 'lnet' instead
+# -- `date`
+#
+AUTO="${AUTO:-Y}"
+MODULE="$MODULE"
+MODULE_OPTIONS="$MODULE_OPTIONS"
+
+MANAGER="${MANAGER:-manual}"
+
+WIRELESS="${WIRELESS:-N}"
+WIRELESS_KEY="$WIRELESS_KEY"
+WIRELESS_RATE="$WIRELESS_RATE"
+WIRELESS_MODE="$WIRELESS_MODE"
+WIRELESS_ESSID="$WIRELESS_ESSID"
+
+ADDRESS="$ADDRESS"
+NETMASK="$NETMASK"
+BROADCAST="$BROADCAST"
+IFCONF_OPTS="$IFCONF_OPTS"
+
+DHCP_CLIENT="${DHCP_CLIENT:-dhcpcd}"
+DHCP_OPTIONS="$DHCP_OPTIONS"
+
+ROUTE_1="$ROUTE_1"
+ROUTE_2="$ROUTE_2"
+ROUTE_3="$ROUTE_3"
+ROUTE_4="$ROUTE_4"
+EOF
+}
+
 if [ -n "$1" ]; then
-   . $CONFIG_DIR/$1
+    . $CONFIG_DIR/$1
 fi
 
- DHCP_MODULE_MESSAGE="The DHCP client you have chosen is not installed. Before your device will work, you will need to install the following module: "
+
+DHCP_MODULE_MESSAGE="The DHCP client you have chosen is not installed. Before your device will work, you will need to install the following module: "
 
 if [ -z $1 ]; then
      while [ -z $DEVICE ]; do
@@ -316,6 +353,12 @@ if [ -z $1 ]; then
            fi
          done
          DEVICE=`inputbox "For more then one device, use the menu for each of them, ie: eth0, eth1 etc.." "$TDEV"`
+     
+         # Generate a file immediately with some sane defaults
+         AUTO="Y"
+         ADDRESS="dhcp"
+         if_template
+         . $CONFIG_DIR/$DEVICE
      done
 else
 	 DEVICE=$1
@@ -351,22 +394,23 @@ while true ; do
 					echo "C"
 					echo "Dhcp client             [${DHCP_CLIENT:-dhcpcd}]"
 					echo "O"
-					echo "Dhcp options            [${DHCP_OPTIONS:--h \`hostname\`}]"
+					echo "Dhcp options            [${DHCP_OPTIONS}]"
 				  fi
 				  if [ "$ADDRESS" != "dhcp" ] ; then
 					echo "I"
-					echo "IP Address              [${ADDRESS:-10.0.0.1}]"
+					echo "IP Address              [${ADDRESS}]"
 					echo "N"
-					echo "Netmask                 [${NETMASK:-255.255.255.0}]"
+					echo "Netmask                 [${NETMASK}]"
 					echo "B"
-					echo "Broadcast               [${BROADCAST:-10.0.0.255}]"
+					echo "Broadcast               [${BROADCAST}]"
 					echo "F"
 					echo "Ifconfig options        [${IFCONF_OPTS:-}]"
 				  fi
-				 )`
+
+				  )`
 
 	if [ $? != 0 ]; then
-		return
+	    return
 	fi
 
 	case $CHOICE in
@@ -431,7 +475,7 @@ while true ; do
 			fi ;;
 		esac
 		;;
-	O)	DHCP_OPTIONS=`inputbox "Enter extra options passed to $DHCP_CLIENT" "${DHCP_OPTIONS:--h \`hostname\`}"`
+	O)	DHCP_OPTIONS=`inputbox "Enter extra options passed to $DHCP_CLIENT" "${DHCP_OPTIONS}"`
 		;;
 	I)	ADDRESS=`inputbox "Enter IP address" "$ADDRESS"`
 		;;
@@ -445,37 +489,7 @@ while true ; do
 
 	# save the config
 	cp -p $CONFIG_DIR/$DEVICE /tmp/lnet.$DEVICE
-	cat > $CONFIG_DIR/$DEVICE << EOF
-#
-# configuration for "$DEVICE"
-# automatically generated by lnet - do not edit, run 'lnet' instead
-# -- `date`
-#
-AUTO="$AUTO"
-MODULE="$MODULE"
-MODULE_OPTIONS="$MODULE_OPTIONS"
-
-MANAGER="$MANAGER"
-
-WIRELESS="$WIRELESS"
-WIRELESS_KEY="$WIRELESS_KEY"
-WIRELESS_RATE="$WIRELESS_RATE"
-WIRELESS_MODE="$WIRELESS_MODE"
-WIRELESS_ESSID="$WIRELESS_ESSID"
-
-ADDRESS="$ADDRESS"
-NETMASK="$NETMASK"
-BROADCAST="$BROADCAST"
-IFCONF_OPTS="$IFCONF_OPTS"
-
-DHCP_CLIENT="$DHCP_CLIENT"
-DHCP_OPTIONS="$DHCP_OPTIONS"
-
-ROUTE_1="$ROUTE_1"
-ROUTE_2="$ROUTE_2"
-ROUTE_3="$ROUTE_3"
-ROUTE_4="$ROUTE_4"
-EOF
+	if_template
 
 done
 }




More information about the Lunar-commits mailing list