From a27cccaba56ebe6d37cc6b17af88559d70b6342e Mon Sep 17 00:00:00 2001 From: Vadim Kurland Date: Sun, 2 Oct 2011 15:45:56 -0700 Subject: [PATCH] see SF bug #3416900 "Replace `command` with `which`". Generated script (Linux/iptables) used to use "command -v" to check if command line tools it needs are present on the system. This was used to find iptables, lsmod, modprobe, ifconfig, vconfig, logger and others. Some embedded Linux distributions, notably TomatoUSB, come without support for "command". Switching to "which" that is more ubuquitous and should be available pretty much everywhere. --- doc/ChangeLog | 11 +++++++++++ src/res/configlets/dd-wrt-jffs/check_utilities | 8 +------- src/res/configlets/dd-wrt-nvram/check_utilities | 10 +--------- src/res/configlets/ipcop/shell_functions | 2 +- src/res/configlets/linux24/check_utilities | 10 +--------- src/res/configlets/linux24/shell_functions | 2 +- src/res/configlets/openwrt/check_utilities | 10 +--------- src/res/configlets/sveasoft/shell_functions | 2 +- src/res/help/en_US/release_notes_5.0.1.html | 14 ++++++++++++++ 9 files changed, 32 insertions(+), 37 deletions(-) diff --git a/doc/ChangeLog b/doc/ChangeLog index 3fc6deb71..f2d4bfbcb 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,14 @@ +2011-10-02 Vadim Kurland + + * shell_functions: see SF bug #3416900 "Replace `command` with + `which`". Generated script (Linux/iptables) used to use "command + -v" to check if command line tools it needs are present on the + system. This was used to find iptables, lsmod, modprobe, ifconfig, + vconfig, logger and others. Some embedded Linux distributions, + notably TomatoUSB, come without support for "command". Switching to + "which" that is more ubuquitous and should be available pretty + much everywhere. + 2011-09-29 Vadim Kurland * SSHSession.cpp (startSession): enable fwbuilder to take diff --git a/src/res/configlets/dd-wrt-jffs/check_utilities b/src/res/configlets/dd-wrt-jffs/check_utilities index 8c33bf494..9b46877f6 100644 --- a/src/res/configlets/dd-wrt-jffs/check_utilities +++ b/src/res/configlets/dd-wrt-jffs/check_utilities @@ -28,16 +28,10 @@ ## These variables are set in OSConfigurator_linux24::printShellFunctions() ## About using "command" to find programs: ## -## apparently "command" is POSIX compliant and should be widely -## available. Another tool that could be used is "type -P" but that is -## bash built-in -## -## Verified DD-WRT v24 and OpenWRT kamikaze 8.09.2 both have command -## and type (both use busybox) find_program() { PGM=$1 - command -v $PGM >/dev/null 2>&1 || { + which $PGM >/dev/null 2>&1 || { echo "$PGM not found" exit 1 } diff --git a/src/res/configlets/dd-wrt-nvram/check_utilities b/src/res/configlets/dd-wrt-nvram/check_utilities index 1b5ea107f..7d8d50de3 100644 --- a/src/res/configlets/dd-wrt-nvram/check_utilities +++ b/src/res/configlets/dd-wrt-nvram/check_utilities @@ -27,18 +27,10 @@ ## ## These variables are set in OSConfigurator_linux24::printShellFunctions() ## -## About using "command" to find programs: -## -## apparently "command" is POSIX compliant and should be widely -## available. Another tool that could be used is "type -P" but that is -## bash built-in -## -## Verified DD-WRT v24 and OpenWRT kamikaze 8.09.2 both have command -## and type (both use busybox) find_program() { PGM=$1 - command -v $PGM >/dev/null 2>&1 || { + which $PGM >/dev/null 2>&1 || { echo "$PGM not found" exit 1 } diff --git a/src/res/configlets/ipcop/shell_functions b/src/res/configlets/ipcop/shell_functions index eadddaec9..b0402ddc7 100644 --- a/src/res/configlets/ipcop/shell_functions +++ b/src/res/configlets/ipcop/shell_functions @@ -13,7 +13,7 @@ log() { echo "$1" - command -v "$LOGGER" >/dev/null 2>&1 && $LOGGER -p info "$1" + which "$LOGGER" >/dev/null 2>&1 && $LOGGER -p info "$1" } check_file() { diff --git a/src/res/configlets/linux24/check_utilities b/src/res/configlets/linux24/check_utilities index e498bb722..c198665bc 100644 --- a/src/res/configlets/linux24/check_utilities +++ b/src/res/configlets/linux24/check_utilities @@ -27,18 +27,10 @@ ## ## These variables are set in OSConfigurator_linux24::printShellFunctions() ## -## About using "command" to find programs: -## -## apparently "command" is POSIX compliant and should be widely -## available. Another tool that could be used is "type -P" but that is -## bash built-in -## -## Verified DD-WRT v24 and OpenWRT kamikaze 8.09.2 both have command -## and type (both use busybox) find_program() { PGM=$1 - command -v $PGM >/dev/null 2>&1 || { + which $PGM >/dev/null 2>&1 || { echo "$PGM not found" exit 1 } diff --git a/src/res/configlets/linux24/shell_functions b/src/res/configlets/linux24/shell_functions index 62d0f9395..77b7a68ff 100644 --- a/src/res/configlets/linux24/shell_functions +++ b/src/res/configlets/linux24/shell_functions @@ -2,7 +2,7 @@ log() { echo "$1" - command -v "$LOGGER" >/dev/null 2>&1 && $LOGGER -p info "$1" + which "$LOGGER" >/dev/null 2>&1 && $LOGGER -p info "$1" } getInterfaceVarName() { diff --git a/src/res/configlets/openwrt/check_utilities b/src/res/configlets/openwrt/check_utilities index 319a2f908..aebc31110 100644 --- a/src/res/configlets/openwrt/check_utilities +++ b/src/res/configlets/openwrt/check_utilities @@ -11,18 +11,10 @@ ## {{$var}} is variable expansion ## {{if var}} is conditional operator. ## -## About using "command" to find programs: -## -## apparently "command" is POSIX compliant and should be widely -## available. Another tool that could be used is "type -P" but that is -## bash built-in -## -## Verified DD-WRT v24 and OpenWRT kamikaze 8.09.2 both have command -## and type (both use busybox) find_program() { PGM=$1 - command -v $PGM >/dev/null 2>&1 || { + which $PGM >/dev/null 2>&1 || { echo "$PGM not found" exit 1 } diff --git a/src/res/configlets/sveasoft/shell_functions b/src/res/configlets/sveasoft/shell_functions index e624cb359..b9472208d 100644 --- a/src/res/configlets/sveasoft/shell_functions +++ b/src/res/configlets/sveasoft/shell_functions @@ -13,7 +13,7 @@ log() { echo "$1" - command -v "$LOGGER" >/dev/null 2>&1 && $LOGGER -p info "$1" + which "$LOGGER" >/dev/null 2>&1 && $LOGGER -p info "$1" } check_file() { diff --git a/src/res/help/en_US/release_notes_5.0.1.html b/src/res/help/en_US/release_notes_5.0.1.html index 0904ca573..fdae6e5b6 100644 --- a/src/res/help/en_US/release_notes_5.0.1.html +++ b/src/res/help/en_US/release_notes_5.0.1.html @@ -233,6 +233,20 @@ was used in the "Interface" column of a policy rule.

+ +
  • +

    + see SF bug #3416900 "Replace `command` with `which`". Generated + script (Linux/iptables) used to use "command -v" to check if + command line tools it needs are present on the system. This was + used to find iptables, lsmod, modprobe, ifconfig, vconfig, + logger and others. Some embedded Linux distributions, notably + TomatoUSB, come without support for "command". Switching to + "which" that is more ubuquitous and should be available pretty + much everywhere. +

    +
  • +