add check for git binary and local changes to self upgrade

This commit is contained in:
Roni Väyrynen
2021-09-15 11:48:40 +03:00
parent f8c97f4afa
commit c0849b5eaa
2 changed files with 12 additions and 1 deletions

7
test.sh Executable file
View File

@@ -0,0 +1,7 @@
#!/bin/bash
if [[ -n $(command -v git) ]]; then
echo "jep"
else
echo "noup"
fi

View File

@@ -94,9 +94,13 @@ function SelfUpgrade {
return 0
fi
if [[ -d "$SCRIPT_DIR/.git" ]]; then
if [[ -d "$SCRIPT_DIR/.git" ]] && [[ -n $(runcmd_stdout "command -v git") ]]; then
local REMOTE="$(runcmd_stdout "cd $SCRIPT_DIR && git config --get remote.origin.url")"
if [[ "$REMOTE" == *"ronivay/XenOrchestraInstallerUpdater"* ]]; then
if [[ -n $(runcmd_stdout "cd $SCRIPT_DIR && git status --porcelain") ]]; then
printfail "Local changes in this script directory. Not attempting to self upgrade"
return 0
fi
runcmd "cd $SCRIPT_DIR && git fetch"
local OLD_SCRIPT_VERSION="$(runcmd_stdout "cd $SCRIPT_DIR && git rev-parse --short HEAD")"
local NEW_SCRIPT_VERSION="$(runcmd_stdout "cd $SCRIPT_DIR && git rev-parse --short FETCH_HEAD")"