diff options
| author | Roy Marples <roy@marples.name> | 2008-05-20 10:55:25 +0000 |
|---|---|---|
| committer | Roy Marples <roy@marples.name> | 2008-05-20 10:55:25 +0000 |
| commit | c61c4118d8a688f26a9bd53b061090aca5e45f66 (patch) | |
| tree | 3d6ef2da241dcd8789f040bcbb45c534f4f65dc1 /dhcpcd.sh.in | |
| parent | f4456e160e165aff083d4c877361ff3e5069708f (diff) | |
| download | dhcpcd-c61c4118d8a688f26a9bd53b061090aca5e45f66.tar.xz | |
Split dhcpcd.sh into smaller hook scripts, so that dhcpcd.sh just provide some handy functions and runs the hooks. We now only have one hook, instead of enter/exit.
Diffstat (limited to 'dhcpcd.sh.in')
| -rw-r--r-- | dhcpcd.sh.in | 128 |
1 files changed, 12 insertions, 116 deletions
diff --git a/dhcpcd.sh.in b/dhcpcd.sh.in index 7e080254..4715101a 100644 --- a/dhcpcd.sh.in +++ b/dhcpcd.sh.in @@ -1,131 +1,27 @@ #!/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 |
