Add is_fedora and exit_distro_not_supported functions
Between is_fedora, is_ubuntu and is_suse, we can make the code a bit
simpler to read. We also use exit_distro_not_supported to identify
places where we need implementation details for new distros.
As "/sbin/service --skip-redirect" is Fedora-specific, guard this with a
is_fedora test too.
Change-Id: Ic77c0697ed9be0dbb5df8e73da93463e76025f0c
diff --git a/functions b/functions
index 0911557..3ee43d3 100644
--- a/functions
+++ b/functions
@@ -354,6 +354,18 @@
}
+# Determine if current distribution is a Fedora-based distribution
+# (Fedora, RHEL, CentOS).
+# is_fedora
+function is_fedora {
+ if [[ -z "$os_VENDOR" ]]; then
+ GetOSVersion
+ fi
+
+ [ "$os_VENDOR" = "Fedora" ] || [ "$os_VENDOR" = "Red Hat" ] || [ "$os_VENDOR" = "CentOS" ]
+}
+
+
# Determine if current distribution is a SUSE-based distribution
# (openSUSE, SLE).
# is_suse
@@ -366,6 +378,23 @@
}
+# Exit after outputting a message about the distribution not being supported.
+# exit_distro_not_supported [optional-string-telling-what-is-missing]
+function exit_distro_not_supported {
+ if [[ -z "$DISTRO" ]]; then
+ GetDistro
+ fi
+
+ if [ $# -gt 0 ]; then
+ echo "Support for $DISTRO is incomplete: no support for $@"
+ else
+ echo "Support for $DISTRO is incomplete."
+ fi
+
+ exit 1
+}
+
+
# git clone only if directory doesn't exist already. Since ``DEST`` might not
# be owned by the installation user, we create the directory and change the
# ownership to the proper user.
@@ -598,12 +627,12 @@
NO_UPDATE_REPOS=True
apt_get install "$@"
+ elif is_fedora; then
+ yum_install "$@"
+ elif is_suse; then
+ zypper_install "$@"
else
- if is_suse; then
- zypper_install "$@"
- else
- yum_install "$@"
- fi
+ exit_distro_not_supported "installing packages"
fi
}
@@ -622,9 +651,11 @@
if [[ "$os_PACKAGE" = "deb" ]]; then
dpkg -l "$@" > /dev/null
return $?
- else
+ elif [[ "$os_PACKAGE" = "rpm" ]]; then
rpm --quiet -q "$@"
return $?
+ else
+ exit_distro_not_supported "finding if a package is installed"
fi
}
@@ -1032,20 +1063,20 @@
function get_rootwrap_location() {
local module=$1
- if is_ubuntu || is_suse; then
- echo "/usr/local/bin/$module-rootwrap"
- else
+ if is_fedora; then
echo "/usr/bin/$module-rootwrap"
+ else
+ echo "/usr/local/bin/$module-rootwrap"
fi
}
# Get the path to the pip command.
# get_pip_command
function get_pip_command() {
- if is_ubuntu || is_suse; then
- echo "/usr/bin/pip"
- else
+ if is_fedora; then
echo "/usr/bin/pip-python"
+ else
+ echo "/usr/bin/pip"
fi
}