From cfb1f0da771b720ae08f4ea728fce218db1fd367 Mon Sep 17 00:00:00 2001 From: Roy Marples Date: Fri, 9 Oct 2009 13:12:20 +0000 Subject: [PATCH] Add new hook, 50-ypbind for BSD ypbind versions. configure now detects ntpd and ypbind for automatic hook install. --- README | 6 +++++ configure | 45 +++++++++++++++++++++++++++++++-- dhcpcd-hooks/50-ypbind | 56 ++++++++++++++++++++++++++++++++++++++++++ dhcpcd-hooks/Makefile | 3 ++- 4 files changed, 107 insertions(+), 3 deletions(-) create mode 100644 dhcpcd-hooks/50-ypbind diff --git a/README b/README index 94278884..0e90f032 100644 --- 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 diff --git a/configure b/configure index 5430bf29..82570fe7 100755 --- 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 index 00000000..44f5bb17 --- /dev/null +++ b/dhcpcd-hooks/50-ypbind @@ -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 diff --git a/dhcpcd-hooks/Makefile b/dhcpcd-hooks/Makefile index fc6a3171..42058b10 100644 --- a/dhcpcd-hooks/Makefile +++ b/dhcpcd-hooks/Makefile @@ -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 + -- 2.47.3