From e23ee4c21c6d8045ab020526aa864a48dc16ddd9 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Mon, 7 Dec 2015 00:09:10 +0100 Subject: [PATCH] part revert, part redo 'which' replacement MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit In e75e5879 'replace "which" with "command -v" for portability' I missed that command -v isn't actually required to be available in debian, so for the 5 files we are using it: Two (abicheck/run_abi_test & test/integration/framework) are called in environments were I believe sh is at least dash or 'better' as the first one is "interactive" for apt developers and the later is sourced by ~200 tests in the same directory run by hand and ci-services – for the later we have pulled some uglier hacks for worser things already, so if there should actually end up needing something more compatible we will notice eventually (and the later actually had a command -v call for some time already and nobody came running). debian/rules and debian/apt.cron.daily I switched back to which as that is more or less debian-specific or at least highly non-critical. That leaves cmdline/apt-key.in with a bunch of calls where I will implement that functionality in shell as this is relatively short-lived as it is used to detect wget (for net-update, which Michael wants to revive and in that process will properly use apt-helper instead of wget) and to detect gpg vs. gpg2 systems, where the earlier is supposed to go away in the longrun (or the later, but by replacing the earlier…). [and this gpg/gpg2 detection is new in sid, so I have some sympathy for that being a problem now.] Thanks: Jakub Wilk for pointing out #747320 --- cmdline/apt-key.in | 29 ++++++++++++++++++++++------- debian/apt.cron.daily | 10 +++++----- debian/rules | 2 +- 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/cmdline/apt-key.in b/cmdline/apt-key.in index 790859e26..f1d021e8a 100644 --- a/cmdline/apt-key.in +++ b/cmdline/apt-key.in @@ -25,6 +25,21 @@ requires_root() { fi } +command_available() { + # command -v "$1" >/dev/null 2>&1 # not required by policy, see #747320 + # which "$1" >/dev/null 2>&1 # is in debianutils (essential) but not on non-debian systems + local OLDIFS="$IFS" + IFS=: + for p in $PATH; do + if [ -x "${p}/${1}" ]; then + IFS="$OLDIFS" + return 0 + fi + done + IFS="$OLDIFS" + return 1 +} + get_fingerprints_of_keyring() { aptkey_execute "$GPG_SH" --keyring "$1" --with-colons --fingerprint | while read publine; do # search for a public key @@ -112,7 +127,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 ! command -v wget >/dev/null 2>&1; then + if ! command_available 'wget'; then echo >&2 "ERROR: an installed wget is required for a network-based update" exit 1 fi @@ -472,11 +487,11 @@ create_gpg_home() { prepare_gpg_home() { eval $(apt-config shell GPG_EXE Apt::Key::gpgcommand) - if [ -n "$GPG_EXE" ] && command -v "$GPG_EXE" >/dev/null 2>&1; then + if [ -n "$GPG_EXE" ] && command_available "$GPG_EXE"; then true - elif command -v gpg >/dev/null 2>&1; then + elif command_available 'gpg'; then GPG_EXE="gpg" - elif command -v gpg2 >/dev/null 2>&1; then + elif command_available 'gpg2'; then GPG_EXE="gpg2" else echo >&2 "Error: gnupg or gnupg2 do not seem to be installed," @@ -569,9 +584,9 @@ case "$command" in verify) GPGV='' eval $(apt-config shell GPGV Apt::Key::gpgvcommand) - 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'; + if [ -n "$GPGV" ] && command_available "$GPGV"; then true; + elif command_available 'gpgv'; then GPGV='gpgv'; + elif command_available 'gpgv2'; then GPGV='gpgv2'; else echo >&2 'ERROR: gpgv or gpgv2 required for verification' exit 29 diff --git a/debian/apt.cron.daily b/debian/apt.cron.daily index 978f06ab6..765dd4ae4 100644 --- a/debian/apt.cron.daily +++ b/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 command -v on_ac_power >/dev/null 2>&1; then + if which on_ac_power >/dev/null; 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 ! command -v apt-config >/dev/null 2>&1; then +if ! which apt-config >/dev/null ; 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 command -v apt-get >/dev/null 2>&1 && ! eval apt-get check $XAPTOPT $XSTDERR ; then +if which apt-get >/dev/null && ! 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 command -v dbus-send >/dev/null 2>&1 && pidof dbus-daemon >/dev/null; then + if which dbus-send >/dev/null && 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 command -v unattended-upgrade >/dev/null 2>&1 && check_stamp $UPGRADE_STAMP $UnattendedUpgradeInterval; then +if which unattended-upgrade >/dev/null && check_stamp $UPGRADE_STAMP $UnattendedUpgradeInterval; then if unattended-upgrade $XUUPOPT; then update_stamp $UPGRADE_STAMP debug_echo "unattended-upgrade (success)" diff --git a/debian/rules b/debian/rules index db59d2898..c8e7cb285 100755 --- a/debian/rules +++ b/debian/rules @@ -24,7 +24,7 @@ confflags += --with-procs=$(PARALLEL) # See below -include build/environment.mak -ifneq (,$(shell command -v dpkg-buildflags)) +ifneq (,$(shell which 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 -- 2.45.2