aboutsummaryrefslogtreecommitdiff
path: root/sh/udhcpc-hook.sh.in
diff options
context:
space:
mode:
authorWilliam Hubbs <w.d.hubbs@gmail.com>2011-04-26 11:05:19 -0500
committerWilliam Hubbs <w.d.hubbs@gmail.com>2011-04-26 15:25:08 -0500
commitb712a9161f3d51566f44d48909776649d70116d0 (patch)
tree8f4c8dfa07da605e21242e142ab4f3dc929d6dc5 /sh/udhcpc-hook.sh.in
parent8202e7dce4065b79c272dc11941b371a9c4f99fc (diff)
change udhcpc support to busybox udhcpc
This updates the udhcpc support to use busybox's udhcpc instead of the stand alone version. I would like to thank jackieku <kjackie@gmail.com> for assisting with this update. X-Gentoo-Bug: 205286 X-Gentoo-Bug-URL: http://bugs.gentoo.org/show_bug.cgi?id=205286
Diffstat (limited to 'sh/udhcpc-hook.sh.in')
-rw-r--r--sh/udhcpc-hook.sh.in117
1 files changed, 117 insertions, 0 deletions
diff --git a/sh/udhcpc-hook.sh.in b/sh/udhcpc-hook.sh.in
new file mode 100644
index 00000000..a14cac99
--- /dev/null
+++ b/sh/udhcpc-hook.sh.in
@@ -0,0 +1,117 @@
+#!@SHELL@
+# busybox udhcp setup script
+
+PATH=/bin:/usr/bin:/sbin:/usr/sbin
+
+peer_var()
+{
+ [ -n "$1" ] && [ "$1" != "yes" ]
+}
+
+update_dns()
+{
+ peer_var "${PEER_DNS}" && return
+ [ -z "${domain}" ] && [ -z "${dns}" ] && return
+
+ conf="# Generated by udhcpc for ${interface}\n"
+ [ -n "${domain}" ] && conf="${conf}search ${domain}\n"
+ for i in ${dns} ; do
+ conf="${conf}nameserver ${i}\n"
+ done
+ if [ -x /sbin/resolvconf ] ; then
+ printf "${conf}" | resolvconf -a ${interface}
+ else
+ printf "${conf}" > /etc/resolv.conf
+ chmod 644 /etc/resolv.conf
+ fi
+}
+
+update_ntp()
+{
+ peer_var "${PEER_NTP}" && return
+ [ -z "${ntpsrv}" ] && return
+
+ conf="# Generated by udhcpc for interface ${interface}\n"
+ conf="${conf}restrict default noquery notrust nomodify\n"
+ conf="${conf}restrict 127.0.0.1\n"
+ for i in ${ntpsrv} ; do
+ conf="${conf}restrict ${i} nomodify notrap noquery\n"
+ conf="${conf}server ${i}\n"
+ done
+ conf="${conf}driftfile /var/lib/ntp/ntp.drift\n"
+ conf="${conf}logfile /var/log/ntp.log\n"
+ printf "${conf}" > /etc/ntp.conf
+ chmod 644 /etc/ntp.conf
+}
+
+update_hostname()
+{
+ peer_var "${PEER_HOSTNAME}" && return
+ [ -z "${hostname}" ] && return
+
+ myhost="$(hostname)"
+ [ -z "${myhost}" ] || [ "${myhost}" = "(none)" ] && hostname "${hostname}"
+}
+
+update_interface()
+{
+ [ -n "${broadcast}" ] && broadcast="broadcast ${broadcast}"
+ [ -n "${subnet}" ] && netmask="netmask ${subnet}"
+ [ -n "${mtu}" ] && mtu="mtu ${mtu}"
+ ifconfig "${interface}" ${ip} ${broadcast} ${netmask} ${mtu}
+}
+
+update_routes()
+{
+ peer_var "${PEER_ROUTERS}" && return
+
+ if [ -n "${router}" ] ; then
+ metric=
+ [ -n "${IF_METRIC}" ] && metric="metric ${IF_METRIC}"
+ for i in ${router} ; do
+ route add default gw "${i}" ${metric} dev "${interface}"
+ done
+ fi
+}
+
+deconfig()
+{
+ ifconfig "${interface}" 0.0.0.0
+
+ if ! peer_var "${PEER_ROUTERS}" ; then
+ while route del default dev "${interface}" >& /dev/null; do
+ :
+ done
+ fi
+
+ if ! peer_var "${PEER_DNS}" ; then
+ [ -x /sbin/resolvconf ] && resolvconf -d "${interface}"
+ fi
+}
+
+if [ -r "/var/run/udhcpc-${interface}.conf" ]; then
+ . "/var/run/udhcpc-${interface}.conf"
+fi
+
+case "$1" in
+ bound|renew)
+ update_hostname
+ update_interface
+ update_routes
+ update_dns
+ update_ntp
+ ;;
+ deconfig|leasefail)
+ deconfig
+ ;;
+ nak)
+ echo "nak: ${message}"
+ ;;
+ *)
+ echo "unknown option $1" >&2
+ echo "Usage: $0 {bound|deconfig|leasefail|nak|renew}" >&2
+ exit 1
+ ;;
+esac
+
+exit 0