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 <antonlacon@gmail.com>
This commit is contained in:
Ian Leonard 2018-10-04 07:24:55 +00:00
parent df1cffa51e
commit ef93ecf54b

View File

@ -41,7 +41,7 @@ get_deps() {
get_yes_no() get_yes_no()
{ {
local ans 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,,}" = "y" ] && return 0
[ "${ans,,}" = "yes" ] && return 0 [ "${ans,,}" = "yes" ] && return 0
return 1 return 1
@ -132,34 +132,38 @@ if [ "${#need[@]}" -gt 0 ]; then
done done
echo "**** You seem to use a $DISTRO system ****" echo "**** You seem to use a $DISTRO system ****"
case "$DISTRO" in if command -v sudo >/dev/null; then
ubuntu|debian|linuxmint|\"elementary\") case "$DISTRO" in
get_yes_no && sudo apt-get install "${need_pkg[@]}" 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 fedora|centos|rhel)
get_yes_no && sudo $YUM install "${need_pkg[@]}" 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[@]}" gentoo)
;; get_yes_no && sudo emerge --ask --deep "${need_pkg[@]}"
sabayon) ;;
get_yes_no && sudo equo install --ask "${need_pkg[@]}" sabayon)
;; get_yes_no && sudo equo install --ask "${need_pkg[@]}"
mageia) ;;
get_yes_no && sudo urpmi "${need_pkg[@]}" mageia)
;; get_yes_no && sudo urpmi "${need_pkg[@]}"
arch) ;;
get_yes_no && sudo pacman -Sy "${need_pkg[@]}" arch)
;; get_yes_no && sudo pacman -Sy "${need_pkg[@]}"
opensuse) ;;
get_yes_no && sudo zypper install -y --no-recommends "${need_pkg[@]}" opensuse)
;; get_yes_no && sudo zypper install -y --no-recommends "${need_pkg[@]}"
*) ;;
echo "**** unsupported distro $DISTRO ****" *)
exit 1 echo "**** unsupported distro $DISTRO ****"
;; exit 1
esac ;;
esac
else
echo "The command 'sudo' was not found. Please install necessary packages manually."
fi
fi fi
get_deps get_deps