Add some extra knobs so that it slides into the FreeBSD file layout.
authorRoy Marples <roy@marples.name>
Fri, 9 Nov 2007 11:04:51 +0000 (11:04 +0000)
committerRoy Marples <roy@marples.name>
Fri, 9 Nov 2007 11:04:51 +0000 (11:04 +0000)
Makefile
libc
resolvconf

index 21406c2056fa15e1e36e86a94c566b7a8995c171..d0ae99fa272b73f5c5e260ae3b293d5e5ad98ab4 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,19 +1,29 @@
+DESTDIR =
+PREFIX = /
+ROOT = $(DESTDIR)$(PREFIX)
 INSTALL = install 
 ETCDIR = $(ROOT)/etc/resolvconf
-MANDIR = $(ROOT)/usr/share/man/man8
+SHAREDIR = $(ROOT)/usr/share/man
+MANDIR = $(SHAREDIR)/man8
 BINDIR = $(ROOT)/sbin
-VARDIR = $(ROOT)/var/run
+VARDIR = $(DESTDIR)/var/run
+UPDATEDIR = $(ETCDIR)/update.d
 
 default:
 
 install:
        $(INSTALL) -d $(ETCDIR)/resolv.conf.d
-       $(INSTALL) -d $(ETCDIR)/update.d
+       $(INSTALL) -d $(UPDATEDIR)
        $(INSTALL) -d $(ETCDIR)/update-libc.d
        $(INSTALL) -d $(MANDIR)
        $(INSTALL) -d $(BINDIR)
        $(INSTALL) -d $(VARDIR)/resolvconf
        $(INSTALL) resolvconf $(BINDIR)
-       $(INSTALL) libc $(ETCDIR)/update.d
+       $(INSTALL) libc $(UPDATEDIR)
+       if test "$(PREFIX)" "!=" "/"; then \
+               for x in $(BINDIR)/resolvconf $(UPDATEDIR)/libc; do \
+               sed -i.bak -e s':^PREFIX=.*:PREFIX="$(PREFIX)":' "$$x"; rm "$$x".bak; \
+               done; \
+               fi;
        $(INSTALL) -m 644 resolvconf.8 $(MANDIR)
-       ln -snf ../../var/run/resolvconf $(ETCDIR)/run
+       ln -snf /var/run/resolvconf $(ETCDIR)/run
diff --git a/libc b/libc
index 022d38a355da3689b0b58d62c603bce52be8f594..47e25cc229c89984f43f36e29d7e9d8e58616f12 100755 (executable)
--- a/libc
+++ b/libc
@@ -1,5 +1,6 @@
 #!/bin/sh
 # Copyright 2006 Gentoo Foundation
+# Copyright 2007 Roy Marples
 # Distributed under the terms of the GNU General Public License v2
 
 # libc resolv.conf updater
@@ -7,15 +8,14 @@
 # Written by Roy Marples (uberlord@gentoo.org)
 # Heavily based on Debian resolvconf by Thomas Hood
 
-[ "$(readlink /etc/resolv.conf 2>/dev/null)" \
-       != "resolvconf/run/resolv.conf" ] && exit 0
-
-RESOLVCONF="$(resolvconf -l)"
-BASE="/etc/resolvconf/resolv.conf.d/base"
+PREFIX=
+RESOLVCONF="${PREFIX}"/etc/resolvconf
+RESOLVCONFS="$(resolvconf -l)"
+BASE="${RESOLVCONF}/resolv.conf.d/base"
 
 uniqify() {
     local result=
-    while [ -n "$1" ] ; do
+    while [ -n "$1" ]; do
                case " ${result} " in
                        *" $1 "*) ;;
                        *) result="${result} $1" ;;
@@ -26,12 +26,12 @@ uniqify() {
 }
 
 OUR_NS=
