Add is_package_installed function to know if a package is installed
This helps reduce the distro-dependent code in stack.sh, and also fixes
the bug where "rpm -qa | grep sudo" will work if gnome-sudoku is
installed.
Rebased
Change-Id: Ib1330b29b915b41d9724197edd791f0d4e0fe373
diff --git a/stack.sh b/stack.sh
index 687e5bf..2c488b4 100755
--- a/stack.sh
+++ b/stack.sh
@@ -182,11 +182,7 @@
sleep $ROOTSLEEP
# Give the non-root user the ability to run as **root** via ``sudo``
- if [[ "$os_PACKAGE" = "deb" ]]; then
- dpkg -l sudo || install_package sudo
- else
- rpm -qa | grep sudo || install_package sudo
- fi
+ is_package_installed sudo || install_package sudo
if ! getent group stack >/dev/null; then
echo "Creating a group called stack"
groupadd stack
@@ -215,12 +211,7 @@
exit 1
else
# We're not **root**, make sure ``sudo`` is available
- if [[ "$os_PACKAGE" = "deb" ]]; then
- CHECK_SUDO_CMD="dpkg -l sudo"
- else
- CHECK_SUDO_CMD="rpm -q sudo"
- fi
- $CHECK_SUDO_CMD || die "Sudo is required. Re-run stack.sh as root ONE TIME ONLY to set up sudo."
+ is_package_installed sudo || die "Sudo is required. Re-run stack.sh as root ONE TIME ONLY to set up sudo."
# UEC images ``/etc/sudoers`` does not have a ``#includedir``, add one
sudo grep -q "^#includedir.*/etc/sudoers.d" /etc/sudoers ||