From ef93ecf54b199828e59fe92f181cc84aa46fe79a Mon Sep 17 00:00:00 2001 From: Ian Leonard Date: Thu, 4 Oct 2018 07:24:55 +0000 Subject: [PATCH] scripts/checkdeps: cleanup Replace "which" with "command -v", which is part of POSIX. Make offering to install packages contingent on having the sudo command. Not every distro uses sudo. It is optional in Gentoo, for example. Signed-off-by: Ian Leonard --- scripts/checkdeps | 62 +++++++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 29 deletions(-) diff --git a/scripts/checkdeps b/scripts/checkdeps index 82268c3b8d..fcff945cca 100755 --- a/scripts/checkdeps +++ b/scripts/checkdeps @@ -41,7 +41,7 @@ get_deps() { get_yes_no() { local ans - read -p "Would you like to install the needed tools ? (y/n) " ans + read -p "Would you like to install the needed tools? (y/n) " ans [ "${ans,,}" = "y" ] && return 0 [ "${ans,,}" = "yes" ] && return 0 return 1 @@ -132,34 +132,38 @@ if [ "${#need[@]}" -gt 0 ]; then done echo "**** You seem to use a $DISTRO system ****" - case "$DISTRO" in - ubuntu|debian|linuxmint|\"elementary\") - get_yes_no && sudo apt-get install "${need_pkg[@]}" - ;; - fedora|centos|rhel) - if [ $(which dnf) ]; then YUM=dnf; else YUM=yum; fi - get_yes_no && sudo $YUM install "${need_pkg[@]}" - ;; - gentoo) - get_yes_no && sudo emerge --ask --deep "${need_pkg[@]}" - ;; - sabayon) - get_yes_no && sudo equo install --ask "${need_pkg[@]}" - ;; - mageia) - get_yes_no && sudo urpmi "${need_pkg[@]}" - ;; - arch) - get_yes_no && sudo pacman -Sy "${need_pkg[@]}" - ;; - opensuse) - get_yes_no && sudo zypper install -y --no-recommends "${need_pkg[@]}" - ;; - *) - echo "**** unsupported distro $DISTRO ****" - exit 1 - ;; - esac + if command -v sudo >/dev/null; then + case "$DISTRO" in + ubuntu|debian|linuxmint|\"elementary\") + get_yes_no && sudo apt-get install "${need_pkg[@]}" + ;; + fedora|centos|rhel) + command -v dnf >/dev/null && YUM=dnf || YUM=yum + get_yes_no && sudo $YUM install "${need_pkg[@]}" + ;; + gentoo) + get_yes_no && sudo emerge --ask --deep "${need_pkg[@]}" + ;; + sabayon) + get_yes_no && sudo equo install --ask "${need_pkg[@]}" + ;; + mageia) + get_yes_no && sudo urpmi "${need_pkg[@]}" + ;; + arch) + get_yes_no && sudo pacman -Sy "${need_pkg[@]}" + ;; + opensuse) + get_yes_no && sudo zypper install -y --no-recommends "${need_pkg[@]}" + ;; + *) + echo "**** unsupported distro $DISTRO ****" + exit 1 + ;; + esac + else + echo "The command 'sudo' was not found. Please install necessary packages manually." + fi fi get_deps