-if [ -e "${BASE}" ] ; then
+if [ -e "${BASE}" ]; then
        OUR_NS="$(sed -n -e 's/^[[:space:]]*nameserver[[:space:]]*//p' "${BASE}")"
 fi
 OUR_NS="$(uniqify \
        ${OUR_NS} \
-       $(echo "${RESOLVCONF}" \
+       $(echo "${RESOLVCONFS}" \
        | sed -n -e 's/^[[:space:]]*nameserver[[:space:]]*//p') \
 )"
 
@@ -40,7 +40,7 @@ OUR_NS="$(uniqify \
 i=0
 NS=
 LOCALH=false
-for N in ${OUR_NS} ; do
+for N in ${OUR_NS}; do
        i=$((${i} + 1))
        NS="${NS} ${N}"
        [ "${i}" = "3" ] && break
@@ -56,22 +56,22 @@ done
 # the order given to us.
 OUR_SEARCH=
 if ${LOCALH} ; then
-       if [ -e "${BASE}" ] ; then
+       if [ -e "${BASE}" ]; then
                OUR_SEARCH="$(sed -n -e 's/^[[:space:]]*search[[:space:]]*//p' "${BASE}")"
        fi
-       OUR_SEARCH="${OUR_SEARCH} $(echo "${RESOLVCONF}" \
+       OUR_SEARCH="${OUR_SEARCH} $(echo "${RESOLVCONFS}" \
                | sed -n 's/^[[:space:]]*search[[:space:]]*//p')"
-       if [ -e "${BASE}" ] ; then
+       if [ -e "${BASE}" ]; then
                OUR_SEARCH="${OUR_SEARCH} $(sed -n -e 's/^[[:space:]]*domain[[:space:]]*//p' "${BASE}")"
        fi
-       OUR_SEARCH="${OUR_SEARCH} $( echo "${RESOLVCONF}" \
+       OUR_SEARCH="${OUR_SEARCH} $( echo "${RESOLVCONFS}" \
                | sed -n -e 's/^[[:space:]]*domain[[:space:]]*//p')"
 else
-       if [ -e "${BASE}" ] ; then
+       if [ -e "${BASE}" ]; then
                OUR_SEARCH="$(sed -n -e 's/^[[:space:]]*search[[:space:]]*//p' \
                        -e 's/^[[:space:]]*domain[[:space:]]*//p' "${BASE}")"
        fi
-       OUR_SEARCH="${OUR_SEARCH} $(echo "${RESOLVCONF}" \
+       OUR_SEARCH="${OUR_SEARCH} $(echo "${RESOLVCONFS}" \
                | sed -n -e 's/^[[:space:]]*search[[:space:]]*//p' \
                        -e 's/^[[:space:]]*domain[[:space:]]*//p')"
 fi
@@ -79,7 +79,7 @@ fi
 # libc only allows for 6 search domains 
 i=0
 SEARCH=
-for S in $(uniqify ${OUR_SEARCH}) ; do
+for S in $(uniqify ${OUR_SEARCH}); do
        i=$((${i} + 1))
        SEARCH="${SEARCH} ${S}"
        [ "${i}" = "6" ] && break
@@ -88,15 +88,15 @@ done
 
 # Hold our new resolv.conf in a variable to save on temporary files
 NEWCONF="# Generated by resolvconf\n"
-[ -e /etc/resolvconf/resolv.conf.d/head ] \
-       && NEWCONF="${NEWCONF}$(cat /etc/resolvconf/resolv.conf.d/head)\n"
+[ -e "${RESOLVCONF}"/resolv.conf.d/head ] \
+       && NEWCONF="${NEWCONF}$(cat "${RESOLVCONF}"/resolv.conf.d/head)\n"
 [ -n "${SEARCH}" ] && NEWCONF="${NEWCONF}${SEARCH}\n"
-for N in ${NS} ; do
+for N in ${NS}; do
        NEWCONF="${NEWCONF}nameserver ${N}\n"
 done
 
 # Now dump everything else from our resolvs
