Change args handling and add support for forced update

This commit is contained in:
ronivay
2021-03-23 09:53:53 +02:00
parent d163d0d9ab
commit 054ba9b4ee
2 changed files with 112 additions and 39 deletions

View File

@@ -28,7 +28,7 @@ basic functionality including menu:
./xo-install.sh ./xo-install.sh
non-interactive update task (option 2): non-interactive update task (option 2):
./xo-install.sh --update ./xo-install.sh --update [--force]
non-interactive install task (option 1): non-interactive install task (option 1):
./xo-install.sh --install ./xo-install.sh --install

View File

@@ -34,6 +34,8 @@ TIME=$(date +%Y%m%d%H%M)
LOGTIME=$(date "+%Y-%m-%d %H:%M:%S") LOGTIME=$(date "+%Y-%m-%d %H:%M:%S")
LOGFILE="${LOGPATH}/xo-install.log-$TIME" LOGFILE="${LOGPATH}/xo-install.log-$TIME"
NODEVERSION="14" NODEVERSION="14"
FORCE="false"
INTERACTIVE="false"
# Set path where new source is cloned/pulled # Set path where new source is cloned/pulled
XO_SRC_DIR="$INSTALLDIR/xo-src/xen-orchestra" XO_SRC_DIR="$INSTALLDIR/xo-src/xen-orchestra"
@@ -141,7 +143,7 @@ function InstallDependenciesCentOS {
curl -s -L https://rpm.nodesource.com/setup_${NODEVERSION}.x | bash - >>$LOGFILE 2>&1 curl -s -L https://rpm.nodesource.com/setup_${NODEVERSION}.x | bash - >>$LOGFILE 2>&1
printok "Installing node.js" printok "Installing node.js"
else else
UpdateNodeYarn install UpdateNodeYarn
fi fi
# only install yarn repo and package if not found # only install yarn repo and package if not found
@@ -208,11 +210,11 @@ function InstallDependenciesDebian {
# Install necessary dependencies for XO build # Install necessary dependencies for XO build
if [[ $OSVERSION =~ (16|18|20) ]]; then if [[ $OSVERSION =~ (16|18|20) ]]; then
echo
printprog "OS Ubuntu so making sure universe repository is enabled" printprog "OS Ubuntu so making sure universe repository is enabled"
cmdlog "add-apt-repository universe" cmdlog "add-apt-repository universe"
add-apt-repository universe >>$LOGFILE 2>&1 add-apt-repository universe >>$LOGFILE 2>&1
printok "OS Ubuntu so making sure universe repository is enabled" printok "OS Ubuntu so making sure universe repository is enabled"
echo
fi fi
echo echo
@@ -273,7 +275,7 @@ function InstallDependenciesDebian {
apt-get install -y nodejs >>$LOGFILE 2>&1 apt-get install -y nodejs >>$LOGFILE 2>&1
printok "Installing node.js" printok "Installing node.js"
else else
UpdateNodeYarn install UpdateNodeYarn
fi fi
# only install yarn repo and package if not found # only install yarn repo and package if not found
@@ -325,13 +327,13 @@ function UpdateNodeYarn {
yum install -y nodejs >>LOGFILE 2>&1 yum install -y nodejs >>LOGFILE 2>&1
printok "node.js version is $NODEV, upgrading to ${NODEVERSION}.x" printok "node.js version is $NODEV, upgrading to ${NODEVERSION}.x"
else else
if [[ $1 == "update" ]]; then if [[ "$TASK" == "Update" ]]; then
echo echo
printprog "node.js version already on $NODEV, checking updates" printprog "node.js version already on $NODEV, checking updates"
cmdlog "yum update -y nodejs yarn" cmdlog "yum update -y nodejs yarn"
yum update -y nodejs yarn >>$LOGFILE 2>&1 yum update -y nodejs yarn >>$LOGFILE 2>&1
printok "node.js version already on $NODEV, checking updates" printok "node.js version already on $NODEV, checking updates"
elif [[ $1 == "install" ]]; then elif [[ "$TASK" == "Installation" ]]; then
echo echo
printinfo "node.js version already on $NODEV" printinfo "node.js version already on $NODEV"
fi fi
@@ -349,13 +351,13 @@ function UpdateNodeYarn {
apt-get install -y nodejs >>$LOGFILE 2>&1 apt-get install -y nodejs >>$LOGFILE 2>&1
printok "node.js version is $NODEV, upgrading to ${NODEVERSION}.x" printok "node.js version is $NODEV, upgrading to ${NODEVERSION}.x"
else else
if [[ $1 == "update" ]]; then if [[ "$TASK" == "Update" ]]; then
echo echo
printprog "node.js version already on $NODEV, checking updates" printprog "node.js version already on $NODEV, checking updates"
cmdlog "apt-get install -y --only-upgrade nodejs yarn" cmdlog "apt-get install -y --only-upgrade nodejs yarn"
apt-get install -y --only-upgrade nodejs yarn >>$LOGFILE 2>&1 apt-get install -y --only-upgrade nodejs yarn >>$LOGFILE 2>&1
printok "node.js version already on $NODEV, checking updates" printok "node.js version already on $NODEV, checking updates"
elif [[ $1 == "install" ]]; then elif [[ "$TASK" == "Installation" ]]; then
echo echo
printinfo "node.js version already on $NODEV" printinfo "node.js version already on $NODEV"
fi fi
@@ -517,13 +519,30 @@ function InstallXO {
# If the new install is no different from the existing install, then don't # If the new install is no different from the existing install, then don't
# proceed with the build. # proceed with the build.
if [[ "$NEW_REPO_HASH" == "$OLD_REPO_HASH" ]]; then if [[ "$NEW_REPO_HASH" == "$OLD_REPO_HASH" ]] && [[ "$FORCE" != "true" ]]; then
echo echo
if [[ "$INTERACTIVE" == "true" ]]; then
printinfo "No changes to xen-orchestra since previous install. Run update anyway?"
read -p "[y/N]: " answer
answer=${answer:-n}
case $answer in
y)
:
;;
n)
printinfo "Cleaning up install directory: $INSTALLDIR/xo-builds/xen-orchestra-$TIME"
cmdlog "rm -rf $INSTALLDIR/xo-builds/xen-orchestra-$TIME"
rm -rf $INSTALLDIR/xo-builds/xen-orchestra-$TIME >>$LOGFILE 2>&1
exit 0
;;
esac
else
printinfo "No changes to xen-orchestra since previous install. Skipping xo-server and xo-web build." printinfo "No changes to xen-orchestra since previous install. Skipping xo-server and xo-web build."
printinfo "Cleaning up install directory: $INSTALLDIR/xo-builds/xen-orchestra-$TIME" printinfo "Cleaning up install directory: $INSTALLDIR/xo-builds/xen-orchestra-$TIME"
cmdlog "rm -rf $INSTALLDIR/xo-builds/xen-orchestra-$TIME" cmdlog "rm -rf $INSTALLDIR/xo-builds/xen-orchestra-$TIME"
rm -rf $INSTALLDIR/xo-builds/xen-orchestra-$TIME >>$LOGFILE 2>&1 rm -rf $INSTALLDIR/xo-builds/xen-orchestra-$TIME >>$LOGFILE 2>&1
return 0 exit 0
fi
fi fi
# Now that we know we're going to be building a new xen-orchestra, make # Now that we know we're going to be building a new xen-orchestra, make
@@ -539,8 +558,11 @@ function InstallXO {
# If this isn't a fresh install, then list the upgrade the user is making. # If this isn't a fresh install, then list the upgrade the user is making.
if [[ -n "$OLD_REPO_HASH" ]]; then if [[ -n "$OLD_REPO_HASH" ]]; then
echo echo
TASK="Update" if [[ "$FORCE" != "true" ]]; then
printinfo "Updating xen-orchestra from '$OLD_REPO_HASH_SHORT' to '$NEW_REPO_HASH_SHORT'" printinfo "Updating xen-orchestra from '$OLD_REPO_HASH_SHORT' to '$NEW_REPO_HASH_SHORT'"
else
printinfo "Updating xen-orchestra (forced) from '$OLD_REPO_HASH_SHORT' to '$NEW_REPO_HASH_SHORT'"
fi
else else
TASK="Installation" TASK="Installation"
fi fi
@@ -736,32 +758,77 @@ function UpdateXO {
function HandleArgs { function HandleArgs {
OPTS=$(getopt -o: --long force,rollback,update,install -- "$@")
if [[ $? != 0 ]]; then
echo "Usage: $(dirname $0)/$(basename $0) [--install | --update | --rollback ] [--force]"
exit 1
fi
eval set -- "$OPTS"
local UPDATEARG=0
local INSTALLARG=0
local ROLLBACKARG=0
while true; do
case "$1" in case "$1" in
--force)
shift
FORCE="true"
;;
--update) --update)
UpdateNodeYarn update shift
UpdateXO local UPDATEARG=1
TASK="Update"
;; ;;
--install) --install)
shift
local INSTALLARG=1
TASK="Installation"
;;
--rollback)
shift
local ROLLBACKARG=1
;;
--)
shift
break
;;
*)
shift
break
;;
esac
done
if [[ "$((INSTALLARG+UPDATEARG+ROLLBACKARG))" -gt 1 ]]; then
echo "Define either install/update or rollback"
exit 1
fi
if [[ $UPDATEARG -gt 0 ]]; then
UpdateNodeYarn
UpdateXO
exit
fi
if [[ $INSTALLARG -gt 0 ]]; then
if [ $OSNAME == "CentOS" ]; then if [ $OSNAME == "CentOS" ]; then
InstallDependenciesCentOS InstallDependenciesCentOS
InstallXO InstallXO
exit 0 exit
else else
InstallDependenciesDebian InstallDependenciesDebian
InstallXO InstallXO
exit 0 exit
fi fi
;; fi
--rollback)
if [[ $ROLLBACKARG -gt 0 ]]; then
RollBackInstallation RollBackInstallation
exit 0 exit
;; fi
*)
CheckDiskFree
CheckMemory
StartUpScreen
;;
esac
} }
@@ -975,17 +1042,23 @@ read -p ": " option
fi fi
if [ $OSNAME == "CentOS" ]; then if [ $OSNAME == "CentOS" ]; then
TASK="Installation"
INTERACTIVE="true"
InstallDependenciesCentOS InstallDependenciesCentOS
InstallXO InstallXO
exit 0 exit 0
else else
TASK="Installation"
INTERACTIVE="true"
InstallDependenciesDebian InstallDependenciesDebian
InstallXO InstallXO
exit 0 exit 0
fi fi
;; ;;
2) 2)
UpdateNodeYarn update TASK="Update"
INTERACTIVE="true"
UpdateNodeYarn
UpdateXO UpdateXO
exit 0 exit 0
;; ;;
@@ -1010,8 +1083,8 @@ CheckOS
CheckSystemd CheckSystemd
CheckCertificate CheckCertificate
if [[ $# == "1" ]]; then if [[ $# != "0" ]]; then
HandleArgs "$1" HandleArgs "$@"
exit 0 exit 0
else else
CheckDiskFree CheckDiskFree