implement self upgrade to the script

This commit is contained in:
ronivay
2021-08-23 16:20:32 +03:00
parent b5399a482e
commit 03f5ad9d10
2 changed files with 31 additions and 0 deletions

View File

@@ -21,6 +21,7 @@ fi
source "$CONFIG_FILE"
# Set some default variables if sourcing config file fails for some reason
SELFUPGRADE=${SELFUPGRADE:-"true"}
PORT=${PORT:-80}
INSTALLDIR=${INSTALLDIR:-"/opt/xo"}
BRANCH=${BRANCH:-"master"}
@@ -83,6 +84,31 @@ function CheckUser {
}
# script self upgrade
function selfUpgrade {
set -o pipefail
if [[ "$SELFUPGRADE" != "true" ]]; then
return 0
fi
if [[ -d "$SCRIPT_DIR/.git" ]]; then
local REMOTE="$(runcmd_stdout "cd $SCRIPT_DIR && git config --get remote.origin.url")"
if [[ "$REMOTE" == *"ronivay/XenOrchestraInstallerUpdater"* ]]; then
runcmd "cd $SCRIPT_DIR && git fetch"
if [[ $(runcmd_stdout "cd $SCRIPT_DIR && git diff --name-only @{upstream}| grep xo-install.sh") ]]; then
printinfo "Newer version of script available, attempting to self upgrade"
runcmd "cd $SCRIPT_DIR && git pull --ff-only" && \
{ printok "Self upgrade done" ; exec "$SCRIPT_DIR/xo-install.sh" "$@"; } || \
printfail "Failed to self upgrade. Check logs for more details"
fi
fi
fi
}
# log script version (git commit) and configuration variables to logfile
function scriptInfo {
@@ -1143,7 +1169,9 @@ if [[ $# == "0" ]]; then
INTERACTIVE="true"
fi
# these functions check specific requirements and are run everytime
selfUpgrade "$@"
scriptInfo
CheckUser
CheckArch