commit:     04225e090e9936df6c5a9ddd5a3926d13e0001df
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Thu Jul 27 10:53:28 2023 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Thu Jul 27 10:53:28 2023 +0000
URL:        https://gitweb.gentoo.org/proj/genkernel.git/commit/?id=04225e09

Replace use of `which`

We're trying to phase it out as it's non-portable. Use bash's `type -P` where
available (preferable as it avoids user functions) or `command -v` if POSIX.

Signed-off-by: Sam James <sam <AT> gentoo.org>

 gen_configkernel.sh  |  2 +-
 gen_determineargs.sh | 14 +++++++-------
 gen_funcs.sh         |  4 ++--
 netboot/linuxrc.x    |  2 +-
 4 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/gen_configkernel.sh b/gen_configkernel.sh
index 62113dc..44a06b3 100755
--- a/gen_configkernel.sh
+++ b/gen_configkernel.sh
@@ -231,7 +231,7 @@ set_initramfs_compression_method() {
 }
 
 config_kernel() {
-       local diff_cmd="$(which zdiff 2>/dev/null)"
+       local diff_cmd="$(type -P zdiff 2>/dev/null)"
        if [ -z "${diff_cmd}" ]
        then
                print_warning 5 "zdiff is not available."

diff --git a/gen_determineargs.sh b/gen_determineargs.sh
index fd3a4ae..ed9b1bc 100755
--- a/gen_determineargs.sh
+++ b/gen_determineargs.sh
@@ -970,7 +970,7 @@ determine_real_args() {
                then
                        if [[ "${CMD_BOOTFONT}" == "current" ]]
                        then
-                               SETFONT_COMMAND="$(which setfont 2>/dev/null)"
+                               SETFONT_COMMAND="$(type -P setfont 2>/dev/null)"
                                if [ -z "${SETFONT_COMMAND}" ]
                                then
                                        gen_die "setfont not found. Is 
sys-apps/kbd installed?"
@@ -1138,15 +1138,15 @@ determine_real_args() {
                        fi
                fi
 
-               DU_COMMAND="$(which du 2>/dev/null)"
+               DU_COMMAND="$(type -P du 2>/dev/null)"
 
-               LDDTREE_COMMAND="$(which lddtree 2>/dev/null)"
+               LDDTREE_COMMAND="$(type -P lddtree 2>/dev/null)"
                if [ -z "${LDDTREE_COMMAND}" ]
                then
                        gen_die "lddtree not found. Is app-misc/pax-utils 
installed?"
                fi
 
-               CPIO_COMMAND="$(which cpio 2>/dev/null)"
+               CPIO_COMMAND="$(type -P cpio 2>/dev/null)"
                if [[ -z "${CPIO_COMMAND}" ]]
                then
                        # This will be fatal because we cpio either way
@@ -1191,7 +1191,7 @@ determine_real_args() {
                                gen_die "SANDBOX_ON=1 detected -- You cannot 
use --sandbox when already running within a sandbox!"
                        fi
 
-                       SANDBOX_COMMAND="$(which sandbox 2>/dev/null)"
+                       SANDBOX_COMMAND="$(type -P sandbox 2>/dev/null)"
                        if [ -z "${SANDBOX_COMMAND}" ]
                        then
                                gen_die "Sandbox not found. Is sys-apps/sandbox 
installed?"
@@ -1215,7 +1215,7 @@ determine_real_args() {
 
        if isTrue "${need_tar}"
        then
-               TAR_COMMAND="$(which tar 2>/dev/null)"
+               TAR_COMMAND="$(type -P tar 2>/dev/null)"
                if [ -z "${TAR_COMMAND}" ]
                then
                        gen_die "tar not found. Is app-arch/tar installed?"
@@ -1230,7 +1230,7 @@ determine_real_args() {
                fi
        fi
 
-       KMOD_CMD=$(which kmod 2>/dev/null)
+       KMOD_CMD=$(type -P kmod 2>/dev/null)
        if ! isTrue "${BUILD_STATIC}"
        then
                if [ -z "${KMOD_CMD}" ]

diff --git a/gen_funcs.sh b/gen_funcs.sh
index 176fa14..476f5ee 100755
--- a/gen_funcs.sh
+++ b/gen_funcs.sh
@@ -1121,13 +1121,13 @@ get_tar_cmd() {
        local pcmd
        if [[ "${archive_file}" == *.tar.bz2 ]]
        then
-               pcmd=$(which pbzip2 2>/dev/null)
+               pcmd=$(type -P pbzip2 2>/dev/null)
        elif [[ "${archive_file}" == *.tar.xz ]]
        then
                pcmd="'xz -T$(makeopts_jobs)'"
        elif [[ "${archive_file}" == *.tar.gz ]]
        then
-               pcmd=$(which pigz 2>/dev/null)
+               pcmd=$(type -P pigz 2>/dev/null)
        fi
 
        if [ -n "${pcmd}" ]

diff --git a/netboot/linuxrc.x b/netboot/linuxrc.x
index 88a2aa7..e607141 100644
--- a/netboot/linuxrc.x
+++ b/netboot/linuxrc.x
@@ -97,7 +97,7 @@ StartUp() {
                #// Hostname
                hostname netboot
 
-               if [ -n "$(which dropbear 2>/dev/null)" ]
+               if [ -n "$(command -v dropbear 2>/dev/null)" ]
                then
                        # Setup dropbear (sshd)
                        echo

Reply via email to