Ámélioré détection link up/down script ifup
authorgobo72 <gobo72@364a67c3-989e-7be9-548d-dae8560ea662>
Sun, 13 Mar 2011 07:04:58 +0000 (07:04 +0000)
committergobo72 <gobo72@364a67c3-989e-7be9-548d-dae8560ea662>
Sun, 13 Mar 2011 07:04:58 +0000 (07:04 +0000)
stage2/bootscripts/ifup

index e31fd43..dd2683b 100755 (executable)
@@ -31,6 +31,25 @@ bring_if_up()
         if ! echo "${link_status}" | grep -q UP; then
             cmd_run_log ip link set ${DEVICE} up
         fi
+    else
+        echo "Interface ${DEVICE} not found"
+        exit ${EXIT_CODE_WARNING}
+    fi
+
+    # Check if a cable is plugged for wired interface
+    if [ ! -d /sys/class/net/${DEVICE}/wireless ]; then
+        count=0
+        while cat /sys/class/net/${DEVICE}/carrier | grep -q "0"; do
+            echo "Waiting for carrier to go up"
+            sleep 0.25
+
+            let count=count+1
+            # 2.5 seconds delay
+            if [ $count -gt 10 ]; then
+                echo "Interface ${DEVICE}: carrier not detected (cable unplugged?)"
+                exit ${EXIT_CODE_WARNING}
+            fi
+        done
     fi
 }
 
@@ -44,7 +63,7 @@ proto_static()
        if ip route | grep -q default; then
            msg_log "Gateway already setup; skipping."
        else
-           cmd_run_log_box "Adding default route to gateway ${GATEWAY}" \
+           cmd_run_log_box "Adding default route to gateway ${GATEWAY} via ${DEVICE}" \
                 ip route add default via ${GATEWAY} dev ${DEVICE}
        fi
     fi
@@ -53,6 +72,8 @@ proto_static()
 # Obtain IP address from DHCP
 proto_dhcp()
 {
+    bring_if_up
+
     # Load DHCP client parameters
     source /etc/sysconfig/network/dhcp-client
 
@@ -104,10 +125,10 @@ proto_wireless()
     count=0
     while ! wpa_cli -i ${DEVICE} status | grep "wpa_state=COMPLETED"; do
         echo "Waiting for wpa_supplicant to complete"
-        sleep 1
+        sleep 0.25
 
         let count=count+1
-        if [ $count -gt 10 ]; then
+        if [ $count -gt 20 ]; then
             echo "wpa_supplicant failure"
             exit ${EXIT_CODE_WARNING}
         fi
@@ -115,8 +136,8 @@ proto_wireless()
 }
 
 # Make sure interface is available
-if ! ip link show ${DEVICE} > /dev/null 2>&1; then
-    echo "Interface ${1} not found"
+if [ ! -d /sys/class/net/${DEVICE} ]; then
+    echo "Interface ${DEVICE} not found"
     exit ${EXIT_CODE_WARNING}
 fi