]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
Replace 'which' with 'command -v' 4019/head
authorDiederik de Haas <didi.debian@cknow.org>
Thu, 28 Oct 2021 15:27:08 +0000 (17:27 +0200)
committerDiederik de Haas <didi.debian@cknow.org>
Thu, 28 Oct 2021 15:27:08 +0000 (17:27 +0200)
The 'which' command is deprecated on Debian Sid as it is not POSIX
compliant and it's behavior is therefor not consistent, so replace it
with 'command -v' which is POSIX compliant.
See https://stackoverflow.com/a/677212 for details.

Also replaced a use of backticks (`) as that is deprecated as well.
See https://github.com/koalaman/shellcheck/wiki/SC2006 for details.

Signed-off-by: Diederik de Haas <didi.debian@cknow.org>
config/init/common/lxc-net.in
hooks/dhclient.in
hooks/nvidia
src/lxc/cmd/lxc-checkconfig.in
templates/lxc-busybox.in
templates/lxc-oci.in

index b2226f3faad1dcf904d58f61ac08092cc401066c..515945308b0c772ecb092cdfd91f7ab6b1427ec7 100644 (file)
@@ -31,7 +31,7 @@ use_nft() {
     [ -n "$NFT" ] && nft list ruleset > /dev/null 2>&1 && [ "$LXC_USE_NFT" = "true" ]
 }
 
-NFT="$(which nft)"
+NFT="$(command -v nft)"
 if ! use_nft; then
     use_iptables_lock="-w"
     iptables -w -L -n > /dev/null 2>&1 || use_iptables_lock=""
@@ -144,7 +144,7 @@ start() {
     # can't write its pid into, so we restorecon it (to var_run_t)
     if [ ! -d "${varrun}" ]; then
         mkdir -p "${varrun}"
-        if which restorecon >/dev/null 2>&1; then
+        if command -v restorecon >/dev/null 2>&1; then
             restorecon "${varrun}"
         fi
     fi
index df5640e9dc0b44c18c790c5f723392b533be6fa7..7ba9b87038bf5cfbf145e6f7b5d8683c6b0c1dcc 100755 (executable)
@@ -29,7 +29,7 @@ usage() {
 # Wrap the dhclient command with "aa-exec -p unconfined" if AppArmor is enabled.
 dhclient() {
     bin="/sbin/dhclient"
-    if [ -d "/sys/kernel/security/apparmor" ] && which aa-exec >/dev/null; then
+    if [ -d "/sys/kernel/security/apparmor" ] && command -v aa-exec >/dev/null; then
         bin="aa-exec -p unconfined ${bin}"
     fi
     echo $bin
index c105148087ae93171a3ac93f87d5f1410b691b79..f5146b411732bbfff672eb7a9e30d43aba996aee 100755 (executable)
@@ -45,7 +45,7 @@ else
 fi
 
 export PATH=$PATH:/usr/sbin:/usr/bin:/sbin:/bin
-if ! which nvidia-container-cli >/dev/null; then
+if ! command -v nvidia-container-cli >/dev/null; then
     echo "ERROR: Missing tool nvidia-container-cli, see https://github.com/NVIDIA/libnvidia-container" >&2
     exit 1
 fi
index 0953b76688dbebcfd6e49b7605949d48d05627c7..09aeff718c53f56005b661ce497a3eaf926ca144 100755 (executable)
@@ -128,16 +128,16 @@ echo
 echo -n "User namespace: " && is_enabled CONFIG_USER_NS
 echo
 if is_set CONFIG_USER_NS; then
-       if which newuidmap > /dev/null 2>&1; then
-               f=`which newuidmap`
+       if command -v newuidmap >/dev/null 2>&1; then
+               f=$(command -v newuidmap)
                if [ ! -u "${f}" ]; then
                        echo "Warning: newuidmap is not setuid-root"
                fi
        else
                echo "newuidmap is not installed"
        fi
-       if which newgidmap > /dev/null 2>&1; then
-               f=`which newgidmap`
+       if command -v newgidmap >/dev/null 2>&1; then
+               f=$(command -v newgidmap)
                if [ ! -u "${f}" ]; then
                        echo "Warning: newgidmap is not setuid-root"
                fi
index 632f9c8016241665c8f5f8f35d8b65e49f33dbd7..e8e62ca050513e82dba7e5933b6fef4c2c373182 100755 (executable)
@@ -23,7 +23,7 @@
 LXC_MAPPED_UID=
 LXC_MAPPED_GID=
 
-BUSYBOX_EXE=`which busybox`
+BUSYBOX_EXE=$(command -v busybox)
 
 # Make sure the usual locations are in PATH
 export PATH="$PATH:/usr/sbin:/usr/bin:/sbin:/bin"
index 06a0be5f6e149501420724f91db42d0c039877c5..7f7d01f8b19de90c655be6dde46d1d0db526827f 100755 (executable)
@@ -27,7 +27,7 @@ export PATH="$PATH:/usr/sbin:/usr/bin:/sbin:/bin"
 
 # Check for required binaries
 for bin in skopeo umoci jq; do
-  if ! which $bin >/dev/null 2>&1; then
+  if ! command -v $bin >/dev/null 2>&1; then
     echo "ERROR: Missing required tool: $bin" 1>&2
     exit 1
   fi
@@ -303,7 +303,7 @@ mkdir -p "${DOWNLOAD_BASE}"
 # Trap all exit signals
 trap cleanup EXIT HUP INT TERM
 
-if ! which mktemp >/dev/null 2>&1; then
+if ! command -v mktemp >/dev/null 2>&1; then
   DOWNLOAD_TEMP="${DOWNLOAD_BASE}/lxc-oci.$$"
   mkdir -p "${DOWNLOAD_TEMP}"
 else