examples/udhcp/simple.script: add possibility to use modern "ip"
authorJiří Prchal <jiri.prchal@aksignal.cz>
Thu, 4 Oct 2018 07:02:27 +0000 (09:02 +0200)
committerDenys Vlasenko <vda.linux@googlemail.com>
Tue, 30 Oct 2018 11:05:03 +0000 (12:05 +0100)
Script uses "ifconfig" only, not up-to-date so much.
This patch adds "ip" in condition if exists.

Signed-off-by: Jiří Prchal <jiri.prchal@aksignal.cz>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
examples/udhcp/simple.script

index e4c1f2d76429eadfb129f817838194aaf12cd785..44aa46ece63f86ec2fd3d5975acd0157e7e910bf 100755 (executable)
@@ -6,19 +6,31 @@ RESOLV_CONF="/etc/resolv.conf"
 [ -n "$1" ] || { echo "Error: should be called from udhcpc"; exit 1; }
 
 NETMASK=""
-[ -n "$subnet" ] && NETMASK="netmask $subnet"
+if command -v ip >/dev/null; then
+       [ -n "$subnet" ] && NETMASK="/$subnet"
+else
+       [ -n "$subnet" ] && NETMASK="netmask $subnet"
+fi
 BROADCAST="broadcast +"
 [ -n "$broadcast" ] && BROADCAST="broadcast $broadcast"
 
 case "$1" in
        deconfig)
                echo "Setting IP address 0.0.0.0 on $interface"
-               ifconfig $interface 0.0.0.0
+               if command -v ip >/dev/null; then
+                       ip addr flush dev $interface
+               else
+                       ifconfig $interface 0.0.0.0
+               fi
                ;;
 
        renew|bound)
                echo "Setting IP address $ip on $interface"
-               ifconfig $interface $ip $NETMASK $BROADCAST
+               if command -v ip >/dev/null; then
+                       ip addr add $ip$NETMASK $BROADCAST dev $interface
+               else
+                       ifconfig $interface $ip $NETMASK $BROADCAST
+               fi
 
                if [ -n "$router" ] ; then
                        echo "Deleting routers"