diff options
Diffstat (limited to 'dhcpcd-run-hooks.in')
| -rw-r--r-- | dhcpcd-run-hooks.in | 78 |
1 files changed, 38 insertions, 40 deletions
diff --git a/dhcpcd-run-hooks.in b/dhcpcd-run-hooks.in index ca8fe94a..35ce93fb 100644 --- a/dhcpcd-run-hooks.in +++ b/dhcpcd-run-hooks.in @@ -2,26 +2,24 @@ # dhcpcd client configuration script # Handy variables and functions for our hooks to use -from="from" +from=from signature_base="# Generated by dhcpcd" -signature="${signature_base} ${from} ${interface}" +signature="$signature_base $from $interface" signature_base_end="# End of dhcpcd" -signature_end="${signature_base_end} ${from} ${interface}" -state_dir="/var/run/dhcpcd" +signature_end="$signature_base_end $from $interface" +state_dir=/var/run/dhcpcd # Ensure that all arguments are unique uniqify() { - local result= - - while [ -n "$1" ]; do - case " ${result} " in - *" $1 "*);; - *) result="${result}${result:+ }$1";; + local result= i= + for i; do + case " $result " in + *" $i "*);; + *) result="$result $i";; esac - shift done - echo "${result}" + echo "${result# *}" } # List interface config files in a dir @@ -31,20 +29,20 @@ uniqify() list_interfaces() { local i= x= ifaces= - for i in ${interface_order}; do - [ -e "$1"/${i} ] && ifaces="${ifaces}${ifaces:+ }${i}" + for i in $iforder; do + [ -e "$1/$i" ] && ifaces="$ifaces${ifaces:+ }$i" done for x in "$1"/*; do - [ -e "${x}" ] || continue - for i in ${interface_order}; do - if [ ${i} = "${x##*/}" ]; then + [ -e "$x" ] || continue + for i in $iforder; do + if [ $i = "${x##*/}" ]; then unset x break fi done - [ -n "${x}" ] && ifaces="${ifaces}${ifaces:+ }${x##*/}" + [ -n "$x" ] && ifaces="$ifaces${ifaces:+ }${x##*/}" done - echo "${ifaces}" + echo "$ifaces" } # We normally use sed to extract values using a key from a list of files @@ -59,10 +57,10 @@ key_get_value() else for x; do while read line; do - case "${line}" in - "${key}"*) echo "${line##${key}}";; + case "$line" in + "$key"*) echo "${line##$key}";; esac - done < "${x}" + done < "$x" done fi } @@ -75,16 +73,16 @@ remove_markers() shift; shift if type sed >/dev/null 2>&1; then - sed "/^${m1}/,/^${m2}/d" $@ + sed "/^$m1/,/^$m2/d" $@ else for x; do while read line; do - case "${line}" in - "${m1}"*) in_marker=1;; - "${m2}"*) in_marker=0;; - *) [ ${in_marker} = 0 ] && echo "${line}";; + case "$line" in + "$m1"*) in_marker=1;; + "$m2"*) in_marker=0;; + *) [ $in_marker = 0 ] && echo "$line";; esac - done < "${x}" + done < "$x" done fi } @@ -114,17 +112,17 @@ change_file() save_conf() { if [ -f "$1" ]; then - rm -f "${1}-pre.${interface}" - cat "$1" > "${1}-pre.${interface}" + rm -f "$1-pre.$interface" + cat "$1" > "$1-pre.$interface" fi } # Restore a config file restore_conf() { - [ -f "${1}-pre.${interface}" ] || return 1 - cat "${1}-pre.${interface}" > "$1" - rm -f "${1}-pre.${interface}" + [ -f "$1-pre.$interface" ] || return 1 + cat "$1-pre.$interface" > "$1" + rm -f "$1-pre.$interface" } @@ -137,14 +135,14 @@ for hook in \ @HOOKDIR@/* \ @SYSCONFDIR@/dhcpcd.exit-hook do - for skip in ${skip_hooks}; do - case "${hook}" in - */"${skip}") continue 2;; - */[0-9][0-9]"-${skip}") continue 2;; - */[0-9][0-9]"-${skip}.sh") continue 2;; + for skip in $skip_hooks; do + case "$hook" in + */"$skip") continue 2;; + */[0-9][0-9]"-$skip") continue 2;; + */[0-9][0-9]"-$skip.sh") continue 2;; esac done - if [ -f "${hook}" ]; then - . "${hook}" + if [ -f "$hook" ]; then + . "$hook" fi done |
