Refactoring docspace-install.sh code

This commit is contained in:
Evgeniy Antonyuk 2024-07-09 13:34:42 +03:00
parent c312ba632b
commit 369cfd8d30

View File

@ -1,7 +1,7 @@
#!/bin/bash
#
# (c) Copyright Ascensio System SIA 2021
# (c) Copyright Ascensio System SIA 2024
#
# This program is a free software product. You can redistribute it and/or
# modify it under the terms of the GNU Affero General Public License (AGPL)
@ -40,35 +40,15 @@ FILE_NAME="$(basename "$0")"
while [ "$1" != "" ]; do
case $1 in
-ls | --localscripts )
if [ "$2" == "true" ] || [ "$2" == "false" ]; then
PARAMETERS="$PARAMETERS ${1}";
LOCAL_SCRIPTS=$2
shift
fi
;;
-gb | --gitbranch )
if [ "$2" != "" ]; then
PARAMETERS="$PARAMETERS ${1}";
GIT_BRANCH=$2
shift
fi
;;
docker )
DOCKER="true";
shift && continue
;;
package )
DOCKER="false";
shift && continue
;;
-ls | --localscripts ) [ "$2" == "true" -o "$2" == "false" ] && { PARAMETERS+=" $1"; LOCAL_SCRIPTS=$2; shift; } ;;
-gb | --gitbranch ) [ -n "$2" ] && { PARAMETERS+=" $1"; GIT_BRANCH=$2; shift; } ;;
docker ) DOCKER="true"; shift && continue ;;
package ) DOCKER="false"; shift && continue ;;
"-?" | -h | --help )
if [ -z "$DOCKER" ]; then
echo "Run 'bash $FILE_NAME docker' to install docker version of application or 'bash $FILE_NAME package' to install deb/rpm version."
echo "Run 'bash $FILE_NAME docker' to install Docker version of application."
echo "Run 'bash $FILE_NAME package' to install DEB/RPM version."
echo "Run 'bash $FILE_NAME docker -h' or 'bash $FILE_NAME package -h' to get more details."
exit 0;
fi
@ -80,10 +60,7 @@ while [ "$1" != "" ]; do
done
root_checking () {
if [ ! $( id -u ) -eq 0 ]; then
echo "To perform this action you must be logged in with root rights"
exit 1;
fi
[ "$(id -u)" -eq 0 ] || { echo "To perform this action you must be logged in with root rights"; exit 1; }
}
command_exists () {
@ -98,91 +75,53 @@ install_curl () {
yum -y install curl
fi
if ! command_exists curl; then
echo "command curl not found"
exit 1;
fi
command_exists curl || { echo "Command curl not found."; exit 1; }
}
read_installation_method () {
echo "Select 'Y' to install ${product_sysname^^} $product using Docker (recommended). Select 'N' to install it using RPM/DEB packages.";
read -p "Install with Docker [Y/N/C]? " choice
case "$choice" in
y|Y )
DOCKER="true";
;;
n|N )
DOCKER="false";
;;
c|C )
exit 0;
;;
* )
echo "Please, enter Y, N or C to cancel";
;;
esac
if [ "$DOCKER" == "" ]; then
read_installation_method;
fi
read_installation_method() {
echo "Select 'Y' to install ${product_sysname^^} $product using Docker (recommended)."
echo "Select 'N' to install it using RPM/DEB packages."
while true; do
read -p "Install with Docker [Y/N/C]? " choice
case "${choice,,}" in
y | yes) DOCKER="true"; break ;;
n | no) DOCKER="false"; break ;;
c | cancel) exit 0 ;;
*) echo "Please, enter Y, N, or C to cancel." ;;
esac
done
}
root_checking
if ! command_exists curl ; then
install_curl;
fi
command_exists curl || install_curl
if command_exists docker &> /dev/null && docker ps -a --format '{{.Names}}' | grep -q "${product_sysname}-api"; then
if command_exists docker && docker ps -a --format '{{.Names}}' | grep -q "${product_sysname}-api"; then
DOCKER="true"
elif command_exists apt-get &> /dev/null && dpkg -s ${product}-api >/dev/null 2>&1; then
elif command_exists dpkg && dpkg -s ${product}-api >/dev/null 2>&1; then
DOCKER="false"
elif command_exists yum &> /dev/null && rpm -q ${product}-api >/dev/null 2>&1; then
elif command_exists rpm && rpm -q ${product}-api >/dev/null 2>&1; then
DOCKER="false"
fi
if [ -z "$DOCKER" ]; then
read_installation_method;
fi
if [ -z $GIT_BRANCH ]; then
DOWNLOAD_URL_PREFIX="https://download.${product_sysname}.com/${product}"
else
DOWNLOAD_URL_PREFIX="https://raw.githubusercontent.com/${product_sysname^^}/${product}-buildtools/${GIT_BRANCH}/install/OneClickInstall"
fi
[ -z "$DOCKER" ] && read_installation_method
DOWNLOAD_URL_PREFIX="https://download.${product_sysname}.com/${product}"
[ -n "$GIT_BRANCH" ] && DOWNLOAD_URL_PREFIX="https://raw.githubusercontent.com/${product_sysname^^}/${product}-buildtools/${GIT_BRANCH}/install/OneClickInstall"
if [ "$DOCKER" == "true" ]; then
if [ "$LOCAL_SCRIPTS" == "true" ]; then
bash install-Docker.sh ${PARAMETERS} || EXIT_CODE=$?
else
curl -s -O ${DOWNLOAD_URL_PREFIX}/install-Docker.sh
bash install-Docker.sh ${PARAMETERS} || EXIT_CODE=$?
rm install-Docker.sh
fi
SCRIPT_NAME="install-Docker.sh"
elif [ -f /etc/redhat-release ]; then
SCRIPT_NAME="install-RedHat.sh"
elif [ -f /etc/debian_version ]; then
SCRIPT_NAME="install-Debian.sh"
else
if [ -f /etc/redhat-release ] ; then
if [ "$LOCAL_SCRIPTS" == "true" ]; then
bash install-RedHat.sh ${PARAMETERS} || EXIT_CODE=$?
else
curl -s -O ${DOWNLOAD_URL_PREFIX}/install-RedHat.sh
bash install-RedHat.sh ${PARAMETERS} || EXIT_CODE=$?
rm install-RedHat.sh
fi
elif [ -f /etc/debian_version ] ; then
if [ "$LOCAL_SCRIPTS" == "true" ]; then
bash install-Debian.sh ${PARAMETERS} || EXIT_CODE=$?
else
curl -s -O ${DOWNLOAD_URL_PREFIX}/install-Debian.sh
bash install-Debian.sh ${PARAMETERS} || EXIT_CODE=$?
rm install-Debian.sh
fi
else
echo "Not supported OS";
exit 1;
fi
echo "Not supported OS"
exit 1
fi
[ "$LOCAL_SCRIPTS" != "true" ] && curl -s -O ${DOWNLOAD_URL_PREFIX}/${SCRIPT_NAME}
bash ${SCRIPT_NAME} ${PARAMETERS} || EXIT_CODE=$?
[ "$LOCAL_SCRIPTS" != "true" ] && rm ${SCRIPT_NAME}
exit ${EXIT_CODE:-0}