implement self upgrade to the script
This commit is contained in:
@@ -7,6 +7,9 @@ PORT="80"
|
||||
# Base dir for installation and future updates
|
||||
INSTALLDIR="/opt/xo"
|
||||
|
||||
# Script will update itself if there's a newer version available. This assumes that script inside a git directory and remote is ronivay/XenOrchestraInstallerUpdater
|
||||
SELFUPGRADE=true
|
||||
|
||||
# Xen Orchestra configuration file is stored in XOUSER's home directory ($HOME/.config/xo-server/config.toml) and by default will be overwritten with every update done by this script.
|
||||
# You may disable this if you edit configuration by hand and don't want an update to overwrite it. Note that some of the options defined here won't be applied even if changed if this is set to false.
|
||||
# options: true/false
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user