]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Add new hook, 50-ypbind for BSD ypbind versions.
authorRoy Marples <roy@marples.name>
Fri, 9 Oct 2009 13:12:20 +0000 (13:12 +0000)
committerRoy Marples <roy@marples.name>
Fri, 9 Oct 2009 13:12:20 +0000 (13:12 +0000)
configure now detects ntpd and ypbind for automatic hook install.

README
configure
dhcpcd-hooks/50-ypbind [new file with mode: 0644]
dhcpcd-hooks/Makefile

diff --git a/README b/README
index 94278884135c385296c6e3348c3d70614554abc9..0e90f032b1642a2d84f12907e089d966a905bdda 100644 (file)
--- a/README
+++ b/README
@@ -39,12 +39,18 @@ BSD systems where this has been fixed are:
     NetBSD-5.0
 
 
+To prepare dhcpcd for import into a platform source tree (like NetBSD)
+you can use the make import target to create /tmp/dhcpcd-$version and
+populate it with all the source files and hooks needed.
+
+
 Hooks
 -----
 Not all the hooks in dhcpcd-hooks are installed by default.
 By default we install 01-test, 10-mtu, 20-resolv.conf,
 29-lookup-hostname and 30-hostname.
 The default dhcpcd.conf disables the lookup-hostname hook by default.
+The configure program attempts to find hooks for systems you have installed.
 To add more simply
 ./configure -with-hook=ntp.conf
 
index 5430bf29f5a6a9d74e09d41141a5352460bc8576..82570fe7b6a42d22e58d463bc61e1bcd2beb2f6e 100755 (executable)
--- a/configure
+++ b/configure
@@ -48,6 +48,24 @@ done
 : ${RUNDIR:=$STATEDIR/run}
 : ${MANDIR:=${PREFIX:-/usr}/share/man}
 
+_which()
+{
+       x="$(which "$1" 2>/dev/null)"
+       if [ -n "$x" ]; then
+               echo "$x"
+               return 0
+       fi
+       for x in /sbin/"$1" /usr/sbin/"$1" \
+               /usr/pkg/sbin/"$1" /usr/local/sbin/"$1"
+       do
+               if [ -e "$x" ]; then
+                       echo "$x"
+                       return 0
+               fi
+       done
+       return 1
+}
+
 CONFIG_H=config.h
 CONFIG_MK=config.mk
 
@@ -266,8 +284,31 @@ else
 fi
 rm -f _strlcpy.c _strlcpy
 
-cd dhcpcd-hooks
 HOOKS=
+printf "Checking for ntpd ... "
+NTPD=$(_which ntpd)
+if [ -n "$NTPD" ]; then
+       echo "$NTPD (50-ntp.conf)"
+       HOOKS="$HOOKS${HOOKS:+ }50-ntp.conf"
+else
+       echo "not found"
+fi
+
+printf "Checking for ypind ... "
+YPBIND=$(_which ypbind)
+if [ -n "$YPBIND" ]; then
+       if strings "$YPBIND" | grep -q yp.conf; then
+               YPHOOK="50-yp.conf"
+       else
+               YPHOOK="50-ypbind"
+       fi
+       echo "$YPBIND ($YPHOOK)"
+       HOOKS="$HOOKS${HOOKS:+ }$YPHOOK"
+else
+       echo "not found"
+fi
+
+cd dhcpcd-hooks
 for x in $HOOKSCRIPTS; do
        printf "Finding hook $x ... "
        for h in [0-9][0-9]"-$x" [0-9][0-9]"-$x.sh" [0-9][0-9]"-$x.conf"; do
@@ -291,5 +332,5 @@ echo "   LIBEXECDIR =               $LIBEXECDIR"
 echo "   DBDIR =               $DBDIR"
 echo "   RUNDIR =              $RUNDIR"
 echo "   MANDIR =              $MANDIR"
-echo "   HOOKSCRIPTS = $HOOKSCRIPTS"
+echo "   HOOKSCRIPTS = $HOOKS"
 echo
diff --git a/dhcpcd-hooks/50-ypbind b/dhcpcd-hooks/50-ypbind
new file mode 100644 (file)
index 0000000..44f5bb1
--- /dev/null
@@ -0,0 +1,56 @@
+# Sample dhcpcd hook for ypbind
+# This script is only suitable for the Linux version.
+
+# Distributions may want to just have their command here instead of this
+if [ -x /etc/rc.d/ypbind ]; then
+       ypbind_restart_cmd="/etc/rc.d/ypbind restart"
+elif [ -x /usr/local/etc/rc.d/ypbind ]; then
+       ypbind_restart_cmd="/usr/local/etc/rc.d/ypbind restart"
+fi
+
+make_yp_binding()
+{
+       [ -z "$new_nis_domain" ] && return
+
+       local cf=/var/yp/binding/"$new_nis_domain".ypservers
+       if [ -n "$new_nis_servers" ]; then
+               local ncf="$cf.$interface" x=
+               rm -f "$ncf"
+               for x in $new_nis_servers; do
+                       echo "$x" >> "$ncf"
+               done
+               if change_file "$cf" "$ncf"; then
+                       if [ -n "$ypbind_restart_cmd" ]; then
+                               eval $ypbind_restart_cmd
+                       fi
+               fi
+       else
+               if [ -e "$cf" ]; then
+                       rm "$cf"
+                       if [ -n "$ypbind_restart_cmd" ]; then
+                               eval $ypbind_restart_cmd
+                       fi
+               fi
+       fi
+}
+
+restore_yp_binding()
+{
+       [ -z "$old_nis_domain" ] && return
+
+       if restore_conf /var/yp/binding/"$old_nis_domain".ypservers; then
+               if [ -n "$ypbind_restart_cmd" ]; then
+                       eval $ypbind_restart_cmd
+               fi
+       elif [ -e /var/yp/binding/"$old_nis_domain".ypservers ]; then
+               rm /var/yp/binding/"$old_nis_domain".ypservers
+               if [ -n "$ypbind_restart_cmd" ]; then
+                       eval $ypbind_restart_cmd
+               fi
+       fi
+}
+
+case "$reason" in
+BOUND|INFORM|REBIND|REBOOT|RENEW|TIMEOUT|STATIC)       make_yp_binding;;
+EXPIRE|FAIL|IPV4LL|NAK|NOCARRIER|RELEASE|STOP)         restore_yp_binding;;
+esac
index fc6a31719e164998a28dc3fb3749bbc4547f82a7..42058b10590fc317cb75e9161e8f2523fc73a304 100644 (file)
@@ -14,4 +14,5 @@ install:
 
 import:
        ${INSTALL} -d /tmp/${DISTPREFIX}/dhcpcd-hooks
-       cp ${SCRIPTS} 50-ntp.conf /tmp/${DISTPREFIX}/dhcpcd-hooks
+       ${INSTALL} -m ${NONBINMODE} ${SCRIPTS} /tmp/${DISTPREFIX}/dhcpcd-hooks
+