add option to disable os/arch checks and call package install functions with respective pkg formats instead of distro names

This commit is contained in:
ronivay
2021-05-03 14:54:07 +03:00
parent a872b79483
commit 3757cad406
2 changed files with 45 additions and 16 deletions

View File

@@ -32,6 +32,12 @@ PLUGINS="all"
# Note that if nodejs is updated when script's update feature is used, it might not be possible to use rollback option anymore without manually downgrading nodejs version to previous one # Note that if nodejs is updated when script's update feature is used, it might not be possible to use rollback option anymore without manually downgrading nodejs version to previous one
AUTOUPDATE="true" AUTOUPDATE="true"
# enable/disable OS check. Installation refuses to run on any other than supported OS versions if this is enabled. Can be disabled for experimental purposes.
OS_CHECK="true"
# enable/disable architecture check. Installation refuses to run on any other than x86_64 if enabled. Can be disabled for experimental purposes.
ARCH_CHECK="true"
# Define the number of previous installations you want to keep. Needs to be at least 1 # Define the number of previous installations you want to keep. Needs to be at least 1
PRESERVE="3" PRESERVE="3"

View File

@@ -28,6 +28,8 @@ XOUSER=${XOUSER:-"root"}
CONFIGPATH="$(getent passwd $XOUSER | cut -d: -f6)" CONFIGPATH="$(getent passwd $XOUSER | cut -d: -f6)"
PLUGINS="${PLUGINS:-"none"}" PLUGINS="${PLUGINS:-"none"}"
REPOSITORY="${REPOSITORY:-"https://github.com/vatesfr/xen-orchestra"}" REPOSITORY="${REPOSITORY:-"https://github.com/vatesfr/xen-orchestra"}"
OS_CHECK="${OS_CHECK:-"true"}"
ARCH_CHECK="${ARCH_CHECK:-"true"}"
# set variables not changeable in configfile # set variables not changeable in configfile
TIME=$(date +%Y%m%d%H%M) TIME=$(date +%Y%m%d%H%M)
@@ -114,7 +116,7 @@ function ErrorHandling {
exit 1 exit 1
} }
function InstallDependenciesCentOS { function InstallDependenciesRPM {
set -euo pipefail set -euo pipefail
@@ -196,7 +198,7 @@ function InstallDependenciesCentOS {
} }
function InstallDependenciesDebian { function InstallDependenciesDeb {
set -euo pipefail set -euo pipefail
@@ -307,7 +309,7 @@ function UpdateNodeYarn {
if [[ $AUTOUPDATE == "true" ]]; then if [[ $AUTOUPDATE == "true" ]]; then
if [ $OSNAME == "CentOS" ]; then if [ $PKG_FORMAT == "rpm" ]; then
echo echo
printinfo "Checking current node.js version" printinfo "Checking current node.js version"
NODEV=$(node -v 2>/dev/null| grep -Eo '[0-9.]+' | cut -d'.' -f1) NODEV=$(node -v 2>/dev/null| grep -Eo '[0-9.]+' | cut -d'.' -f1)
@@ -809,12 +811,12 @@ function HandleArgs {
fi fi
if [[ $INSTALLARG -gt 0 ]]; then if [[ $INSTALLARG -gt 0 ]]; then
if [ $OSNAME == "CentOS" ]; then if [ $PKG_FORMAT == "rpm" ]; then
InstallDependenciesCentOS InstallDependenciesRPM
InstallXO InstallXO
exit exit
else else
InstallDependenciesDebian InstallDependenciesDeb
InstallXO InstallXO
exit exit
fi fi
@@ -874,14 +876,26 @@ function RollBackInstallation {
function CheckOS { function CheckOS {
if [[ $(uname -m) != "x86_64" ]]; then if [[ "$(which yum)" ]]; then
printfail "Installation supports only x86_64. You seem to be running architecture: $(uname -m)" PKG_FORMAT="rpm"
exit 1 fi
if [[ "$(which apt-get)" ]]; then
PKG_FORMAT="deb"
fi
if [[ "$OS_CHECK" != "true" ]]; then
return 0
fi fi
OSVERSION=$(grep ^VERSION_ID /etc/os-release | cut -d'=' -f2 | grep -Eo "[0-9]{1,2}" | head -1) OSVERSION=$(grep ^VERSION_ID /etc/os-release | cut -d'=' -f2 | grep -Eo "[0-9]{1,2}" | head -1)
OSNAME=$(grep ^NAME /etc/os-release | cut -d'=' -f2 | sed 's/"//g' | awk '{print $1}') OSNAME=$(grep ^NAME /etc/os-release | cut -d'=' -f2 | sed 's/"//g' | awk '{print $1}')
if [[ ! $OSNAME =~ ^(Debian|Ubuntu|CentOS)$ ]]; then
printfail "Only Ubuntu/Debian/CentOS supported"
exit 1
fi
if [[ $OSNAME == "CentOS" ]] && [[ ! $OSVERSION != "8" ]]; then if [[ $OSNAME == "CentOS" ]] && [[ ! $OSVERSION != "8" ]]; then
printfail "Only CentOS 8 supported" printfail "Only CentOS 8 supported"
exit 1 exit 1
@@ -903,11 +917,18 @@ function CheckOS {
exit 1 exit 1
fi fi
if [[ ! $OSNAME =~ ^(Debian|Ubuntu|CentOS)$ ]]; then }
printfail "Only Ubuntu/Debian/CentOS supported"
exit 1 function CheckArch {
if [[ "$ARCH_CHECK" != "true" ]]; then
return 0
fi fi
if [[ $(uname -m) != "x86_64" ]]; then
printfail "Installation supports only x86_64. You seem to be running architecture: $(uname -m)"
exit 1
fi
} }
function CheckSystemd { function CheckSystemd {
@@ -1038,16 +1059,17 @@ read -p ": " option
esac esac
fi fi
if [ $OSNAME == "CentOS" ]; then if [ $PKG_FORMAT == "rpm" ]; then
TASK="Installation" TASK="Installation"
INTERACTIVE="true" INTERACTIVE="true"
InstallDependenciesCentOS InstallDependenciesRPM
InstallXO InstallXO
exit 0 exit 0
else fi
if [ $PKG_FORMAT == "deb" ]; then
TASK="Installation" TASK="Installation"
INTERACTIVE="true" INTERACTIVE="true"
InstallDependenciesDebian InstallDependenciesDeb
InstallXO InstallXO
exit 0 exit 0
fi fi
@@ -1076,6 +1098,7 @@ esac
} }
CheckUser CheckUser
CheckArch
CheckOS CheckOS
CheckSystemd CheckSystemd
CheckCertificate CheckCertificate