treewide: replace `which` with `command -v`
authorPaul Spooren <mail@aparcar.org>
Sun, 9 Aug 2020 23:42:09 +0000 (13:42 -1000)
committerPaul Spooren <mail@aparcar.org>
Fri, 21 Aug 2020 01:54:54 +0000 (15:54 -1000)
Fix shellcheck SC2230
> which is non-standard. Use builtin 'command -v' instead.

Once applied to everything concerning OpenWrt we can disable the busybox
feature `which` and save 3.8kB.

Signed-off-by: Paul Spooren <mail@aparcar.org>
applications/luci-app-ddns/root/usr/libexec/rpcd/luci.ddns
applications/luci-app-dockerman/luasrc/model/cbi/dockerman/container.lua
applications/luci-app-mwan3/luasrc/model/cbi/mwan/interfaceconfig.lua
build/i18n-init.sh
libs/luci-lib-nixio/src/Makefile

index 8ba4ad3165129cb0cc42773f23212df6e41f97c4..7710ee66f47e0b8901e5d1254f60824f2dc954a0 100755 (executable)
@@ -179,23 +179,23 @@ local methods = {
                        local cache = {}
 
                        local function has_wget()
-                               return (sys.call( [[which wget >/dev/null 2>&1]] ) == 0)
+                               return (sys.call( [[command -v wget >/dev/null 2>&1]] ) == 0)
                        end
 
                        local function has_wgetssl()
                                if cache['has_wgetssl'] then return cache['has_wgetssl'] end
-                               local res = (sys.call( [[which wget-ssl >/dev/null 2>&1]] ) == 0)
+                               local res = (sys.call( [[command -v wget-ssl >/dev/null 2>&1]] ) == 0)
                                cache['has_wgetssl'] = res
                                return res
                        end
 
                        local function has_curlssl()
-                               return (sys.call( [[$(which curl) -V 2>&1 | grep -qF "https"]] ) == 0)
+                               return (sys.call( [[$(command -v curl) -V 2>&1 | grep -qF "https"]] ) == 0)
                        end
 
                        local function has_fetch()
                                if cache['has_fetch'] then return cache['has_fetch'] end
-                               local res = (sys.call( [[which uclient-fetch >/dev/null 2>&1]] ) == 0)
+                               local res = (sys.call( [[command -v uclient-fetch >/dev/null 2>&1]] ) == 0)
                                cache['has_fetch'] = res
                                return res
                        end
@@ -206,7 +206,7 @@ local methods = {
 
                        local function has_curl()
                                if cache['has_curl'] then return cache['has_curl'] end
-                               local res = (sys.call( [[which curl >/dev/null 2>&1]] ) == 0)
+                               local res = (sys.call( [[command -v curl >/dev/null 2>&1]] ) == 0)
                                cache['has_curl'] = res
                                return res
                        end
@@ -216,7 +216,7 @@ local methods = {
                        end
 
                        local function has_bbwget()
-                               return (sys.call( [[$(which wget) -V 2>&1 | grep -iqF "busybox"]] ) == 0)
+                               return (sys.call( [[$(command -v wget) -V 2>&1 | grep -iqF "busybox"]] ) == 0)
                        end
 
                        res['has_wget'] = has_wget() or false
@@ -229,17 +229,17 @@ local methods = {
 
                        local function has_bindhost()
                                if cache['has_bindhost'] then return cache['has_bindhost'] end
-                               local res = (sys.call( [[which host >/dev/null 2>&1]] ) == 0)
+                               local res = (sys.call( [[command -v host >/dev/null 2>&1]] ) == 0)
                                if res then
                                        cache['has_bindhost'] = res
                                        return true
                                end
-                               res = (sys.call( [[which khost >/dev/null 2>&1]] ) == 0)
+                               res = (sys.call( [[command -v khost >/dev/null 2>&1]] ) == 0)
                                if res then
                                        cache['has_bindhost'] = res
                                        return true
                                end
-                               res = (sys.call( [[which drill >/dev/null 2>&1]] ) == 0)
+                               res = (sys.call( [[command -v drill >/dev/null 2>&1]] ) == 0)
                                if res then
                                        cache['has_bindhost'] = res
                                        return true
@@ -251,11 +251,11 @@ local methods = {
                        res['has_bindhost'] = cache['has_bindhost'] or has_bindhost() or false
 
                        local function has_hostip()
-                               return (sys.call( [[which hostip >/dev/null 2>&1]] ) == 0)
+                               return (sys.call( [[command -v hostip >/dev/null 2>&1]] ) == 0)
                        end
 
                        local function has_nslookup()
-                               return (sys.call( [[which nslookup >/dev/null 2>&1]] ) == 0)
+                               return (sys.call( [[command -v nslookup >/dev/null 2>&1]] ) == 0)
                        end
 
                        res['has_dnsserver'] = cache['has_bindhost'] or has_nslookup() or has_hostip() or has_bindhost() or false
index 37be23e0d136ff8b906fa0838551e59a09f0bb45..ec3f9201af8fed81dd836de279d77d9a582f2b34 100644 (file)
@@ -664,8 +664,8 @@ elseif action == "logs" then
 elseif action == "console" then
        m.submit = false
        m.reset  = false
-       local cmd_docker = luci.util.exec("which docker"):match("^.+docker") or nil
-       local cmd_ttyd = luci.util.exec("which ttyd"):match("^.+ttyd") or nil
+       local cmd_docker = luci.util.exec("command -v docker"):match("^.+docker") or nil
+       local cmd_ttyd = luci.util.exec("command -v ttyd"):match("^.+ttyd") or nil
 
        if cmd_docker and cmd_ttyd and container_info.State.Status == "running" then
                local cmd = "/bin/sh"
@@ -697,8 +697,8 @@ elseif action == "console" then
                        Button.render(self, section, scope)
                end
                o.write = function(self, section)
-                       local cmd_docker = luci.util.exec("which docker"):match("^.+docker") or nil
-                       local cmd_ttyd = luci.util.exec("which ttyd"):match("^.+ttyd") or nil
+                       local cmd_docker = luci.util.exec("command -v docker"):match("^.+docker") or nil
+                       local cmd_ttyd = luci.util.exec("command -v ttyd"):match("^.+ttyd") or nil
 
                        if not cmd_docker or not cmd_ttyd or cmd_docker:match("^%s+$") or cmd_ttyd:match("^%s+$")then
                                return
index bcbf03d54eaedad4d0d6cc34f41cc8baba3f4c3c..e52791a1cf3c759d0f09a30873cc96d6421fc505 100644 (file)
@@ -41,18 +41,18 @@ track_ip.datatype = "host"
 track_method = mwan_interface:option(ListValue, "track_method", translate("Tracking method"))
 track_method.default = "ping"
 track_method:value("ping")
-if os.execute("which nping 1>/dev/null") == 0 then
+if os.execute("command -v nping 1>/dev/null") == 0 then
        track_method:value("nping-tcp")
        track_method:value("nping-udp")
        track_method:value("nping-icmp")
        track_method:value("nping-arp")
 end
 
-if os.execute("which arping 1>/dev/null") == 0 then
+if os.execute("command -v arping 1>/dev/null") == 0 then
        track_method:value("arping")
 end
 
-if os.execute("which httping 1>/dev/null") == 0 then
+if os.execute("command -v httping 1>/dev/null") == 0 then
        track_method:value("httping")
 end
 
index b20fbc33474499a3c201994347b0fc983dbd8f85..94abdfcd568eecb5efc195b7e03dfb203d01887e 100755 (executable)
@@ -4,7 +4,7 @@ PATTERN=$1
 SCM=
 
 [ -d .svn ] && SCM="svn"
-git=$( which git 2>/dev/null )
+git=$( command -v git 2>/dev/null )
 [ "$git" ] && "$git" status >/dev/null && SCM="git"
 
 [ -z "$SCM" ] && {
index a7e9a77d9992e3d62998cce04b4f155362d812fa..893656c25685a77ecedc07513eac1cad51fc906f 100644 (file)
@@ -51,7 +51,7 @@ ifeq ($(OS),SunOS)
 endif
 
 ifneq (,$(findstring MINGW,$(OS))$(findstring mingw,$(OS))$(findstring Windows,$(OS)))
-       NIXIO_CROSS_CC:=$(shell which i586-mingw32msvc-cc)
+       NIXIO_CROSS_CC:=$(shell command -v i586-mingw32msvc-cc)
 ifneq (,$(NIXIO_CROSS_CC))
        CC:=$(NIXIO_CROSS_CC)
 endif