From 2efc1d10b9bf1accfc434432c8c4f640aab71c3e Mon Sep 17 00:00:00 2001 From: FriendlyNeighborhoodShane Date: Thu, 24 Jun 2021 14:13:53 +0530 Subject: [PATCH] use `command -v` instead of `which` to determine tool availability. It's POSIX and also considers builtins. --- build.sh | 2 +- bump.sh | 2 +- res/util/func-defconf.sh | 2 +- res/util/func-resdl.sh | 4 ++-- src/META-INF/com/google/android/update-binary | 2 +- test.sh | 2 +- update.sh | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/build.sh b/build.sh index 47e8cf0..59392f9 100755 --- a/build.sh +++ b/build.sh @@ -25,7 +25,7 @@ echo "-- The Essentials only MicroG pack --"; modname="MinMicroG"; for bin in cp grep ls mv rm sed zip; do - [ "$(which $bin)" ] || abort "No $bin found"; + command -v "$bin" >/dev/null || abort "No $bin found"; done; echo " "; diff --git a/bump.sh b/bump.sh index 9439305..94dc8a7 100755 --- a/bump.sh +++ b/bump.sh @@ -23,7 +23,7 @@ echo "-- Minimal MicroG Test Script --"; echo "-- The Essentials only MicroG pack --"; for bin in printf sed; do - [ "$(which $bin)" ] || abort "No $bin found"; + command -v "$bin" >/dev/null || abort "No $bin found"; done; [ "$#" = "3" ] || abort "Not enough arguments"; diff --git a/res/util/func-defconf.sh b/res/util/func-defconf.sh index ba855c1..ef7bda9 100755 --- a/res/util/func-defconf.sh +++ b/res/util/func-defconf.sh @@ -80,7 +80,7 @@ microg_cleanup() { fi; done; fi; - if [ "$(which sqlite3)" ]; then + if command -v "sqlite3" >/dev/null; then find /data/system* -type f -name "accounts*db" 2>/dev/null | while read -r database; do log "PREPPER: deleting Google Accounts from $database"; sqlite3 "$database" "DELETE FROM accounts WHERE type='com.google';"; diff --git a/res/util/func-resdl.sh b/res/util/func-resdl.sh index 8c6bfb7..cd37c18 100755 --- a/res/util/func-resdl.sh +++ b/res/util/func-resdl.sh @@ -54,7 +54,7 @@ verifycerts() { [ "$stuff_repo" ] || echo "$stuff_download" | grep -qE "^[ ]*[^ ]+.apk[ ]+" || return 0; - [ "$(which jarsigner)" ] && [ "$(which openssl)" ] || { + command -v "jarsigner" >/dev/null && command -v "openssl" >/dev/null || { echo " "; echo " !! Not checking certificates (missing jarsigner or openssl)"; return 0; @@ -115,7 +115,7 @@ checkwhitelist() { echo "$stuff_download" | grep -qE "^[ ]*/system/priv-app/[^ ]+.apk[ ]+" || return 0; - [ "$(which aapt)" ] || { + command -v "aapt" >/dev/null || { echo " "; echo " !! Not checking privperms (missing aapt)"; return 0; diff --git a/src/META-INF/com/google/android/update-binary b/src/META-INF/com/google/android/update-binary index 3b77cb3..02c0b6b 100644 --- a/src/META-INF/com/google/android/update-binary +++ b/src/META-INF/com/google/android/update-binary @@ -102,7 +102,7 @@ $bootmode || { } for bin in chcon chmod chown cp cut df du echo find grep head mkdir mount ps rm sed tail touch umount unzip; do - [ "$(which "$bin")" ] || abort "No $bin available"; + command -v "$bin" >/dev/null || abort "No $bin available"; done; $bootmode && filedir="/dev/tmp/$modname" || filedir="/tmp/$modname"; diff --git a/test.sh b/test.sh index b4a3bba..c1e069e 100755 --- a/test.sh +++ b/test.sh @@ -19,7 +19,7 @@ echo "-- Minimal MicroG Test Script --"; echo "-- The Essentials only MicroG pack --"; for bin in shellcheck; do - [ "$(which $bin)" ] || abort "No $bin found"; + command -v "$bin" >/dev/null || abort "No $bin found"; done; # These tests are only excluded in the command because they're pointless diff --git a/update.sh b/update.sh index 9b25b99..38a32aa 100755 --- a/update.sh +++ b/update.sh @@ -40,7 +40,7 @@ echo "-- The Essentials Only MicroG Pack --"; # Bin check for bin in chmod cp curl grep head jq mv rm sort tr unzip; do - [ "$(which $bin)" ] || abort "No $bin found"; + command -v "$bin" >/dev/null || abort "No $bin found"; done; echo " ";