]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
dhcpcd-run-hooks: POSIX shell does not require the local builtin
authorRoy Marples <roy@marples.name>
Sat, 20 Jan 2018 20:28:20 +0000 (20:28 +0000)
committerRoy Marples <roy@marples.name>
Sat, 20 Jan 2018 20:28:20 +0000 (20:28 +0000)
And sadly some ksh variants don't support it.
As dhcpcd strives to be portable, stop using local.

hooks/10-wpa_supplicant
hooks/15-timezone
hooks/20-resolv.conf
hooks/29-lookup-hostname
hooks/30-hostname
hooks/50-ntp.conf
hooks/50-yp.conf
hooks/50-ypbind.in
hooks/dhcpcd-run-hooks.in

index 9eec0c1f170e1435f838ddd64a3d93f7f7b84c5f..6249385dee8f8c7d8028244114a46dc03372f7e8 100644 (file)
@@ -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
index 0ccdc45b22646bff4ebb89896f86969684e428da..ac04c652f1b20cc674524c2f1bfe9fe749b40ce5 100644 (file)
@@ -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       \
index e4db368dd8efbb2da99492841e6a03c38c70d006..b03ab5789f52a5b1702e5cf872934e6012b052d3 100644 (file)
@@ -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
index 04ad275e304d10d91eeb591083070ad586b70c6a..d0b10329cf69e4a858d4f48f39dc2baf2b3cac51 100644 (file)
@@ -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)
index 6f8623f896aedb91149729fcfaf587559ded3d96..5f7d26da16cbd065318fb3cbd99801fd6282a29a 100644 (file)
@@ -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
index 7480503961d3c40bed0b5b9dd7280e9b7a0d6fab..1217868486eb7379bbaaef5e9d0f150f5d576eaa 100644 (file)
@@ -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"
index 2da68ebc9bcde16bcc70f28c9f904056491e4ff5..cc63d139221ff84240aa8238034cb713b9d301ba 100644 (file)
@@ -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
index a9ebbfa652fe4e4dbb330614a0f4d180a8d2ee71..eeb3f7184577fef7268c89b947797ad0cb9d90e2 100644 (file)
@@ -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 :/
index c1d012569ed6f4590a3be44336e80f83356c84e5..440e25c97f83d100ade841e7fb160ed649af8bf2 100644 (file)
@@ -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
 }