-if [ -e "${BASE}" ] ; then
+if [ -e "${BASE}" ]; then
        NEWCONF="${NEWCONF}$(sed -e '/^[[:space:]]*$/d' \
                -e '/^[[:space:]]*nameserver[[:space:]]*.*/d' \
                -e '/^[[:space:]]*search[[:space:]]*.*/d' \
@@ -105,30 +105,33 @@ if [ -e "${BASE}" ] ; then
 fi
 
 # We don't know we're using GNU sed, so we do it like this
-NEWCONF="${NEWCONF}$(echo "${RESOLVCONF}" | sed -e '/^[[:space:]]*$/d' \
+NEWCONF="${NEWCONF}$(echo "${RESOLVCONFS}" | sed -e '/^[[:space:]]*$/d' \
        -e '/^[[:space:]]*#/d' \
        -e '/^[[:space:]]*nameserver[[:space:]]*.*/d' \
        -e '/^[[:space:]]*search[[:space:]]*.*/d' \
        -e '/^[[:space:]]*domain[[:space:]]*.*/d' \
        )"
-[ -e /etc/resolvconf/resolv.conf.d/tail ] \
-       && NEWCONF="${NEWCONF}$(cat /etc/resolvconf/resolv.conf.d/tail)"
+[ -e "${RESOLVCONF}"/resolv.conf.d/tail ] \
+       && NEWCONF="${NEWCONF}$(cat "${RESOLVCONF}"/resolv.conf.d/tail)"
 
 # Check if the file has actually changed or not
-if [ -e /etc/resolv.conf ] ; then
-       [ "$(cat /etc/resolv.conf)" = "$(printf "${NEWCONF}")" ] && exit 0
+if [ -e "${RESOLVCONF}"/run/resolv.conf ]; then
+       [ "$(cat "${RESOLVCONF}"/run/resolv.conf)" = "$(printf "${NEWCONF}")" ] && exit 0
 fi
 
 # Create our resolv.conf now
-printf "${NEWCONF}" > /etc/resolvconf/run/resolv.conf
+printf "${NEWCONF}" > "${RESOLVCONF}"/run/resolv.conf
 
 # Restart nscd if it's running
-if [ -x /etc/init.d/nscd ] ; then
+if [ -x /etc/init.d/nscd ]; then
        /etc/init.d/nscd --nodeps --quiet conditionalrestart
 fi
+if [ -x /etc/rc.d/nscd ]; then
+       /etc/rc.d/nscd restart
+fi
 
 # Notify users of the resolver
