From: Roy Marples Date: Sat, 20 Jan 2018 20:28:20 +0000 (+0000) Subject: dhcpcd-run-hooks: POSIX shell does not require the local builtin X-Git-Tag: v7.0.1~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f73b5dab0ff7800358e64d430c00d8428d3337f7;p=thirdparty%2Fdhcpcd.git dhcpcd-run-hooks: POSIX shell does not require the local builtin And sadly some ksh variants don't support it. As dhcpcd strives to be portable, stop using local. --- diff --git a/hooks/10-wpa_supplicant b/hooks/10-wpa_supplicant index 9eec0c1f..6249385d 100644 --- a/hooks/10-wpa_supplicant +++ b/hooks/10-wpa_supplicant @@ -20,8 +20,6 @@ fi wpa_supplicant_ctrldir() { - local dir - dir=$(key_get_value "[[:space:]]*ctrl_interface=" \ "$wpa_supplicant_conf") dir=$(trim "$dir") @@ -37,8 +35,6 @@ wpa_supplicant_ctrldir() wpa_supplicant_start() { - local dir err errn - # If the carrier is up, don't bother checking anything [ "$ifcarrier" = "up" ] && return 0 @@ -72,8 +68,6 @@ wpa_supplicant_start() wpa_supplicant_reconfigure() { - local dir err errn - dir=$(wpa_supplicant_ctrldir) [ -z "$dir" ] && return 1 if ! wpa_cli -p "$dir" -i "$interface" status >/dev/null 2>&1; then @@ -92,8 +86,6 @@ wpa_supplicant_reconfigure() wpa_supplicant_stop() { - local dir err errn - dir=$(wpa_supplicant_ctrldir) [ -z "$dir" ] && return 1 wpa_cli -p "$dir" -i "$interface" status >/dev/null 2>&1 || return 0 diff --git a/hooks/15-timezone b/hooks/15-timezone index 0ccdc45b..ac04c652 100644 --- a/hooks/15-timezone +++ b/hooks/15-timezone @@ -4,10 +4,9 @@ set_zoneinfo() { - local zoneinfo_dir= zone_file= - [ -z "$new_tzdb_timezone" ] && return 0 + zoneinfo_dir= for d in \ /usr/share/zoneinfo \ /usr/lib/zoneinfo \ diff --git a/hooks/20-resolv.conf b/hooks/20-resolv.conf index e4db368d..b03ab578 100644 --- a/hooks/20-resolv.conf +++ b/hooks/20-resolv.conf @@ -13,8 +13,7 @@ NL=" build_resolv_conf() { - local cf="$state_dir/resolv.conf.$ifname" - local interfaces= header= search= srvs= servers= x= + cf="$state_dir/resolv.conf.$ifname" # Build a list of interfaces interfaces=$(list_interfaces "$resolv_conf_dir") @@ -77,7 +76,6 @@ build_resolv_conf() # regarding DNS option lifetime in ND messages. eval_nd_dns() { - eval ltime=\$nd${i}_rdnss${j}_lifetime if [ -z "$ltime" -o "$ltime" = 0 ]; then rdnss= @@ -101,8 +99,8 @@ eval_nd_dns() add_resolv_conf() { - local x= conf="$signature$NL" warn=true - local i j ltime rdnss dnssl new_rdnss new_dnssl + conf="$signature$NL" + warn=true # Loop to extract the ND DNS options using our indexed shell values i=1 diff --git a/hooks/29-lookup-hostname b/hooks/29-lookup-hostname index 04ad275e..d0b10329 100644 --- a/hooks/29-lookup-hostname +++ b/hooks/29-lookup-hostname @@ -3,7 +3,6 @@ lookup_hostname() { [ -z "$new_ip_address" ] && return 1 - local h= # Silly ISC programs love to send error text to stdout if type dig >/dev/null 2>&1; then h=$(dig +short -x $new_ip_address) diff --git a/hooks/30-hostname b/hooks/30-hostname index 6f8623f8..5f7d26da 100644 --- a/hooks/30-hostname +++ b/hooks/30-hostname @@ -22,8 +22,6 @@ # Some systems don't have hostname(1) _hostname() { - local name= - if [ -z "${1+x}" ]; then if type hostname >/dev/null 2>&1; then hostname @@ -55,10 +53,19 @@ _hostname() fi } -need_hostname() +set_hostname_vars() { - local hfqdn=false hshort=false + hfqdn=false + hshort=false + case "$hostname_fqdn" in + [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|1) hfqdn=true;; + ""|[Ss][Ee][Rr][Vv][Ee][Rr]) ;; + *) hshort=true;; + esac +} +need_hostname() +{ # Always load the hostname variable for future use hostname="$(_hostname)" case "$hostname" in @@ -70,11 +77,7 @@ need_hostname() [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|1) return 0;; esac - case "$hostname_fqdn" in - [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|1) hfqdn=true;; - ""|[Ss][Ee][Rr][Vv][Ee][Rr]) ;; - *) hshort=true;; - esac + set_hostname_vars if [ -n "$old_fqdn" ]; then if ${hfqdn} || ! ${hsort}; then @@ -105,7 +108,6 @@ need_hostname() try_hostname() { - [ "$hostname" = "$1" ] && return 0 if valid_domainname "$1"; then syslog info "Setting hostname: $1" @@ -117,15 +119,9 @@ try_hostname() set_hostname() { - local hfqdn=false hshort=false - need_hostname || return - case "$hostname_fqdn" in - [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|1) hfqdn=true;; - ""|[Ss][Ee][Rr][Vv][Ee][Rr]) ;; - *) hshort=true;; - esac + set_hostname_vars if [ -n "$new_fqdn" ]; then if ${hfqdn} || ! ${hshort}; then diff --git a/hooks/50-ntp.conf b/hooks/50-ntp.conf index 74805039..12178684 100644 --- a/hooks/50-ntp.conf +++ b/hooks/50-ntp.conf @@ -57,12 +57,12 @@ NL=" build_ntp_conf() { - local cf="$state_dir/ntp.conf.$ifname" - local interfaces= header= srvs= servers= x= + cf="$state_dir/ntp.conf.$ifname" # Build a list of interfaces interfaces=$(list_interfaces "$ntp_conf_dir") + servers= if [ -n "$interfaces" ]; then # Build the header for x in ${interfaces}; do @@ -107,7 +107,7 @@ build_ntp_conf() add_ntp_conf() { - local cf="$ntp_conf_dir/$ifname" x= + cf="$ntp_conf_dir/$ifname" [ -e "$cf" ] && rm "$cf" [ -d "$ntp_conf_dir" ] || mkdir -p "$ntp_conf_dir" diff --git a/hooks/50-yp.conf b/hooks/50-yp.conf index 2da68ebc..cc63d139 100644 --- a/hooks/50-yp.conf +++ b/hooks/50-yp.conf @@ -9,9 +9,10 @@ ypbind_pid() make_yp_conf() { [ -z "$new_nis_domain" -a -z "$new_nis_servers" ] && return 0 - local cf=/etc/yp.conf."$ifname" prefix= x= pid= + cf=/etc/yp.conf."$ifname" rm -f "$cf" echo "$signature" > "$cf" + prefix= if [ -n "$new_nis_domain" ]; then if ! valid_domainname "$new_nis_domain"; then syslog err "Invalid NIS domain name: $new_nis_domain" @@ -43,7 +44,7 @@ restore_yp_conf() { [ -n "$old_nis_domain" ] && domainname "" restore_conf /etc/yp.conf || return 0 - local pid="$(ypbind_pid)" + pid="$(ypbind_pid)" if [ -n "$pid" ]; then kill -HUP "$pid" fi diff --git a/hooks/50-ypbind.in b/hooks/50-ypbind.in index a9ebbfa6..eeb3f718 100644 --- a/hooks/50-ypbind.in +++ b/hooks/50-ypbind.in @@ -10,8 +10,6 @@ ypbind_dir="$state_dir/ypbind" best_domain() { - local i= - for i in "$ypbind_dir/$interface_order".*; do if [ -f "$i" ]; then cat "$i" @@ -29,9 +27,9 @@ make_yp_binding() if [ -z "$ypdomain_dir" ]; then false else - local cf="$ypdomain_dir/$new_nis_domain$ypdomain_suffix" + cf="$ypdomain_dir/$new_nis_domain$ypdomain_suffix" if [ -n "$new_nis_servers" ]; then - local ncf="$cf.$ifname" x= + ncf="$cf.$ifname" rm -f "$ncf" for x in $new_nis_servers; do echo "$x" >>"$ncf" @@ -42,7 +40,7 @@ make_yp_binding() fi fi - local nd="$(best_domain)" + nd="$(best_domain)" if [ $? = 0 -a "$nd" != "$(domainname)" ]; then domainname "$nd" if [ -n "$ypbind_restart_cmd" ]; then @@ -53,9 +51,8 @@ make_yp_binding() restore_yp_binding() { - rm -f "$ypbind_dir/$ifname" - local nd="$(best_domain)" + nd="$(best_domain)" # We need to stop ypbind if there is no best domain # otherwise it will just stall as we cannot set domainname # to blank :/ diff --git a/hooks/dhcpcd-run-hooks.in b/hooks/dhcpcd-run-hooks.in index c1d01256..440e25c9 100644 --- a/hooks/dhcpcd-run-hooks.in +++ b/hooks/dhcpcd-run-hooks.in @@ -18,7 +18,6 @@ _detected_init=false # Ensure that all arguments are unique uniqify() { - local result= i= for i do case " $result " in *" $i "*);; @@ -34,7 +33,6 @@ uniqify() # Otherwise we just use what we have. list_interfaces() { - local i= x= ifaces= for i in $interface_order; do for x in "$1"/$i.*; do [ -f "$x" ] && ifaces="$ifaces${ifaces:+ }${x##*/}" @@ -49,8 +47,7 @@ list_interfaces() # Trim function trim() { - local var="$*" - + var="$*" var=${var#"${var%%[![:space:]]*}"} var=${var%"${var##*[![:space:]]}"} if [ -z "$var" ]; then @@ -65,9 +62,9 @@ trim() # but sed may not always be available at the time. key_get_value() { - local key="$1" value= x= line= - + key="$1" shift + if type sed >/dev/null 2>&1; then sed -n "s/^$key//p" $@ else @@ -85,7 +82,9 @@ key_get_value() # but sed may not always be available at the time. remove_markers() { - local m1="$1" m2="$2" x= line= in_marker=0 + m1="$1" + m2="$2" + in_marker=0 shift; shift if type sed >/dev/null 2>&1; then @@ -106,7 +105,6 @@ remove_markers() # Compare two files. comp_file() { - [ -e "$1" -a -e "$2" ] || return 1 if type cmp >/dev/null 2>&1; then @@ -123,7 +121,6 @@ comp_file() # If different, replace first with second otherwise remove second. change_file() { - if [ -e "$1" ]; then if comp_file "$1" "$2"; then rm -f "$2" @@ -139,7 +136,6 @@ change_file() # If different, copy or link depending on target type copy_file() { - if [ -h "$2" ]; then [ "$(readlink "$2")" = "$1" ] && return 1 ln -sf "$1" "$2" @@ -152,7 +148,6 @@ copy_file() # Save a config file save_conf() { - if [ -f "$1" ]; then rm -f "$1-pre.$interface" cat "$1" > "$1-pre.$interface" @@ -162,7 +157,6 @@ save_conf() # Restore a config file restore_conf() { - [ -f "$1-pre.$interface" ] || return 1 cat "$1-pre.$interface" > "$1" rm -f "$1-pre.$interface" @@ -171,7 +165,7 @@ restore_conf() # Write a syslog entry syslog() { - local lvl="$1" + lvl="$1" if [ "$lvl" = debug ]; then ${syslog_debug} || return 0 @@ -190,8 +184,7 @@ syslog() # Check for a valid name as per RFC952 and RFC1123 section 2.1 valid_domainname() { - local name="$1" label - + name="$1" [ -z "$name" -o ${#name} -gt 255 ] && return 1 while [ -n "$name" ]; do @@ -209,8 +202,6 @@ valid_domainname() valid_domainname_list() { - local name - for name do valid_domainname "$name" || return $? done @@ -228,7 +219,7 @@ detect_init() [ -n "$_service_cmd" ] && return 0 - if ${_detected_init}; then + if $_detected_init; then [ -n "$_service_cmd" ] return $? fi @@ -236,7 +227,7 @@ detect_init() # Detect the running init system. # As systemd and OpenRC can be installed on top of legacy init # systems we try to detect them first. - local status="@STATUSARG@" + status="@STATUSARG@" : ${status:=status} if [ -x /bin/systemctl -a -S /run/systemd/private ]; then _service_exists="/bin/systemctl --quiet is-enabled \$1.service" @@ -297,7 +288,6 @@ detect_init() # Check a system service exists service_exists() { - if [ -z "$_service_exists" ]; then detect_init || return 1 fi @@ -307,7 +297,6 @@ service_exists() # Send a command to a system service service_cmd() { - if [ -z "$_service_cmd" ]; then detect_init || return 1 fi @@ -317,7 +306,6 @@ service_cmd() # Send a command to a system service if it is running service_status() { - if [ -z "$_service_cmd" ]; then detect_init || return 1 fi @@ -331,12 +319,10 @@ service_status() # Handy macros for our hooks service_command() { - service_exists $1 && service_cmd $1 $2 } service_condcommand() { - service_exists $1 && service_status $1 && service_cmd $1 $2 }