From 47839ae6797bcded0178893cb950d2e2f8be1f6f Mon Sep 17 00:00:00 2001 From: Jiří Prchal Date: Thu, 4 Oct 2018 09:02:27 +0200 Subject: examples/udhcp/simple.script: add possibility to use modern "ip" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Script uses "ifconfig" only, not up-to-date so much. This patch adds "ip" in condition if exists. Signed-off-by: Jiří Prchal Signed-off-by: Denys Vlasenko --- examples/udhcp/simple.script | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'examples') diff --git a/examples/udhcp/simple.script b/examples/udhcp/simple.script index e4c1f2d76..44aa46ece 100755 --- a/examples/udhcp/simple.script +++ b/examples/udhcp/simple.script @@ -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" -- cgit v1.2.3