From 3757cad4061018c8c57b52c8a83265225a533607 Mon Sep 17 00:00:00 2001 From: ronivay Date: Mon, 3 May 2021 14:54:07 +0300 Subject: [PATCH] add option to disable os/arch checks and call package install functions with respective pkg formats instead of distro names --- sample.xo-install.cfg | 6 +++++ xo-install.sh | 55 ++++++++++++++++++++++++++++++------------- 2 files changed, 45 insertions(+), 16 deletions(-) diff --git a/sample.xo-install.cfg b/sample.xo-install.cfg index 9ca3cb6..d11acd8 100644 --- a/sample.xo-install.cfg +++ b/sample.xo-install.cfg @@ -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 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 PRESERVE="3" diff --git a/xo-install.sh b/xo-install.sh index 43baa4c..8905c7b 100755 --- a/xo-install.sh +++ b/xo-install.sh @@ -28,6 +28,8 @@ XOUSER=${XOUSER:-"root"} CONFIGPATH="$(getent passwd $XOUSER | cut -d: -f6)" PLUGINS="${PLUGINS:-"none"}" REPOSITORY="${REPOSITORY:-"https://github.com/vatesfr/xen-orchestra"}" +OS_CHECK="${OS_CHECK:-"true"}" +ARCH_CHECK="${ARCH_CHECK:-"true"}" # set variables not changeable in configfile TIME=$(date +%Y%m%d%H%M) @@ -114,7 +116,7 @@ function ErrorHandling { exit 1 } -function InstallDependenciesCentOS { +function InstallDependenciesRPM { set -euo pipefail @@ -196,7 +198,7 @@ function InstallDependenciesCentOS { } -function InstallDependenciesDebian { +function InstallDependenciesDeb { set -euo pipefail @@ -307,7 +309,7 @@ function UpdateNodeYarn { if [[ $AUTOUPDATE == "true" ]]; then - if [ $OSNAME == "CentOS" ]; then + if [ $PKG_FORMAT == "rpm" ]; then echo printinfo "Checking current node.js version" NODEV=$(node -v 2>/dev/null| grep -Eo '[0-9.]+' | cut -d'.' -f1) @@ -809,12 +811,12 @@ function HandleArgs { fi if [[ $INSTALLARG -gt 0 ]]; then - if [ $OSNAME == "CentOS" ]; then - InstallDependenciesCentOS + if [ $PKG_FORMAT == "rpm" ]; then + InstallDependenciesRPM InstallXO exit else - InstallDependenciesDebian + InstallDependenciesDeb InstallXO exit fi @@ -874,14 +876,26 @@ function RollBackInstallation { function CheckOS { - if [[ $(uname -m) != "x86_64" ]]; then - printfail "Installation supports only x86_64. You seem to be running architecture: $(uname -m)" - exit 1 + if [[ "$(which yum)" ]]; then + PKG_FORMAT="rpm" + fi + + if [[ "$(which apt-get)" ]]; then + PKG_FORMAT="deb" + fi + + if [[ "$OS_CHECK" != "true" ]]; then + return 0 fi 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}') + if [[ ! $OSNAME =~ ^(Debian|Ubuntu|CentOS)$ ]]; then + printfail "Only Ubuntu/Debian/CentOS supported" + exit 1 + fi + if [[ $OSNAME == "CentOS" ]] && [[ ! $OSVERSION != "8" ]]; then printfail "Only CentOS 8 supported" exit 1 @@ -903,11 +917,18 @@ function CheckOS { exit 1 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 + 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 { @@ -1038,16 +1059,17 @@ read -p ": " option esac fi - if [ $OSNAME == "CentOS" ]; then + if [ $PKG_FORMAT == "rpm" ]; then TASK="Installation" INTERACTIVE="true" - InstallDependenciesCentOS + InstallDependenciesRPM InstallXO exit 0 - else + fi + if [ $PKG_FORMAT == "deb" ]; then TASK="Installation" INTERACTIVE="true" - InstallDependenciesDebian + InstallDependenciesDeb InstallXO exit 0 fi @@ -1076,6 +1098,7 @@ esac } CheckUser +CheckArch CheckOS CheckSystemd CheckCertificate