Procházet zdrojové kódy

replace "which" with "command -v" for portability

which is a debian specific tool packaged in debianutils (essential)
while command is a shell builtin defined by POSIX.

Closes: 807144
Thanks: Mingye Wang for the suggestion.
David Kalnischkies před 10 roky
rodič
revize
e75e5879c0
5 změnil soubory, kde provedl 15 přidání a 15 odebrání
  1. 1 1
      abicheck/run_abi_test
  2. 7 7
      cmdline/apt-key.in
  3. 5 5
      debian/apt.cron.daily
  4. 1 1
      debian/rules
  5. 1 1
      test/integration/framework

+ 1 - 1
abicheck/run_abi_test

@@ -8,7 +8,7 @@ if [ ! -d ../build ]; then
 	exit 1
 fi
 
-if [ ! -x "$(which abi-compliance-checker 2>/dev/null )" ]; then
+if command -v abi-compliance-checker 2>/dev/null >&2; then
 	echo "Please install the 'abi-compliance-checker' package"
 	exit 1
 fi

+ 7 - 7
cmdline/apt-key.in

@@ -112,7 +112,7 @@ net_update() {
     fi
     # in theory we would need to depend on wget for this, but this feature
     # isn't useable in debian anyway as we have no keyring uri nor a master key
-    if ! which wget >/dev/null 2>&1; then
+    if ! command -v wget >/dev/null 2>&1; then
 	echo >&2 "ERROR: an installed wget is required for a network-based update"
 	exit 1
     fi
@@ -472,11 +472,11 @@ create_gpg_home() {
 prepare_gpg_home() {
     eval $(apt-config shell GPG_EXE Apt::Key::gpgcommand)
 
-    if [ -n "$GPG_EXE" ] && which "$GPG_EXE" >/dev/null 2>&1; then
+    if [ -n "$GPG_EXE" ] && command -v "$GPG_EXE" >/dev/null 2>&1; then
 	true
-    elif which gpg >/dev/null 2>&1; then
+    elif command -v gpg >/dev/null 2>&1; then
 	GPG_EXE="gpg"
-    elif which gpg2 >/dev/null 2>&1; then
+    elif command -v gpg2 >/dev/null 2>&1; then
 	GPG_EXE="gpg2"
     else
 	echo >&2 "Error: gnupg or gnupg2 do not seem to be installed,"
@@ -569,9 +569,9 @@ case "$command" in
     verify)
 	GPGV=''
 	eval $(apt-config shell GPGV Apt::Key::gpgvcommand)
-	if [ -n "$GPGV" ] && which "$GPGV" >/dev/null 2>&1; then true;
-	elif which gpgv >/dev/null 2>&1; then GPGV='gpgv';
-	elif which gpgv2 >/dev/null 2>&1; then GPGV='gpgv2';
+	if [ -n "$GPGV" ] && command -v "$GPGV" >/dev/null 2>&1; then true;
+	elif command -v gpgv >/dev/null 2>&1; then GPGV='gpgv';
+	elif command -v gpgv2 >/dev/null 2>&1; then GPGV='gpgv2';
 	else
 	   echo >&2 'ERROR: gpgv or gpgv2 required for verification'
 	   exit 29

+ 5 - 5
debian/apt.cron.daily

@@ -324,7 +324,7 @@ check_power(){
     #       1 (false)   System is not on main power
     #       255 (false) Power status could not be determined
     # Desktop systems always return 255 it seems
-    if which on_ac_power >/dev/null; then
+    if command -v on_ac_power >/dev/null 2>&1; then
         on_ac_power
         POWER=$?
         if [ $POWER -eq 1 ]; then
@@ -352,7 +352,7 @@ if test -r /var/lib/apt/extended_states; then
 fi
 
 # check apt-config existence
-if ! which apt-config >/dev/null ; then
+if ! command -v apt-config >/dev/null 2>&1; then
 	exit 0
 fi
 
@@ -388,7 +388,7 @@ fi
 check_power || exit 0
 
 # check if we can lock the cache and if the cache is clean
-if which apt-get >/dev/null && ! eval apt-get check $XAPTOPT $XSTDERR ; then
+if command -v apt-get >/dev/null 2>&1 && ! eval apt-get check $XAPTOPT $XSTDERR ; then
     debug_echo "error encountered in cron job with \"apt-get check\"."
     exit 0
 fi
@@ -451,7 +451,7 @@ UPDATE_STAMP=/var/lib/apt/periodic/update-stamp
 if check_stamp $UPDATE_STAMP $UpdateInterval; then
     if eval apt-get $XAPTOPT -y update $XSTDERR; then
 	debug_echo "download updated metadata (success)."
-	if which dbus-send >/dev/null && pidof dbus-daemon >/dev/null; then
+	if command -v dbus-send >/dev/null 2>&1 && pidof dbus-daemon >/dev/null; then
 	    if dbus-send --system / app.apt.dbus.updated boolean:true ; then
 		debug_echo "send dbus signal (success)"
 	    else
@@ -487,7 +487,7 @@ fi
 
 # auto upgrade all upgradeable packages
 UPGRADE_STAMP=/var/lib/apt/periodic/upgrade-stamp
-if which unattended-upgrade >/dev/null && check_stamp $UPGRADE_STAMP $UnattendedUpgradeInterval; then
+if command -v unattended-upgrade >/dev/null 2>&1 && check_stamp $UPGRADE_STAMP $UnattendedUpgradeInterval; then
     if unattended-upgrade $XUUPOPT; then
 	update_stamp $UPGRADE_STAMP
 	debug_echo "unattended-upgrade (success)"

+ 1 - 1
debian/rules

@@ -24,7 +24,7 @@ confflags += --with-procs=$(PARALLEL)
 # See below
 -include build/environment.mak
 
-ifneq (,$(shell which dpkg-buildflags))
+ifneq (,$(shell command -v dpkg-buildflags))
   # make does not export to $(shell) so we need to workaround 
   # (http://savannah.gnu.org/bugs/?10593)
   dpkg_buildflags = DEB_BUILD_MAINT_OPTIONS=hardening=+all dpkg-buildflags

+ 1 - 1
test/integration/framework

@@ -1205,7 +1205,7 @@ changetowebserver() {
 }
 
 changetohttpswebserver() {
-	if ! which stunnel4 >/dev/null; then
+	if ! command -v stunnel4 >/dev/null 2>&1; then
 		msgdie 'You need to install stunnel4 for https testcases'
 	fi
 	if [ ! -e "${TMPWORKINGDIRECTORY}/aptarchive/aptwebserver.pid" ]; then