Install dhcpcd.sh and hooks into /libexec by default. dhcpcd.conf, dhcpcd.duid and dhcpcd.hook are now in /etc.

This commit is contained in:
Roy Marples 2008-05-20 12:23:29 +00:00
parent c61c4118d8
commit 0aeb350cfa
13 changed files with 63 additions and 36 deletions

View File

@ -7,32 +7,43 @@ SRCS= common.c dhcp.c dhcpcd.c logger.c net.c signals.c
SRCS+= configure.c client.c
SRCS+= ${SRC_IF} ${SRC_SOCKET}
CONFIG= ${SYSCONFDIR}/dhcpcd.conf
SCRIPTDIR= ${PREFIX}/libexec
SCRIPT= ${SCRIPTDIR}/dhcpcd.sh
HOOKDIR= ${SCRIPTDIR}/dhcpcd.hook.d
BINDIR= ${PREFIX}/sbin
SYSCONFDIR?= ${PREFIX}/etc/dhcpcd
SYSCONFDIR?= ${PREFIX}/etc
MAN= dhcpcd.conf.5 dhcpcd.8 dhcpcd.sh.8
CLEANFILES= dhcpcd.conf.5 dhcpcd.8 dhcpcd.sh.8
SCRIPTS= dhcpcd.sh
SCRIPTSDIR= ${SYSCONFDIR}
SCRIPTSDIR= ${SCRIPTDIR}
CLEANFILES+= dhcpcd.sh
FILES= dhcpcd.conf
FILESDIR= ${SYSCONFDIR}
CPPFLAGS+= -DSYSCONFDIR=\"${SYSCONFDIR}\"
CPPFLAGS+= -DDBDIR=\"${DBDIR}\"
CPPFLAGS+= -DCONFIG=\"${CONFIG}\"
CPPFLAGS+= -DSCRIPT=\"${SCRIPT}\"
LDADD+= ${LIBRT}
SUBDIRS= hook.d
.SUFFIXES: .in .sh.in
SED_DBDIR= -e 's:@DBDIR@:${DBDIR}:g'
SED_HOOKDIR= -e 's:@HOOKDIR@:${HOOKDIR}:g'
SED_SCRIPT= -e 's:@SCRIPT@:${SCRIPT}:g'
SED_SYS= -e 's:@SYSCONFDIR@:${SYSCONFDIR}:g'
.in:
${SED} 's:@SYSCONFDIR@:${SYSCONFDIR}:g; s:@DBDIR@:${DBDIR}:g' $< > $@
${SED} ${SED_DBDIR} ${SED_HOOKDIR} ${SED_SCRIPT} ${SED_SYS} $< > $@
.sh.in.sh:
${SED} 's:@SYSCONFDIR@:${SYSCONFDIR}:g' $< > $@
${SED} ${SED_HOOKDIR} ${SED_SCRIPT} ${SED_SYS} $< > $@
MK= mk
include ${MK}/prog.mk

7
README
View File

@ -31,9 +31,10 @@ set CSTD=gnu99 to work around this.
Hooks
-----
We provide example exit hooks for looking up the hostname in DNS,
NTP (www.ntp.org) and ypbind (Linux).
There are not installed by default as they are platform dependant.
Not all the hooks in hook.d are installed by default.
By default we install 01-test.sh, 10-resolv.conf.sh and 15-hostname.sh.
To add more simply add them in the HOOKSCRIPTS variable.
make HOOKSCRIPTS=50-ntp.sh install
Compatibility

View File

