CPPFLAGS+= -DDBDIR=\"${DBDIR}\"
LDADD+= ${LIBRT}
+SUBDIRS= hook.d
+
.SUFFIXES: .in .sh.in
.in:
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd May 12, 2008
+.Dd May 20, 2008
.Dt DHCPCD 8 SMM
.Sh NAME
.Nm dhcpcd
.Pa /etc/resolv.conf
and the
.Xr hostname 3
-if possible. It will also run custom hook scripts if defined. See
+if possible. You can customize its behaviour through hook scripts. See
.Xr dhcpcd.sh 8
for more details.
.Nm
-ignores the exit code of the script.
+currently ignores the exit code of the script.
.Ss Fine tuning
You can fine tune the behaviour of
.Nm
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd May 02, 2008
+.Dd May 20, 2008
.Dt DHCPCD.SH 8 SMM
.Sh NAME
.Nm dhcpcd.sh
.Nm
is used by
.Xr dhcpcd 8
-to configure
+to run any system or user defined hook scripts, which include configuring
.Pa /etc/resolv.conf
-and run any system or user defined hook scripts.
+and the hostname.
Each time
.Nm
is invoked,
for the script to process them.
.El
.Sh FILES
-Before
+When
.Nm
runs, it loads
-.Pa @SYSCONFDIR@/dhcpcd-enter-hook
+.Pa @SYSCONFDIR@/dhcpcd-hook
and any scripts found in
-.Pa @SYSCONFDIR@/dhcpcd-enter-hook.d .
-Then it runs itself, configuring
-.Pa /etc/resolv.conf .
-Finally it loads
-.Pa @SYSCONFDIR@/dhcpcd-exit-hook
-and any scripts found in
-.Pa @SYSCONFDIR@/dhcpcd-exit-hook.d .
+.Pa @SYSCONFDIR@/dhcpcd-hook.d
+in a lexical order.
.Sh SEE ALSO
.Xr dhcpcd 8
.Sh AUTHORS
#!/bin/sh
-# dhcpcd - DHCP client daemon
-# Copyright 2006-2008 Roy Marples <roy@marples.name>
-# All rights reserved
-
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-# 1. Redistributions of source code must retain the above copyright
-# notice, this list of conditions and the following disclaimer.
-# 2. Redistributions in binary form must reproduce the above copyright
-# notice, this list of conditions and the following disclaimer in the
-# documentation and/or other materials provided with the distribution.
-#
-# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
-# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-# SUCH DAMAGE.
-
-do_hooks()
-{
- local x= r=0
- for x in @SYSCONFDIR@/dhcpcd-"$1"-hook.d/* \
- @SYSCONFDIR@/dhcpcd-"$1"-hook \
- ; do
- if [ -e "${x}" ]; then
- . "${x}"
- r=$((${r} + $?))
- fi
- done
- return ${r}
-}
+# dhcpcd client configuration script
+# Handy functions for our hooks to use
+signature="# Generated by dhcpcd for ${interface}"
save_conf()
{
- if [ -e "$1" ]; then
+ if [ -f "$1" ]; then
rm -f "$1"-pre."${interface}"
mv -f "$1" "$1"-pre."${interface}"
fi
}
-
restore_conf()
{
- [ -e "$1"-pre."${interface}" ] || return 1
+ [ -f "$1"-pre."${interface}" ] || return 1
rm -f "$1"
mv -f "$1"-pre."${interface}" "$1"
}
-make_resolv_conf()
-{
- if [ -z "${new_domain_name_servers}" -a \
- -z "${new_domain_name}" -a \
- -z "${new_domain_search}" ]; then
- return 0
- fi
- local x= conf="${signature}\n"
- if [ -n "${new_domain_search}" ]; then
- conf="${conf}search ${new_domain_search}\n"
- elif [ -n "${new_domain_name}" ]; then
- conf="${conf}search ${new_domain_name}\n"
- fi
- for x in ${new_domain_name_servers}; do
- conf="${conf}nameserver ${x}\n"
- done
- if type resolvconf >/dev/null 2>&1; then
- printf "${conf}" | resolvconf -a "${interface}"
- else
- save_conf /etc/resolv.conf
- printf "${conf}" > /etc/resolv.conf
- fi
-}
-
-restore_resolv_conf()
-{
- if type resolvconf >/dev/null 2>&1; then
- resolvconf -d "${interface}" -f
- else
- restore_conf /etc/resolv.conf || return 0
+for hook in \
+ @SYSCONFDIR@/dhcpcd-hook \
+ @SYSCONFDIR@/dhcpcd-hook.d/* \
+do
+ if [ -f "${x}" ]; then
+ . "${x}"
fi
-}
-
-need_hostname()
-{
- case "$(hostname)" in
- ""|"(none)"|localhost) [ -n "${new_host_name}" ];;
- "${old_host_name}") true;;
- *) false;;
- esac
-}
-
-set_hostname()
-{
- if need_hostname; then
- hostname "${new_host_name}"
- fi
-}
-
-run_test()
-{
- env | grep "^\(interface\|pid\|reason\)="
- env | grep "^\(new_\|old_\)" | sort
-}
-
-signature="# Generated by dhcpcd for ${interface}"
-
-# We should do something with exit codes really
-do_hooks enter
-case "${reason}" in
- TEST)
- run_test
- ;;
- BOUND|INFORM|REBIND|REBOOT|RENEW|TIMEOUT)
- make_resolv_conf
- set_hostname
- ;;
- EXPIRE|FAIL|IPV4LL|RELEASE|STOP)
- restore_resolv_conf
- ;;
- *)
- echo "unsupported reason ${reason}" >&2
- false
- ;;
-esac
-do_hooks exit
+done
--- /dev/null
+# Just echo our DHCP options we have
+
+if [ "${reason}" = "TEST" ]; then
+ env | grep "^\(interface\|pid\|reason\)="
+ env | grep "^\(new_\|old_\)" | sort
+fi
--- /dev/null
+# Generate /etc/resolv.conf
+# Support resolvconf(8) if available
+
+make_resolv_conf()
+{
+ if [ -z "${new_domain_name_servers}" -a \
+ -z "${new_domain_name}" -a \
+ -z "${new_domain_search}" ]; then
+ return 0
+ fi
+ local x= conf="${signature}\n"
+ if [ -n "${new_domain_search}" ]; then
+ conf="${conf}search ${new_domain_search}\n"
+ elif [ -n "${new_domain_name}" ]; then
+ conf="${conf}search ${new_domain_name}\n"
+ fi
+ for x in ${new_domain_name_servers}; do
+ conf="${conf}nameserver ${x}\n"
+ done
+ if type resolvconf >/dev/null 2>&1; then
+ printf "${conf}" | resolvconf -a "${interface}"
+ else
+ save_conf /etc/resolv.conf
+ printf "${conf}" > /etc/resolv.conf
+ fi
+}
+
+restore_resolv_conf()
+{
+ if type resolvconf >/dev/null 2>&1; then
+ resolvconf -d "${interface}" -f
+ else
+ restore_conf /etc/resolv.conf || return 0
+ fi
+}
+
+case "${reason}" in
+ BOUND|INFORM|REBIND|REBOOT|RENEW|TIMEOUT) make_resolv_conf;;
+ EXPIRE|FAIL|IPV4LL|RELEASE|STOP) restore_resolv_conf;;
+esac
-# Sample exit hook to lookup the hostname in DNS if not set
+# Lookup the hostname in DNS if not set
lookup_hostname()
{
return 1
}
-do_hostname()
+set_hostname()
{
- if [ -z "${new_host_name}" ] && need_hostname; then
- local hname="$(lookup_hostname)"
- if [ -n "${hname}" ]; then
- hostname "${hname}"
- fi
+ if [ -z "${new_host_name}" ]
+ export new_host_name="$(lookup_hostname)"
fi
}
case "${reason}" in
- TEST)
- ;;
- BOUND|INFORM|REBIND|REBOOT|RENEW|TIMEOUT)
- do_hostname
- ;;
- EXPIRE|FAIL|IPV4LL|RELEASE|STOP)
- ;;
- *)
- echo "lookup_hostname: unsupported reason ${reason}" >&2
- false
- ;;
+ BOUND|INFORM|REBIND|REBOOT|RENEW|TIMEOUT) set_hostname;;
esac
--- /dev/null
+# Set the hostname from DHCP data if required
+
+need_hostname()
+{
+ case "$(hostname)" in
+ ""|"(none)"|localhost) [ -n "${new_host_name}" ];;
+ "${old_host_name}") true;;
+ *) false;;
+ esac
+}
+
+set_hostname()
+{
+ if need_hostname; then
+ hostname "${new_host_name}"
+ fi
+}
+
+case "${reason}" in
+ BOUND|INFORM|REBIND|REBOOT|RENEW|TIMEOUT) set_hostname;;
+esac
--- /dev/null
+SYSCONFDIR?= /etc/dhcpcd
+
+SYSTEMSCRIPTS= 01-test.sh 10-resolv.conf.sh 15-hostname.sh
+SCRIPTS= ${SYSTEMSCRIPTS} ${HOOKSCRIPTS}
+SCRIPTSDIR= ${SYSCONFDIR}/hook.d
+
+MK= ../mk
+include ${MK}/scripts.mk
+install: _scriptsinstall
FILESMODE?= ${NONBINMODE}
_filesinstall:
- ${INSTALL} -d ${DESTDIR}${FILESIR}
+ ${INSTALL} -d ${DESTDIR}${FILESDIR}
${INSTALL} -m ${FILESMODE} ${FILES} ${DESTDIR}${FILESDIR}
include ${MK}/cc.mk
include ${MK}/os.mk
+include ${MK}/sys.mk
-BINDIR?= ${PREFIX}/usr/bin
-BINMODE?= 0755
-NONBINMODE?= 0644
OBJS+= ${SRCS:.c=.o}
-SYSCONFDIR?= ${PREFIX}/etc
-
-INSTALL?= install
-SED?= sed
-
all: ${PROG} ${SCRIPTS} _man
.c.o:
include ${MK}/dist.mk
install: _proginstall _scriptsinstall _filesinstall _maninstall
+ for x in ${SUBDIRS}; do cd $$x; ${MAKE} $@; cd ..; done
clean:
rm -f ${OBJS} ${PROG} _${PROG}.c _${PROG}.o ${CLEANFILES}
# Quick and dirty scripts
# Copyright 2008 Roy Marples <roy@marples.name>
+include ${MK}/sys.mk
+
SCRIPTSDIR?= ${BINDIR}
SCRIPTSMODE?= ${BINMODE}
_scriptsinstall:
${INSTALL} -d ${DESTDIR}${SCRIPTSDIR}
- ${INSTALL} -m ${SCRIPTSMODE} ${SCRIPTS} ${DESTDIR}${FILESDIR}
+ ${INSTALL} -m ${SCRIPTSMODE} ${SCRIPTS} ${DESTDIR}${SCRIPTSDIR}
--- /dev/null
+# Simple defaults
+
+BINDIR?= ${PREFIX}/usr/bin
+BINMODE?= 0755
+NONBINMODE?= 0644
+
+SYSCONFDIR?= ${PREFIX}/etc
+
+INSTALL?= install
+SED?= sed