-for x in /etc/resolvconf/update-libc.d/* ; do
+for x in "${REVOLVCONF}"/update-libc.d/*; do
        [ -e "${x}" ] && "${x}" "$@"
 done
 
index e3cad26fecdd0c72d9ade428fde697de029fa305..1e6bd2ea89c2f5239367c459158baf683990e7d2 100755 (executable)
@@ -1,13 +1,17 @@
 #!/bin/sh
 # Copyright 2006 Gentoo Foundation
+# Copyright 2007 Roy Marples
 # Distributed under the terms of the GNU General Public License v2
 
-# Written by Roy Marples (uberlord@gentoo.org)
-# Heavily based on Debian resolvconf by Thomas Hood
+# Written by Roy Marples (roy@marples.name)
+# Based on Debian resolvconf by Thomas Hood
 
 argv0="$0"
 
-VARDIR=/etc/resolvconf/run
+PREFIX=
+RESOLVCONF="${PREFIX}"/etc/resolvconf
+UPDATED="${RESOLVCONF}"/update.d
+VARDIR="${RESOLVCONF}"/run
 IFACEDIR="${VARDIR}/interfaces"
 
 error_exit() {
@@ -49,7 +53,7 @@ echo_resolv() {
 
 uniqify() {
     local result=
-    while [ -n "$1" ] ; do
+    while [ -n "$1" ]; do
                case " ${result} " in
                        *" $1 "*) ;;
                        *) result="${result} $1" ;;
@@ -59,40 +63,40 @@ uniqify() {
     echo "${result# *}"
 }
 
-if [ -n "$1" ] ; then
+if [ -n "$1" ]; then
        CMD="$1"
        shift
 fi
-if [ -n "$1" ] ; then
+if [ -n "$1" ]; then
        IFACE="$1"
        shift
 fi
 
 # -l is a Gentoo option that lists our resolv files
 # optionally for a specific interface
-if [ "x${CMD}" = "x-l" -o "x${CMD}" = "x-i" ] ; then
-       [ ! -d "${IFACEDIR}" ] && exit 0
+if [ "x${CMD}" = "x-l" -o "x${CMD}" = "x-i" ]; then
+       [ -d "${IFACEDIR}" ] || exit 0
        
        # If we have an interface ordering list, then use that.
        # It works by just using pathname expansion in the interface directory.
-       if [ -n "${IFACE}" ] ; then
+       if [ -n "${IFACE}" ]; then
                LIST="${IFACE} $@"
-       elif [ -r /etc/resolvconf/interface-order ] ; then
-               LIST="$(cat /etc/resolvconf/interface-order)"
+       elif [ -r "${RESOLVCONF}"/interface-order ]; then
+               LIST="$(cat "${RESOLVCONF}"/interface-order)"
        fi
 
        # If we don't have a list then prefer lo, tunnels, ppp
        # and then anything else.
-       if [ -z "${LIST}" ] ; then
+       if [ -z "${LIST}" ]; then
                LIST="lo lo[0-9]* tap[0-9]* tun[0-9]* vpn vpn[0-9]* ppp[0-9]* ippp[0-9]* *"
        fi
 
        cd "${IFACEDIR}"
-       for IFACE in $(uniqify ${LIST}) ; do
+       for IFACE in $(uniqify ${LIST}); do
                # Only list interfaces which we really have
                [ -e "${IFACE}" ] || continue
                
-               if [ "x${CMD}" = "x-i" ] ; then
+               if [ "x${CMD}" = "x-i" ]; then
                        printf "${IFACE} "
                else
                        echo_resolv "${IFACE}"
@@ -102,7 +106,7 @@ if [ "x${CMD}" = "x-l" -o "x${CMD}" = "x-i" ] ; then
        exit 0
 fi
 
-if [ "x${CMD}" = "x-v" ] ; then
+if [ "x${CMD}" = "x-v" ]; then
        NS=
        DOMAIN=
        SEARCH=
@@ -111,7 +115,7 @@ if [ "x${CMD}" = "x-v" ] ; then
        NEWDOMAIN=
        LINES="$("${argv0}" -l "${IFACE}" | sed -e "s/'/'\\\\''/g" -e "s/^/'/g" -e "s/$/'/g")"
        eval set -- ${LINES}
-       for LINE in "$@" ; do
+       for LINE in "$@"; do
                case "${LINE}" in
                        "nameserver "*)
                                case "${LINE#* }" in
@@ -127,12 +131,12 @@ if [ "x${CMD}" = "x-v" ] ; then
                                DOMAIN=
                                ;;
                        *)
-                               if [ -z "${LINE}" ] ; then
-                                       for N in ${NS} ; do
-                                               if [ -n "${DOMAIN}" ] ; then
+                               if [ -z "${LINE}" ]; then
+                                       for N in ${NS}; do
+                                               if [ -n "${DOMAIN}" ]; then
                                                        NEWDOMAIN="${NEWDOMAIN} ${DOMAIN},${N}"
-                                               elif [ -n "${SEARCH}" ] ; then
-                                                       for S in ${SEARCH} ; do
+                                               elif [ -n "${SEARCH}" ]; then
+                                                       for S in ${SEARCH}; do
                                                                NEWSEARCH="${NEWSEARCH} ${S},${N}"
                                                        done
                                                else
@@ -152,9 +156,9 @@ if [ "x${CMD}" = "x-v" ] ; then
        NEWDOMAIN="$(uniqify ${NEWDOMAIN})"
        NEWSEARCH="$(uniqify ${NEWSEARCH})"
        NEWNS="$(uniqify ${NEWNS})"
-       for S in ${NEWSEARCH} ; do
-               for DN in ${NEWDOMAIN} ; do
-                       if [ "${S%,*}" = "${DN%,*}" ] ; then
+       for S in ${NEWSEARCH}; do
+               for DN in ${NEWDOMAIN}; do
+                       if [ "${S%,*}" = "${DN%,*}" ]; then
                                NEWSEARCH="$(echo "${NEWSEARCH}" | sed -e "s/${S}/${DN}/g")"
                                NEWDOMAIN="$(echo "${NEWDOMAIN}" | sed -e "s/${DN}//g")"
                                break
@@ -169,28 +173,27 @@ if [ "x${CMD}" = "x-v" ] ; then
 fi
 
 # Only root can update resolv.conf
-if ! touch "${VARDIR}"/.test ; then
+if ! touch "${VARDIR}"/.test; then
        error_exit "You must be root to run ${argv0##*/}"
 fi
 rm "${VARDIR}"/.test
 
 # Test that we have valid options
