]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
hooks: Use command -v rather than type
authorRoy Marples <roy@marples.name>
Thu, 24 Feb 2022 12:53:02 +0000 (12:53 +0000)
committerRoy Marples <roy@marples.name>
Thu, 24 Feb 2022 12:53:02 +0000 (12:53 +0000)
command -v is now required by POSIX, type is technically an extension.

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

index 04acce088840c1d0cf33e6e37679b17a8b8a3769..1da0108dc64a914fe3621c195a528e17bed6a64f 100644 (file)
@@ -102,8 +102,8 @@ wpa_supplicant_stop()
 }
 
 if [ "$ifwireless" = "1" ] && \
-    type wpa_supplicant >/dev/null 2>&1 && \
-    type wpa_cli >/dev/null 2>&1
+    command -v wpa_supplicant >/dev/null 2>&1 && \
+    command -v wpa_cli >/dev/null 2>&1
 then
        case "$reason" in
        PREINIT)        wpa_supplicant_start;;
index 504a6c5373a400042a5b780d32dfdbb834444a7f..7c29e2765b36c98df0ccaf5ba913a78fdea8f063 100644 (file)
@@ -11,7 +11,7 @@ nocarrier_roaming_dir="$state_dir/roaming"
 NL="
 "
 : ${resolvconf:=resolvconf}
-if type "$resolvconf" >/dev/null 2>&1; then
+if command -v "$resolvconf" >/dev/null 2>&1; then
        have_resolvconf=true
 else
        have_resolvconf=false
index 811c7a9c89bf1999570262ac7f5cf2387a4d4770..a1540dd983409e0b0c9def03b04b309a77b85471 100644 (file)
@@ -4,20 +4,20 @@ lookup_hostname()
 {
        [ -z "$new_ip_address" ] && return 1
        # Silly ISC programs love to send error text to stdout
-       if type dig >/dev/null 2>&1; then
+       if command -v dig >/dev/null 2>&1; then
                h=$(dig +short -x $new_ip_address)
                if [ $? = 0 ]; then
                        echo "$h" | sed 's/\.$//'
                        return 0
                fi
-       elif type host >/dev/null 2>&1; then
+       elif command -v host >/dev/null 2>&1; then
                h=$(host $new_ip_address)
                if [ $? = 0 ]; then 
                        echo "$h" \
                        | sed 's/.* domain name pointer \(.*\)./\1/'
                        return 0
                fi
-       elif type getent >/dev/null 2>&1; then
+       elif command -v getent >/dev/null 2>&1; then
                h=$(getent hosts $new_ip_address)
                if [ $? = 0 ]; then
                        echo "$h" | sed 's/[^ ]* *\([^ ]*\).*/\1/'
index abeb369672210351bf2d6253cb14c8dd5ff2fe09..b0a37576429f9175f16009a75c888518e3828be8 100644 (file)
@@ -25,7 +25,7 @@ _hostname()
        if [ -z "${1+x}" ]; then
                if [ -r /proc/sys/kernel/hostname ]; then
                        read name </proc/sys/kernel/hostname && echo "$name"
-               elif type hostname >/dev/null 2>/dev/null; then
+               elif command -v hostname >/dev/null 2>/dev/null; then
                        hostname
                elif sysctl kern.hostname >/dev/null 2>&1; then
                        sysctl -n kern.hostname
@@ -39,7 +39,7 @@ _hostname()
 
        if [ -w /proc/sys/kernel/hostname ]; then
                echo "$1" >/proc/sys/kernel/hostname
-       elif [ -n "$1" ] && type hostname >/dev/null 2>&1; then
+       elif [ -n "$1" ] && command -v hostname >/dev/null 2>&1; then
                hostname "$1"
        elif sysctl kern.hostname >/dev/null 2>&1; then
                sysctl -w "kern.hostname=$1" >/dev/null
index 046ab6b33a06cb5b98057d1db6cf1aa86576cd71..767e83609dd6f28dfcd26e7f32025e28d7bac631 100644 (file)
@@ -43,7 +43,7 @@ fi
 
 # Debian has a separate file for DHCP config to avoid stamping on
 # the master.
-if [ "$ntp_service" = ntpd ] && type invoke-rc.d >/dev/null 2>&1; then
+if [ "$ntp_service" = ntpd ] && command -v invoke-rc.d >/dev/null 2>&1; then
        [ -e /var/lib/ntp ] || mkdir /var/lib/ntp
        : ${ntp_service:=ntp}
        : ${NTP_DHCP_CONF:=/var/lib/ntp/ntp.conf.dhcp}
index a237f6af53400adeb332e891f3e97fe251c36efa..c858da3b3988e95ae16b25506a1949924294381d 100644 (file)
@@ -67,7 +67,7 @@ key_get_value()
        key="$1"
        shift
 
-       if type sed >/dev/null 2>&1; then
+       if command -v sed >/dev/null 2>&1; then
                sed -n "s/^$key//p" $@
        else
                for x do
@@ -89,7 +89,7 @@ remove_markers()
        in_marker=0
 
        shift; shift
-       if type sed >/dev/null 2>&1; then
+       if command -v sed >/dev/null 2>&1; then
                sed "/^$m1/,/^$m2/d" $@
        else
                for x do
@@ -109,9 +109,9 @@ comp_file()
 {
        [ -e "$1" ] && [ -e "$2" ] || return 1
 
-       if type cmp >/dev/null 2>&1; then
+       if command -v cmp >/dev/null 2>&1; then
                cmp -s "$1" "$2"
-       elif type diff >/dev/null 2>&1; then
+       elif command -v diff >/dev/null 2>&1; then
                diff -q "$1" "$2" >/dev/null
        else
                # Hopefully we're only working on small text files ...
@@ -178,7 +178,7 @@ syslog()
        err|error)      echo "$interface: $*" >&2;;
        *)              echo "$interface: $*";;
        esac
-       if type logger >/dev/null 2>&1; then
+       if command -v logger >/dev/null 2>&1; then
                logger -i -p daemon."$lvl" -t dhcpcd-run-hooks "$interface: $*"
        fi
 }