@@ -104,18 +104,18 @@ function SelfUpgrade {
104104 fi
105105
106106 if [[ -d " $SCRIPT_DIR /.git" ]] && [[ -n $( runcmd_stdout " command -v git" ) ]]; then
107- local REMOTE=" $( runcmd_stdout " cd $SCRIPT_DIR && git config --get remote.origin.url" ) "
107+ local REMOTE=" $( runcmd_stdout " git -C $SCRIPT_DIR config --get remote.origin.url" ) "
108108 if [[ " $REMOTE " == * " ronivay/XenOrchestraInstallerUpdater" * ]]; then
109- if [[ -n $( runcmd_stdout " cd $SCRIPT_DIR && git status --porcelain" ) ]]; then
109+ if [[ -n $( runcmd_stdout " git -C $SCRIPT_DIR status --porcelain" ) ]]; then
110110 printfail " Local changes in this script directory. Not attempting to self upgrade"
111111 return 0
112112 fi
113- runcmd " cd $SCRIPT_DIR && git fetch"
114- local OLD_SCRIPT_VERSION=" $( runcmd_stdout " cd $SCRIPT_DIR && git rev-parse --short HEAD" ) "
115- local NEW_SCRIPT_VERSION=" $( runcmd_stdout " cd $SCRIPT_DIR && git rev-parse --short FETCH_HEAD" ) "
116- if [[ $( runcmd_stdout " cd $SCRIPT_DIR && git diff --name-only @{upstream}| grep xo-install.sh" ) ]]; then
113+ runcmd " git -C $SCRIPT_DIR fetch"
114+ local OLD_SCRIPT_VERSION=" $( runcmd_stdout " git -C $SCRIPT_DIR rev-parse --short HEAD" ) "
115+ local NEW_SCRIPT_VERSION=" $( runcmd_stdout " git -C $SCRIPT_DIR rev-parse --short FETCH_HEAD" ) "
116+ if [[ $( runcmd_stdout " git -C $SCRIPT_DIR diff --name-only @{upstream}| grep xo-install.sh" ) ]]; then
117117 printinfo " Newer version of script available, attempting to self upgrade from '$OLD_SCRIPT_VERSION ' to '$NEW_SCRIPT_VERSION '"
118- runcmd " cd $SCRIPT_DIR && git pull --ff-only" &&
118+ runcmd " git -C $SCRIPT_DIR pull --ff-only" &&
119119 {
120120 printok " Self upgrade done"
121121 exec " $SCRIPT_DIR /xo-install.sh" " $@ "
@@ -132,7 +132,7 @@ function ScriptInfo {
132132
133133 set -o pipefail
134134
135- local SCRIPTVERSION=$( cd " $SCRIPT_DIR " 2> /dev/null && git rev-parse --short HEAD 2> /dev/null)
135+ local SCRIPTVERSION=$( git -C $SCRIPT_DIR rev-parse --short HEAD 2> /dev/null)
136136
137137 [ -z " $SCRIPTVERSION " ] && SCRIPTVERSION=" undefined"
138138 echo " Running script version $SCRIPTVERSION with config:" >> " $LOGFILE "
@@ -477,8 +477,7 @@ function InstallAdditionalXOPlugins {
477477 runcmd " mkdir -p \" $PLUGIN_SRC_DIR \" "
478478 runcmd " git clone \" ${x} \" \" $PLUGIN_SRC_DIR \" "
479479 else
480- runcmd " cd \" $PLUGIN_SRC_DIR \" && git pull --ff-only"
481- runcmd " cd $SCRIPT_DIR "
480+ runcmd " git -C \" $PLUGIN_SRC_DIR \" pull --ff-only"
482481 fi
483482
484483 runcmd " cp -r $PLUGIN_SRC_DIR $INSTALLDIR /xo-builds/xen-orchestra-$TIME /packages/"
@@ -589,10 +588,10 @@ function PrepInstall {
589588 runcmd " mkdir -p \" $XO_SRC_DIR \" "
590589 runcmd " git clone \" ${REPOSITORY} \" \" $XO_SRC_DIR \" "
591590 else
592- runcmd " cd \" $XO_SRC_DIR \" && git remote set-url origin \" ${REPOSITORY} \" && \
593- git fetch --prune && \
594- git reset --hard origin/master && \
595- git clean -xdff"
591+ runcmd " git -C \" $XO_SRC_DIR \" remote set-url origin \" ${REPOSITORY} \" && \
592+ git -C \" $XO_SRC_DIR \" fetch --prune && \
593+ git -C \" $XO_SRC_DIR \" reset --hard origin/master && \
594+ git -C \" $XO_SRC_DIR \" clean -xdff"
596595 fi
597596
598597 # Deploy the latest xen-orchestra source to the new install directory.
@@ -606,24 +605,26 @@ function PrepInstall {
606605 echo
607606 printinfo " Checking out source code from branch/commit '$BRANCH '"
608607
609- runcmd " cd $INSTALLDIR /xo-builds/xen-orchestra-$TIME && git checkout $BRANCH "
610- runcmd " cd $SCRIPT_DIR "
608+ runcmd " git -C $INSTALLDIR /xo-builds/xen-orchestra-$TIME checkout $BRANCH "
611609 fi
612610
613611 # Check if the new repo is any different from the currently-installed
614612 # one. If not, then skip the build and delete the repo we just cloned.
615613
616614 # Get the commit ID of the to-be-installed xen-orchestra.
617- local NEW_REPO_HASH=$( runcmd_stdout " cd $INSTALLDIR /xo-builds/xen-orchestra-$TIME && git rev-parse HEAD" )
618- local NEW_REPO_HASH_SHORT=$( runcmd_stdout " cd $INSTALLDIR /xo-builds/xen-orchestra-$TIME && git rev-parse --short HEAD" )
619- runcmd " cd $SCRIPT_DIR "
615+ local NEW_REPO_HASH=$( runcmd_stdout " git -C $INSTALLDIR /xo-builds/xen-orchestra-$TIME rev-parse HEAD" )
616+ local NEW_REPO_HASH_SHORT=$( runcmd_stdout " git -C $INSTALLDIR /xo-builds/xen-orchestra-$TIME rev-parse --short HEAD" )
620617
621618 # Get the commit ID of the currently-installed xen-orchestra (if one
622619 # exists).
623620 if [[ -L " $INSTALLDIR /$XO_SVC " ]] && [[ -n $( runcmd_stdout " readlink -e $INSTALLDIR /$XO_SVC " ) ]]; then
624- local OLD_REPO_HASH=$( runcmd_stdout " cd $INSTALLDIR /$XO_SVC && git rev-parse HEAD" )
625- local OLD_REPO_HASH_SHORT=$( runcmd_stdout " cd $INSTALLDIR /$XO_SVC && git rev-parse --short HEAD" )
626- runcmd " cd $SCRIPT_DIR "
621+ if [[ " $XOUSER " != " root" ]]; then
622+ local OLD_REPO_HASH=$( runcmd_stdout " runuser -u $XOUSER -- git -C $INSTALLDIR /$XO_SVC rev-parse HEAD" )
623+ local OLD_REPO_HASH_SHORT=$( runcmd_stdout " runuser -u $XOUSER -- git -C $INSTALLDIR /$XO_SVC rev-parse --short HEAD" )
624+ else
625+ local OLD_REPO_HASH=$( runcmd_stdout " git -C $INSTALLDIR /$XO_SVC rev-parse HEAD" )
626+ local OLD_REPO_HASH_SHORT=$( runcmd_stdout " git -C $INSTALLDIR /$XO_SVC rev-parse --short HEAD" )
627+ fi
627628 else
628629 # If there's no existing installation, then we definitely want
629630 # to proceed with the bulid.
0 commit comments