netcardconfig: fix variable assignment in awk cmdline
[grml-network.git] / sbin / netcardconfig
index 9312052..ba8d7bf 100755 (executable)
@@ -15,7 +15,7 @@ LANGUAGE=C LANG=C
 export PATH LANGUAGE LANG
 
 . /etc/grml/script-functions
-check4root
+check4root || exit 1
 
 TMP=$(mktemp)
 
@@ -156,6 +156,8 @@ configiface() {
   DEVICE=${NETDEVICES[$DV]}
   device2props
   DV=$DEVICENAME
+  ifdown $DV
+  sleep 3
   # wireless config
   WLDEVICE="$(LANG=C LC_MESSAGEWS=C iwconfig $DV 2>/dev/null | awk '/802\.11|READY|ESSID/{print $1}')"
   WLDEVICECOUNT="$(LANG=C LC_MESSAGEWS=C iwconfig $DV 2>/dev/null | wc -l)"
@@ -325,7 +327,13 @@ configiface() {
                           }
                   }
                   ' /etc/network/interfaces)
-          $DIALOG --inputbox "$MESSAGEW23 $ESSID" 15 50 "$WPASECRET" 2>"$TMP" || bailout 1
+          while [ -z "$WPASECRET" ] ; do
+            $DIALOG --inputbox "$MESSAGEW23 $ESSID" 15 50 "$WPASECRET" 2>"$TMP" || bailout 1
+            read WPASECRET <"$TMP"
+            if [ -z "$WPASECRET" ] ; then
+              $DIALOG --msgbox "Sorry, empty password not allowed, please retry." 0 0 || bailout 1
+            fi
+          done
 
           # make sure backslashes inside passphrase are handled correct
           WPASECRET=$(sed -e 's/\\/\\/g' "$TMP") && rm -r "$TMP"
@@ -389,8 +397,8 @@ configiface() {
         /netmask/{if(found){netmask=$NF}}
         /broadcast/{if(found){broadcast=$NF}}
         /gateway/{if(found){gateway=$NF}}
-        /dns-nameservers/{if(found){dns-nameservers=$NF}}
-        END{print address" "netmask" "broadcast" "gateway" "dns-nameservers}' /etc/network/interfaces >"$TMP"
+        /dns-nameservers/{if(found){dnsnameservers=$NF}}
+        END{print address" "netmask" "broadcast" "gateway" "dnsnameservers}' /etc/network/interfaces >"$TMP"
       read IP NM BC DG <"$TMP"
       rm -f "$TMP"
     fi
@@ -486,7 +494,14 @@ if [ -r /proc/net/dev ] ; then
 else
    LAN=""
 fi
-[ -n "$WLAN" ] || WLAN=$(tail -n +3 /proc/net/wireless 2>/dev/null|awk -F: '{print $1}'|sort)
+
+if [ -z "$WLAN" ] ; then
+  WLAN_OLD=$(tail -n +3 /proc/net/wireless 2>/dev/null|awk -F: '{print $1}')
+  # /proc/net/wireless does not work e.g. with iwl3945 on kernel 2.6.33 anymore
+  WLAN_NEW=$(for i in /sys/class/net/* ; do [ -d $i/wireless ] && basename $i ; done)
+  WLAN=$(echo $WLAN_OLD $WLAN_NEW | sort -u)
+fi
+
 unset LAN_DEVICES WLAN_DEVICES FIREWIRE_DEVICES NETDEVICES
 
 while read dev mac; do
@@ -565,8 +580,6 @@ while (true); do
   IFACEDONE=""
   while [ -n "$DV" -a -z "$IFACEDONE" ]; do
     configiface
-    ifdown $DV
-    sleep 3
     if ! ifup $DV; then
       $DIALOG --yesno "$MESSAGE14" 15 50 || IFACEDONE="DONE"
     else