udhcpc.script 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #!/bin/sh
  2. PATH=/bin:/usr/bin:/sbin:/usr/sbin
  3. RESOLV_CONF="/etc/resolv.conf"
  4. UDHCPC_INFO="/etc/udhcpc.info"
  5. update_interface()
  6. {
  7. [ -n "$broadcast" ] && BROADCAST="broadcast $broadcast"
  8. [ -n "$subnet" ] && NETMASK="netmask $subnet"
  9. /bin/ifconfig $interface $ip $BROADCAST $NETMASK
  10. }
  11. update_routes()
  12. {
  13. if [ -n "$router" ]
  14. then
  15. echo "deleting routes"
  16. while /bin/route del default gw 0.0.0.0 dev $interface > /dev/null 2>&1
  17. do :
  18. done
  19. for i in $router
  20. do
  21. /bin/route add default gw $i dev $interface
  22. done
  23. fi
  24. }
  25. update_dns()
  26. {
  27. echo -n > $RESOLV_CONF
  28. [ -n "$domain" ] && echo domain $domain >> $RESOLV_CONF
  29. for i in $dns
  30. do
  31. echo adding dns $i
  32. echo nameserver $i >> $RESOLV_CONF
  33. done
  34. }
  35. deconfig()
  36. {
  37. /bin/ifconfig $interface 0.0.0.0
  38. }
  39. update_udhcpc_info()
  40. {
  41. cat > $UDHCPC_INFO <<EOF
  42. HOSTNAME=$hostname
  43. INTERFACE=$interface
  44. IP=$ip
  45. BROADCAST=$broadcast
  46. NETMASK=$netmask
  47. ROOTPATH=$rootpath
  48. EOF
  49. }
  50. case "$1" in
  51. bound)
  52. update_interface;
  53. update_routes;
  54. update_dns;
  55. update_udhcpc_info;
  56. ;;
  57. renew)
  58. update_interface;
  59. update_routes;
  60. update_dns;
  61. update_udhcpc_info;
  62. ;;
  63. deconfig)
  64. deconfig;
  65. ;;
  66. *)
  67. echo "Usage: $0 {bound|renew|deconfig}"
  68. exit 1
  69. ;;
  70. esac
  71. exit 0