-if [ "x${CMD}" = "x-a" -o "x${CMD}" = "x-d" ] ; then
-       if [ -z "${IFACE}" ] ; then
+if [ "x${CMD}" = "x-a" -o "x${CMD}" = "x-d" ]; then
+       if [ -z "${IFACE}" ]; then
                usage "Interface not specified"
        fi
-elif [ "x${CMD}" != "x-u" ] ; then
+elif [ "x${CMD}" != "x-u" ]; then
        [ -n "x${CMD}" -a "x${CMD}" != "x-h" ] && usage "Unknown option ${CMD}"
        usage
 fi
-if [ "x${CMD}" = "x-a" ] ; then
-       q='\'
-       for x in '/' '\' ' ' '*' ; do
+if [ "x${CMD}" = "x-a" ]; then
+       for x in '/' \\ ' ' '*'; do
                case "${IFACE}" in
                        *[${x}]*) error_exit "${x} not allowed in interface name" ;;
                esac
        done
-       for x in '.' '-' '~' ; do
+       for x in '.' '-' '~'; do
                case "${IFACE}" in
                        [${x}]*) error_exit "${x} not allowed at start of interface name" ;;
                esac
@@ -200,9 +203,9 @@ if [ "x${CMD}" = "x-a" ] ; then
 fi
 
 # Ensure that libdir exists
-if [ ! -d "${IFACEDIR}" ] ; then
-       if [ ! -d "${VARDIR}" ] ; then
-               if [ -L "${VARDIR}" ] ; then
+if [ ! -d "${IFACEDIR}" ]; then
+       if [ ! -d "${VARDIR}" ]; then
+               if [ -L "${VARDIR}" ]; then
                        DIR="$(readlink -f "${VARDIR}")"
                        [ -z "${DIR}" ] && DIR="$(readlink "${VARDIR}")"
                fi
@@ -215,20 +218,20 @@ if [ ! -d "${IFACEDIR}" ] ; then
                error_exit "Failed to create needed directory ${IFACEDIR}"
 else
        # Delete any existing information about the interface
-       if [ "x${CMD}" = "x-a" -o "x${CMD}" = "x-d" ] ; then
+       if [ "x${CMD}" = "x-a" -o "x${CMD}" = "x-d" ]; then
                cd "${IFACEDIR}"
-               for iface in ${IFACE} ; do
+               for iface in ${IFACE}; do
                        rm -f "${iface}"
                done
        fi
 fi
 
-if [ "x${CMD}" = "x-a" ] ; then
+if [ "x${CMD}" = "x-a" ]; then
        # Create our resolv.conf file
        cat >"${IFACEDIR}"/"${IFACE}"
 fi
 
-for x in /etc/resolvconf/update.d/* ; do
+for x in "${UPDATED}"/*; do
        [ -e "${x}" ] && "${x}" "${CMD}" "${IFACE}"
 done