2 # dhcpcd client configuration script
4 # Handy variables and functions for our hooks to use
6 signature_base
="# Generated by dhcpcd"
7 signature
="$signature_base $from $interface"
8 signature_base_end
="# End of dhcpcd"
9 signature_end
="$signature_base_end $from $interface"
10 state_dir
=/var
/run
/dhcpcd
12 # Ensure that all arguments are unique
19 *) result
="$result $i";;
25 # List interface config files in a dir
26 # If dhcpcd is running as a single instance then it will have a list of
27 # interfaces in the preferred order.
28 # Otherwise we just use what we have.
32 for i
in $interface_order; do
33 [ -e "$1/$i" ] && ifaces
="$ifaces${ifaces:+ }$i"
36 [ -e "$x" ] ||
continue
37 for i
in $interface_order; do
38 if [ $i = "${x##*/}" ]; then
43 [ -n "$x" ] && ifaces
="$ifaces${ifaces:+ }${x##*/}"
48 # We normally use sed to extract values using a key from a list of files
49 # but sed may not always be available at the time.
52 local key
="$1" value
= x
= line
=
55 if type sed >/dev
/null
2>&1; then
56 sed -n "s/^$key//p" $@
61 "$key"*) echo "${line##$key}";;
68 # We normally use sed to remove markers from a configuration file
69 # but sed may not always be available at the time.
72 local m1
="$1" m2
="$2" x
= line
= in_marker
=0
75 if type sed >/dev
/null
2>&1; then
76 sed "/^$m1/,/^$m2/d" $@
83 *) [ $in_marker = 0 ] && echo "$line";;
91 # If different, replace first with second otherwise remove second
94 if type cmp >/dev
/null
2>&1; then
96 elif type diff >/dev
/null
2>&1; then
97 diff -q "$1" "$2" >/dev
/null
99 # Hopefully we're only working on small text files ...
100 [ "$(cat "$1")" = "$(cat "$2")" ]
102 if [ $?
-eq 0 ]; then
115 rm -f "$1-pre.$interface"
116 cat "$1" > "$1-pre.$interface"
120 # Restore a config file
123 [ -f "$1-pre.$interface" ] ||
return 1
124 cat "$1-pre.$interface" > "$1"
125 rm -f "$1-pre.$interface"
128 # Write a syslog entry
133 [ -n "$lvl" ] && shift
135 if type logger
>/dev
/null
2>&1; then
136 logger
-t dhcpcd
-p daemon.
"$lvl" -s "$@"
142 # We source each script into this one so that scripts run earlier can
143 # remove variables from the environment so later scripts don't see them.
144 # Thus, the user can create their dhcpcd.enter/exit-hook script to configure
145 # /etc/resolv.conf how they want and stop the system scripts ever updating it.
147 @SYSCONFDIR@
/dhcpcd.enter-hook \
149 @SYSCONFDIR@
/dhcpcd.exit-hook
151 for skip
in $skip_hooks; do
153 */"$skip") continue 2;;
154 */[0-9][0-9]"-$skip") continue 2;;
155 */[0-9][0-9]"-$skip.sh") continue 2;;
158 if [ -f "$hook" ]; then