@ -238,7 +238,7 @@ get_duid(unsigned char *duid, const struct interface *iface)
/* If we already have a DUID then use it as it's never supposed
* to change once we have one even if the interfaces do */
if ((f = fopen(DUIDFILE, "r"))) {
if ((f = fopen(DUID, "r"))) {
while ((get_line(&buffer, &len, f))) {
line = buffer;
while ((option = strsep(&line, " \t")))
@ -263,7 +263,7 @@ get_duid(unsigned char *duid, const struct interface *iface)
}
/* No file? OK, lets make one based on our interface */
if (!(f = fopen(DUIDFILE, "w")))
if (!(f = fopen(DUID, "w")))
return 0;
type = htons(1); /* DUI-D-LLT */
@ -293,7 +293,7 @@ get_duid(unsigned char *duid, const struct interface *iface)
/* Failed to write the duid? scrub it, we cannot use it */
if (x < 1) {
len = 0;
unlink(DUIDFILE);
unlink(DUID);
}
return len;

View File

@ -63,6 +63,9 @@
#ifndef SYSCONFDIR
# define SYSCONFDIR "/etc/" PACKAGE
#endif
#ifndef LIBEXECDIR
# define LIBEXECDIR "/libexec"
#endif
#ifndef RUNDIR
# define RUNDIR "/var/run"
#endif
@ -70,14 +73,14 @@
# define DBDIR "/var/db"
#endif
#ifndef CONFIGFILE
# define CONFIGFILE SYSCONFDIR "/" PACKAGE ".conf"
#ifndef CONFIG
# define CONFIG SYSCONFDIR "/" PACKAGE ".conf"
#endif
#ifndef SCRIPT
# define SCRIPT SYSCONFDIR "/" PACKAGE ".sh"
# define SCRIPT LIBEXECDIR "/" PACKAGE ".sh"
#endif
#ifndef DUIDFILE
# define DUIDFILE SYSCONFDIR "/" PACKAGE ".duid"
#ifndef DUID
# define DUID SYSCONFDIR "/" PACKAGE ".duid"
#endif
#ifndef LEASEFILE
# define LEASEFILE DBDIR "/" PACKAGE "-%s.lease"

View File

@ -102,7 +102,7 @@ can use the
option.
.Ss Hooking into DHCP events
.Nm
will run @SYSCONFDIR@/dhcpcd.sh, or the script specified by the
will run @SCRIPT@, or the script specified by the
.Fl c , -script
option. This script will configure
.Pa /etc/resolv.conf
@ -172,7 +172,7 @@ different interfaces, the lower the metric the more it is preferred.
Request the DHCP
.Ar option
variable for use in
.Pa @SYSCONFDIR@/dhcpcd.sh .
.Pa @SCRIPT@ .
.It Fl n , -renew
Notifies an existing
.Nm
@ -271,7 +271,7 @@ Don't request the specified option. If no option given, then don't request
any options other than those to configure the interface and routing.
.It Fl T, -test
On receipt of discover messages we just call
.Pa @SYSCONFDIR@/dhcpcd.sh
.Pa @SCRIPT@
with the reason of TEST which echo's the DHCP variables found in the message
to the console. The interface configuration isn't touched and neither are any
configuration files.
@ -285,7 +285,7 @@ requires a Berkley Packet Filter, or BPF device on BSD based systems and a
Linux Socket Filter, or LPF device on Linux based systems.
.Sh FILES
.Bl -ohang
.It Pa @SYSCONFDIR@/dhcpcd.sh
.It Pa @SCRIPT@
Bourne shell script that is run when we configure or deconfigure an interface.
.It Pa @SYSCONFDIR@/dhcpcd.duid
Text file that holds the DUID used to identify the host.

View File

@ -421,7 +421,7 @@ main(int argc, char **argv)
/* If the duid file exists, then enable duid by default
* This means we don't break existing clients that easily :) */
# ifdef ENABLE_DUID
if ((f = fopen(DUIDFILE, "r"))) {
if ((f = fopen(DUID, "r"))) {
options->options |= DHCPCD_DUID;
fclose(f);
}
@ -497,7 +497,7 @@ main(int argc, char **argv)
}
/* Parse our options file */
f = fopen(cf ? cf : CONFIGFILE, "r");
f = fopen(cf ? cf : CONFIG, "r");
if (f) {
r = 1;
while ((get_line(&buffer, &len, f))) {
@ -567,7 +567,7 @@ main(int argc, char **argv)
goto abort;
} else {
if (errno != ENOENT || cf) {
logger(LOG_ERR, "fopen `%s': %s", cf ? cf : CONFIGFILE,
logger(LOG_ERR, "fopen `%s': %s", cf ? cf : CONFIG,
strerror(errno));
goto abort;
}

View File

@ -22,7 +22,7 @@
.\" 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.CONF 5 SMM
.Sh NAME
.Nm dhcpcd.conf
@ -95,6 +95,11 @@ from the server. It can be a variable to be used in
.Xr dhcpcd.sh 8
or the numerical value. You can specify more seperated by commas, spaces or
more option lines.
.It Ic script Ar script
Use
.Ar script
instead of the default
.Pa @SCRIPT@ .
.It Ic timeout Ar seconds
The default timeout for waiting for a DHCP response is 20 seconds which may
be too long or too short and can be changed here.

View File

@ -81,9 +81,9 @@ for the script to process them.
When
.Nm
runs, it loads
.Pa @SYSCONFDIR@/dhcpcd-hook
.Pa @SYSCONFDIR@/dhcpcd.hook
and any scripts found in
.Pa @SYSCONFDIR@/dhcpcd-hook.d
.Pa @HOOKDIR@
in a lexical order.
.Sh SEE ALSO
.Xr dhcpcd 8

View File

@ -17,11 +17,15 @@ restore_conf()
mv -f "$1"-pre."${interface}" "$1"
}
# We source each script into this one so that scripts run earlier can
# remove variables from the environment so later scripts don't see them.
# Thus, the user can create their dhcpcd.hook script to configure
# /etc/resolv.conf how they want and stop the system scripts ever updating it.
for hook in \
@SYSCONFDIR@/dhcpcd-hook \
@SYSCONFDIR@/dhcpcd-hook.d/* \
@SYSCONFDIR@/dhcpcd.hook \
@HOOKDIR@/*
do
if [ -f "${x}" ]; then
. "${x}"
if [ -f "${hook}" ]; then
. "${hook}"
fi
done

View File

@ -1,8 +1,8 @@
SYSCONFDIR?= /etc/dhcpcd
SCRIPTDIR?= ${PREFIX}/libexec
HOOKDIR?= ${SCRIPTDIR}/dhcpcd.hook.d
SYSTEMSCRIPTS= 01-test.sh 10-resolv.conf.sh 15-hostname.sh
SCRIPTS= ${SYSTEMSCRIPTS} ${HOOKSCRIPTS}
SCRIPTSDIR= ${SYSCONFDIR}/hook.d
SCRIPTSDIR= ${HOOKDIR}
MK= ../mk
include ${MK}/scripts.mk

View File

@ -1,7 +1,10 @@
# rules to install manpages
# Copyright 2008 Roy Marples <roy@marples.name>
MANPREFIX?= /usr/share
_MANPREFIX_SH= if [ -n "${PREFIX}" ]; then echo "${PREFIX}"; else echo "/usr/share"; fi
_MANPREFIX!= ${_MANPREFIX_SH}
MANPREFIX?= ${_MANPREFIX}$(shell ${_MANPREFIX_SH})
MANDIR?= ${MANPREFIX}/man/man
MANMODE?= 0444

View File

@ -28,7 +28,7 @@ small: ${SRCS}
_proginstall: ${PROG}
${INSTALL} -d ${DESTDIR}${BINDIR}
${INSTALL} -m ${BINMODE} ${PROG} ${DESTDIR}${BINDIR}
${INSTALL} -d ${DESTDIR}${INFODIR}
${INSTALL} -d ${DESTDIR}${DBDIR}
include ${MK}/depend.mk
include ${MK}/files.mk

View File

@ -6,6 +6,6 @@ include ${MK}/sys.mk
SCRIPTSDIR?= ${BINDIR}
SCRIPTSMODE?= ${BINMODE}
_scriptsinstall:
_scriptsinstall: ${SCRIPTS}
${INSTALL} -d ${DESTDIR}${SCRIPTSDIR}
${INSTALL} -m ${SCRIPTSMODE} ${SCRIPTS} ${DESTDIR}${SCRIPTSDIR}