]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Install dhcpcd.sh and hooks into /libexec by default. dhcpcd.conf, dhcpcd.duid and...
authorRoy Marples <roy@marples.name>
Tue, 20 May 2008 12:23:29 +0000 (12:23 +0000)
committerRoy Marples <roy@marples.name>
Tue, 20 May 2008 12:23:29 +0000 (12:23 +0000)
13 files changed:
Makefile
README
client.c
config.h
dhcpcd.8.in
dhcpcd.c
dhcpcd.conf.5.in
dhcpcd.sh.8.in
dhcpcd.sh.in
hook.d/Makefile
mk/man.mk
mk/prog.mk
mk/scripts.mk

index 0a46c3b8163e385272042dbdc20417806c101430..3d186e793e89c65cc829bc9c5dcddaa6baf1bd8f 100644 (file)
--- 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 488ba0525a540d5e0c97780decea3d8f357f8fcf..1bf89108dcacf46ea5b6b148dab6a454eb1cafb1 100644 (file)
--- 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
index 1ef088685bcd4913680fa1b133637f03fcaa5695..c9858a63b182c51612fcfdcfa2692768d72ccc24 100644 (file)
--- 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;
index 4d9fe899235c8cdeec8fe8a1bcc563b481dedbf7..37deba5fb0b734ce746b946eda5661bdd4aee597 100644 (file)
--- 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
 # 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"
index d3a30fa1756a15e309f2e36fa71e9464b8262d44..c77827b45b27cddffd2998d5073236fda82f0e56 100644 (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.
index 92701094f8db45a0b07de1508fbfc68850a36f76..fd59e84b4f81e17158edc159e1c1bb4c7a140daf 100644 (file)
--- 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;
                }
index 53f8ea1301dcc8da837a93fb567c88ab6b785530..93c099dcbc9d6205727752a20bd36cd1d9f1acf8 100644 (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.
index 3568366741bf49ceb5206a77143b9d9ab815e81d..ace556e1b0fc1c00633c5224cb36f230788494c9 100644 (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
index 4715101a8512df4f177e879735e7b51953bb00d2..10ae50cd99e2aa7af6a0c8915d2d5b6aa1448996 100644 (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
index a0fd00c7d085cadb362db724d2d01ab53f133807..ced12df1f5554b808a9eee8d79674137de92dc7e 100644 (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
index 1b43611ba6f2f09e2f8597a9b1596fa7853813dd..58cd53b257989473fb9ecb37cfd7e38957a0294f 100644 (file)
--- a/mk/man.mk
+++ b/mk/man.mk
@@ -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
 
index 55896021fca9791ac3eb7444e2d079ba31f17100..5cfc128221aecc017496a5b1b300b56091ec621d 100644 (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
index ed2dca93e83a01c555b4e5720fbd9691d955ec5b..f9b66a985bd444dc9babe982284028b267da22b1 100644 (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}