Refactoring docspace-install.sh code
This commit is contained in:
parent
c312ba632b
commit
369cfd8d30
@ -1,7 +1,7 @@
|
|||||||
#!/bin/bash
|
#!/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
|
# 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)
|
# modify it under the terms of the GNU Affero General Public License (AGPL)
|
||||||
@ -40,35 +40,15 @@ FILE_NAME="$(basename "$0")"
|
|||||||
|
|
||||||
while [ "$1" != "" ]; do
|
while [ "$1" != "" ]; do
|
||||||
case $1 in
|
case $1 in
|
||||||
-ls | --localscripts )
|
-ls | --localscripts ) [ "$2" == "true" -o "$2" == "false" ] && { PARAMETERS+=" $1"; LOCAL_SCRIPTS=$2; shift; } ;;
|
||||||
if [ "$2" == "true" ] || [ "$2" == "false" ]; then
|
-gb | --gitbranch ) [ -n "$2" ] && { PARAMETERS+=" $1"; GIT_BRANCH=$2; shift; } ;;
|
||||||
PARAMETERS="$PARAMETERS ${1}";
|
docker ) DOCKER="true"; shift && continue ;;
|
||||||
LOCAL_SCRIPTS=$2
|
package ) DOCKER="false"; shift && continue ;;
|
||||||
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
|
|
||||||
;;
|
|
||||||
|
|
||||||
"-?" | -h | --help )
|
"-?" | -h | --help )
|
||||||
if [ -z "$DOCKER" ]; then
|
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."
|
echo "Run 'bash $FILE_NAME docker -h' or 'bash $FILE_NAME package -h' to get more details."
|
||||||
exit 0;
|
exit 0;
|
||||||
fi
|
fi
|
||||||
@ -80,10 +60,7 @@ while [ "$1" != "" ]; do
|
|||||||
done
|
done
|
||||||
|
|
||||||
root_checking () {
|
root_checking () {
|
||||||
if [ ! $( id -u ) -eq 0 ]; then
|
[ "$(id -u)" -eq 0 ] || { echo "To perform this action you must be logged in with root rights"; exit 1; }
|
||||||
echo "To perform this action you must be logged in with root rights"
|
|
||||||
exit 1;
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
command_exists () {
|
command_exists () {
|
||||||
@ -98,91 +75,53 @@ install_curl () {
|
|||||||
yum -y install curl
|
yum -y install curl
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! command_exists curl; then
|
command_exists curl || { echo "Command curl not found."; exit 1; }
|
||||||
echo "command curl not found"
|
|
||||||
exit 1;
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
read_installation_method () {
|
read_installation_method() {
|
||||||
echo "Select 'Y' to install ${product_sysname^^} $product using Docker (recommended). Select 'N' to install it using RPM/DEB packages.";
|
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
|
read -p "Install with Docker [Y/N/C]? " choice
|
||||||
case "$choice" in
|
case "${choice,,}" in
|
||||||
y|Y )
|
y | yes) DOCKER="true"; break ;;
|
||||||
DOCKER="true";
|
n | no) DOCKER="false"; break ;;
|
||||||
;;
|
c | cancel) exit 0 ;;
|
||||||
|
*) echo "Please, enter Y, N, or C to cancel." ;;
|
||||||
n|N )
|
|
||||||
DOCKER="false";
|
|
||||||
;;
|
|
||||||
|
|
||||||
c|C )
|
|
||||||
exit 0;
|
|
||||||
;;
|
|
||||||
|
|
||||||
* )
|
|
||||||
echo "Please, enter Y, N or C to cancel";
|
|
||||||
;;
|
|
||||||
esac
|
esac
|
||||||
|
done
|
||||||
if [ "$DOCKER" == "" ]; then
|
|
||||||
read_installation_method;
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
root_checking
|
root_checking
|
||||||
|
|
||||||
if ! command_exists curl ; then
|
command_exists curl || install_curl
|
||||||
install_curl;
|
|
||||||
fi
|
|
||||||
|
|
||||||
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"
|
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"
|
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"
|
DOCKER="false"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "$DOCKER" ]; then
|
[ -z "$DOCKER" ] && read_installation_method
|
||||||
read_installation_method;
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -z $GIT_BRANCH ]; then
|
DOWNLOAD_URL_PREFIX="https://download.${product_sysname}.com/${product}"
|
||||||
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"
|
||||||
else
|
|
||||||
DOWNLOAD_URL_PREFIX="https://raw.githubusercontent.com/${product_sysname^^}/${product}-buildtools/${GIT_BRANCH}/install/OneClickInstall"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "$DOCKER" == "true" ]; then
|
if [ "$DOCKER" == "true" ]; then
|
||||||
if [ "$LOCAL_SCRIPTS" == "true" ]; then
|
SCRIPT_NAME="install-Docker.sh"
|
||||||
bash install-Docker.sh ${PARAMETERS} || EXIT_CODE=$?
|
elif [ -f /etc/redhat-release ]; then
|
||||||
else
|
SCRIPT_NAME="install-RedHat.sh"
|
||||||
curl -s -O ${DOWNLOAD_URL_PREFIX}/install-Docker.sh
|
elif [ -f /etc/debian_version ]; then
|
||||||
bash install-Docker.sh ${PARAMETERS} || EXIT_CODE=$?
|
SCRIPT_NAME="install-Debian.sh"
|
||||||
rm install-Docker.sh
|
|
||||||
fi
|
|
||||||
else
|
else
|
||||||
if [ -f /etc/redhat-release ] ; then
|
echo "Not supported OS"
|
||||||
if [ "$LOCAL_SCRIPTS" == "true" ]; then
|
exit 1
|
||||||
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
|
|
||||||
fi
|
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}
|
exit ${EXIT_CODE:-0}
|
||||||
|
Loading…
Reference in New Issue
Block a user