From: Roy Marples Date: Tue, 20 May 2008 12:23:29 +0000 (+0000) Subject: Install dhcpcd.sh and hooks into /libexec by default. dhcpcd.conf, dhcpcd.duid and... X-Git-Tag: v4.0.2~370 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0aeb350cfa645e333dbbc353064408e81ba8c93c;p=thirdparty%2Fdhcpcd.git Install dhcpcd.sh and hooks into /libexec by default. dhcpcd.conf, dhcpcd.duid and dhcpcd.hook are now in /etc. --- diff --git a/Makefile b/Makefile index 0a46c3b8..3d186e79 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/README b/README index 488ba052..1bf89108 100644 --- a/README +++ b/README @@ -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 diff --git a/client.c b/client.c index 1ef08868..c9858a63 100644 --- a/client.c +++ b/client.c @@ -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; diff --git a/config.h b/config.h index 4d9fe899..37deba5f 100644 --- a/config.h +++ b/config.h @@ -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" diff --git a/dhcpcd.8.in b/dhcpcd.8.in index d3a30fa1..c77827b4 100644 --- a/dhcpcd.8.in +++ b/dhcpcd.8.in @@ -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. diff --git a/dhcpcd.c b/dhcpcd.c index 92701094..fd59e84b 100644 --- a/dhcpcd.c +++ b/dhcpcd.c @@ -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; } diff --git a/dhcpcd.conf.5.in b/dhcpcd.conf.5.in index 53f8ea13..93c099dc 100644 --- a/dhcpcd.conf.5.in +++ b/dhcpcd.conf.5.in @@ -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. diff --git a/dhcpcd.sh.8.in b/dhcpcd.sh.8.in index 35683667..ace556e1 100644 --- a/dhcpcd.sh.8.in +++ b/dhcpcd.sh.8.in @@ -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 diff --git a/dhcpcd.sh.in b/dhcpcd.sh.in index 4715101a..10ae50cd 100644 --- a/dhcpcd.sh.in +++ b/dhcpcd.sh.in @@ -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 diff --git a/hook.d/Makefile b/hook.d/Makefile index a0fd00c7..ced12df1 100644 --- a/hook.d/Makefile +++ b/hook.d/Makefile @@ -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 diff --git a/mk/man.mk b/mk/man.mk index 1b43611b..58cd53b2 100644 --- a/mk/man.mk +++ b/mk/man.mk @@ -1,7 +1,10 @@ # rules to install manpages # Copyright 2008 Roy Marples -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 diff --git a/mk/prog.mk b/mk/prog.mk index 55896021..5cfc1282 100644 --- a/mk/prog.mk +++ b/mk/prog.mk @@ -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 diff --git a/mk/scripts.mk b/mk/scripts.mk index ed2dca93..f9b66a98 100644 --- a/mk/scripts.mk +++ b/mk/scripts.mk @@ -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}