3
0

simple.script 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/bin/sh
  2. # udhcpc script edited by Tim Riker <Tim@Rikers.org>
  3. RESOLV_CONF="/etc/resolv.conf"
  4. [ -n "$1" ] || { echo "Error: should be called from udhcpc"; exit 1; }
  5. NETMASK=""
  6. [ -n "$subnet" ] && NETMASK="netmask $subnet"
  7. BROADCAST="broadcast +"
  8. [ -n "$broadcast" ] && BROADCAST="broadcast $broadcast"
  9. case "$1" in
  10. deconfig)
  11. echo "Setting IP address 0.0.0.0 on $interface"
  12. ifconfig $interface 0.0.0.0
  13. ;;
  14. renew|bound)
  15. echo "Setting IP address $ip on $interface"
  16. ifconfig $interface $ip $NETMASK $BROADCAST
  17. if [ -n "$router" ] ; then
  18. echo "Deleting routers"
  19. while route del default gw 0.0.0.0 dev $interface ; do
  20. :
  21. done
  22. metric=0
  23. for i in $router ; do
  24. echo "Adding router $i"
  25. route add default gw $i dev $interface metric $metric
  26. : $(( metric += 1 ))
  27. done
  28. fi
  29. echo "Recreating $RESOLV_CONF"
  30. # If the file is a symlink somewhere (like /etc/resolv.conf
  31. # pointing to /run/resolv.conf), make sure things work.
  32. realconf=$(readlink -f "$RESOLV_CONF" 2>/dev/null || echo "$RESOLV_CONF")
  33. tmpfile="$realconf-$$"
  34. > "$tmpfile"
  35. [ -n "$domain" ] && echo "search $domain" >> "$tmpfile"
  36. for i in $dns ; do
  37. echo " Adding DNS server $i"
  38. echo "nameserver $i" >> "$tmpfile"
  39. done
  40. mv "$tmpfile" "$realconf"
  41. ;;
  42. esac
  43. exit 0