2002-10-14 21:41:28 +00:00
|
|
|
#!/bin/sh
|
|
|
|
# udhcpc script edited by Tim Riker <Tim@Rikers.org>
|
|
|
|
|
|
|
|
RESOLV_CONF="/etc/resolv.conf"
|
2009-04-21 00:17:00 +00:00
|
|
|
|
2009-05-10 21:27:43 +00:00
|
|
|
[ -n "$1" ] || { echo "Error: should be called from udhcpc"; exit 1; }
|
2009-04-21 00:17:00 +00:00
|
|
|
|
2009-04-16 20:04:09 +00:00
|
|
|
NETMASK=""
|
2002-10-14 21:41:28 +00:00
|
|
|
[ -n "$subnet" ] && NETMASK="netmask $subnet"
|
2009-04-16 20:04:09 +00:00
|
|
|
BROADCAST="broadcast +"
|
|
|
|
[ -n "$broadcast" ] && BROADCAST="broadcast $broadcast"
|
2002-10-14 21:41:28 +00:00
|
|
|
|
|
|
|
case "$1" in
|
|
|
|
deconfig)
|
2009-04-16 20:04:09 +00:00
|
|
|
echo "Setting IP address 0.0.0.0 on $interface"
|
|
|
|
ifconfig $interface 0.0.0.0
|
2002-10-14 21:41:28 +00:00
|
|
|
;;
|
|
|
|
|
|
|
|
renew|bound)
|
2009-04-16 20:04:09 +00:00
|
|
|
echo "Setting IP address $ip on $interface"
|
|
|
|
ifconfig $interface $ip $NETMASK $BROADCAST
|
2002-10-14 21:41:28 +00:00
|
|
|
|
|
|
|
if [ -n "$router" ] ; then
|
2009-04-16 20:04:09 +00:00
|
|
|
echo "Deleting routers"
|
2002-10-14 21:41:28 +00:00
|
|
|
while route del default gw 0.0.0.0 dev $interface ; do
|
|
|
|
:
|
|
|
|
done
|
|
|
|
|
2004-10-13 07:18:05 +00:00
|
|
|
metric=0
|
2002-10-14 21:41:28 +00:00
|
|
|
for i in $router ; do
|
2009-04-16 20:04:09 +00:00
|
|
|
echo "Adding router $i"
|
2013-02-27 06:05:34 +00:00
|
|
|
route add default gw $i dev $interface metric $metric
|
|
|
|
: $(( metric += 1 ))
|
2002-10-14 21:41:28 +00:00
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
2009-04-16 20:04:09 +00:00
|
|
|
echo "Recreating $RESOLV_CONF"
|
2013-02-27 06:01:43 +00:00
|
|
|
# If the file is a symlink somewhere (like /etc/resolv.conf
|
|
|
|
# pointing to /run/resolv.conf), make sure things work.
|
2013-03-12 14:48:09 +00:00
|
|
|
realconf=$(readlink -f "$RESOLV_CONF" 2>/dev/null || echo "$RESOLV_CONF")
|
2013-02-27 06:01:43 +00:00
|
|
|
tmpfile="$realconf-$$"
|
|
|
|
> "$tmpfile"
|
|
|
|
[ -n "$domain" ] && echo "search $domain" >> "$tmpfile"
|
2002-10-14 21:41:28 +00:00
|
|
|
for i in $dns ; do
|
2009-04-16 20:04:09 +00:00
|
|
|
echo " Adding DNS server $i"
|
2013-02-27 06:01:43 +00:00
|
|
|
echo "nameserver $i" >> "$tmpfile"
|
2002-10-14 21:41:28 +00:00
|
|
|
done
|
2013-02-27 06:01:43 +00:00
|
|
|
mv "$tmpfile" "$realconf"
|
2002-10-14 21:41:28 +00:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
exit 0
|