installer: Abstract out apt/yum divide into a variable.

This check is done in several places, using a somewhat fragile `case`
statement; move it into an explicit variable.
This commit is contained in:
Alex Vandiver
2020-06-23 21:22:54 +00:00
committed by Tim Abbott
parent 876ee4a8ed
commit 85dbb13c56

View File

@@ -115,6 +115,14 @@ export LANGUAGE="en_US.UTF-8"
if [ -f /etc/os-release ]; then if [ -f /etc/os-release ]; then
os_info="$(. /etc/os-release; printf '%s\n' "$ID" "$ID_LIKE" "$VERSION_ID" "$VERSION_CODENAME")" os_info="$(. /etc/os-release; printf '%s\n' "$ID" "$ID_LIKE" "$VERSION_ID" "$VERSION_CODENAME")"
{ read -r os_id; read -r os_id_like; read -r os_version_id; read -r os_version_codename || true; } <<< "$os_info" { read -r os_id; read -r os_id_like; read -r os_version_id; read -r os_version_codename || true; } <<< "$os_info"
case " $os_id $os_id_like " in
*' debian '*)
package_system="apt"
;;
*' rhel '*)
package_system="yum"
;;
esac
fi fi
case "$os_id$os_version_id" in case "$os_id$os_version_id" in
@@ -169,15 +177,12 @@ if [ "$mem_kb" -lt 1860000 ]; then
fi fi
# Do package update, e.g. do `apt-get update` on Debian # Do package update, e.g. do `apt-get update` on Debian
case " $os_id $os_id_like " in if [ "$package_system" = apt ]; then
*' debian '*) # setup-apt-repo does an `apt-get update`
# setup-apt-repo does an `apt-get update` "$ZULIP_PATH"/scripts/lib/setup-apt-repo
"$ZULIP_PATH"/scripts/lib/setup-apt-repo elif [ "$package_system" = yum ]; then
;; "$ZULIP_PATH"/scripts/lib/setup-yum-repo
*' rhel '*) fi
"$ZULIP_PATH"/scripts/lib/setup-yum-repo
;;
esac
# Check early for missing SSL certificates # Check early for missing SSL certificates
if [ "$PUPPET_CLASSES" = "zulip::voyager" ] && [ -z "$USE_CERTBOT""$SELF_SIGNED_CERT" ] && { ! [ -e "/etc/ssl/private/zulip.key" ] || ! [ -e "/etc/ssl/certs/zulip.combined-chain.crt" ]; }; then if [ "$PUPPET_CLASSES" = "zulip::voyager" ] && [ -z "$USE_CERTBOT""$SELF_SIGNED_CERT" ] && { ! [ -e "/etc/ssl/private/zulip.key" ] || ! [ -e "/etc/ssl/certs/zulip.combined-chain.crt" ]; }; then
@@ -206,49 +211,46 @@ fi
# don't run dist-upgrade in one click apps to make the # don't run dist-upgrade in one click apps to make the
# installation process more seamless. # installation process more seamless.
if [ -z "$NO_DIST_UPGRADE" ]; then if [ -z "$NO_DIST_UPGRADE" ]; then
case " $os_id $os_id_like " in if [ "$package_system" = apt ]; then
*' debian '*) apt-get -y dist-upgrade "${APT_OPTIONS[@]}"
apt-get -y dist-upgrade "${APT_OPTIONS[@]}" elif [ "$package_system" = yum ]; then
;;
# On CentOS, there is no need to do `yum -y upgrade` because `yum -y # On CentOS, there is no need to do `yum -y upgrade` because `yum -y
# update` already does the same thing. # update` already does the same thing.
esac :
fi
fi fi
case " $os_id $os_id_like " in if [ "$package_system" = apt ]; then
*' debian '*) if [ "$os_id" = ubuntu ] && [ "$os_version_id" = 20.04 ]; then
if [ "$os_id" = ubuntu ] && [ "$os_version_id" = 20.04 ]; then PYTHON2="python2"
PYTHON2="python2" else
else PYTHON2="python"
PYTHON2="python" fi
fi
if ! apt-get install -y \ if ! apt-get install -y \
puppet git curl wget jq \ puppet git curl wget jq \
"$PYTHON2" python3 python-six python3-six crudini \ "$PYTHON2" python3 python-six python3-six crudini \
"${ADDITIONAL_PACKAGES[@]}"; then "${ADDITIONAL_PACKAGES[@]}"; then
set +x set +x
echo -e '\033[0;31m' >&2 echo -e '\033[0;31m' >&2
echo "Installing packages failed; is network working and (on Ubuntu) the universe repository enabled?" >&2 echo "Installing packages failed; is network working and (on Ubuntu) the universe repository enabled?" >&2
echo >&2 echo >&2
echo -e '\033[0m' >&2 echo -e '\033[0m' >&2
exit 1 exit 1
fi fi
;; elif [ "$package_system" = yum ]; then
*' rhel '*) if ! yum install -y \
if ! yum install -y \ puppet git curl wget jq \
puppet git curl wget jq \ python python3 python-six python3-six crudini \
python python3 python-six python3-six crudini \ "${ADDITIONAL_PACKAGES[@]}"; then
"${ADDITIONAL_PACKAGES[@]}"; then set +x
set +x echo -e '\033[0;31m' >&2
echo -e '\033[0;31m' >&2 echo "Installing packages failed; is network working?" >&2
echo "Installing packages failed; is network working?" >&2 echo >&2
echo >&2 echo -e '\033[0m' >&2
echo -e '\033[0m' >&2 exit 1
exit 1 fi
fi fi
;;
esac
if [ -n "$USE_CERTBOT" ]; then if [ -n "$USE_CERTBOT" ]; then
"$ZULIP_PATH"/scripts/setup/setup-certbot \ "$ZULIP_PATH"/scripts/setup/setup-certbot \
@@ -309,15 +311,13 @@ EOF
fi fi
if [ -e "/etc/init.d/postgresql" ]; then if [ -e "/etc/init.d/postgresql" ]; then
case " $os_id $os_id_like " in if [ "$package_system" = apt ]; then
*' debian '*) cat <<EOF
cat <<EOF
[postgresql] [postgresql]
version = 12 version = 12
EOF EOF
;; fi
esac
fi fi
) > /etc/zulip/zulip.conf ) > /etc/zulip/zulip.conf
fi fi
@@ -340,14 +340,12 @@ esac
"$ZULIP_PATH"/scripts/zulip-puppet-apply -f "$ZULIP_PATH"/scripts/zulip-puppet-apply -f
case " $os_id $os_id_like " in if [ "$package_system" = apt ]; then
*' debian '*) SUPERVISOR_CONF_DIR="/etc/supervisor/conf.d"
SUPERVISOR_CONF_DIR="/etc/supervisor/conf.d" elif [ "$package_system" = yum ]; then
;; SUPERVISOR_CONF_DIR="/etc/supervisord.d/conf.d"
*' rhel '*) fi
SUPERVISOR_CONF_DIR="/etc/supervisord.d/conf.d"
;;
esac
# Detect which features were selected for the below # Detect which features were selected for the below
set +e set +e
[ -e "/etc/init.d/nginx" ]; has_nginx=$? [ -e "/etc/init.d/nginx" ]; has_nginx=$?
@@ -369,14 +367,12 @@ if [ -n "$POSTGRES_MISSING_DICTIONARIES" ]; then
fi fi
# These server restarting bits should be moveable into puppet-land, ideally # These server restarting bits should be moveable into puppet-land, ideally
case " $os_id $os_id_like " in if [ "$package_system" = apt ]; then
*' debian '*) apt-get -y upgrade
apt-get -y upgrade elif [ "$package_system" = yum ]; then
;; # No action is required because `yum update` already does upgrade.
*' rhel '*) :
# No action is required because `yum update` already does upgrade. fi
;;
esac
if [ "$has_nginx" = 0 ]; then if [ "$has_nginx" = 0 ]; then
# Check nginx was configured properly now that we've installed it. # Check nginx was configured properly now that we've installed it.