@@ -103,18 +103,18 @@ function SelfUpgrade {
103103 fi
104104
105105 if [[ -d " $SCRIPT_DIR /.git" ]] && [[ -n $( runcmd_stdout " command -v git" ) ]]; then
106- local REMOTE=" $( runcmd_stdout " cd $SCRIPT_DIR && git config --get remote.origin.url" ) "
106+ local REMOTE=" $( runcmd_stdout " git -C $SCRIPT_DIR config --get remote.origin.url" ) "
107107 if [[ " $REMOTE " == * " ronivay/XenOrchestraInstallerUpdater" * ]]; then
108- if [[ -n $( runcmd_stdout " cd $SCRIPT_DIR && git status --porcelain" ) ]]; then
108+ if [[ -n $( runcmd_stdout " git -C $SCRIPT_DIR status --porcelain" ) ]]; then
109109 printfail " Local changes in this script directory. Not attempting to self upgrade"
110110 return 0
111111 fi
112- runcmd " cd $SCRIPT_DIR && git fetch"
113- local OLD_SCRIPT_VERSION=" $( runcmd_stdout " cd $SCRIPT_DIR && git rev-parse --short HEAD" ) "
114- local NEW_SCRIPT_VERSION=" $( runcmd_stdout " cd $SCRIPT_DIR && git rev-parse --short FETCH_HEAD" ) "
115- if [[ $( runcmd_stdout " cd $SCRIPT_DIR && git diff --name-only @{upstream}| grep xo-install.sh" ) ]]; then
112+ runcmd " git -C $SCRIPT_DIR fetch"
113+ local OLD_SCRIPT_VERSION=" $( runcmd_stdout " git -C $SCRIPT_DIR rev-parse --short HEAD" ) "
114+ local NEW_SCRIPT_VERSION=" $( runcmd_stdout " git -C $SCRIPT_DIR rev-parse --short FETCH_HEAD" ) "
115+ if [[ $( runcmd_stdout " git -C $SCRIPT_DIR diff --name-only @{upstream}| grep xo-install.sh" ) ]]; then
116116 printinfo " Newer version of script available, attempting to self upgrade from '$OLD_SCRIPT_VERSION ' to '$NEW_SCRIPT_VERSION '"
117- runcmd " cd $SCRIPT_DIR && git pull --ff-only" &&
117+ runcmd " git -C $SCRIPT_DIR pull --ff-only" &&
118118 {
119119 printok " Self upgrade done"
120120 exec " $SCRIPT_DIR /xo-install.sh" " $@ "
@@ -131,7 +131,7 @@ function ScriptInfo {
131131
132132 set -o pipefail
133133
134- local SCRIPTVERSION=$( cd " $SCRIPT_DIR " 2> /dev/null && git rev-parse --short HEAD 2> /dev/null)
134+ local SCRIPTVERSION=$( git -C $SCRIPT_DIR rev-parse --short HEAD 2> /dev/null)
135135
136136 [ -z " $SCRIPTVERSION " ] && SCRIPTVERSION=" undefined"
137137 echo " Running script version $SCRIPTVERSION with config:" >> " $LOGFILE "
@@ -489,8 +489,7 @@ function InstallAdditionalXOPlugins {
489489 runcmd " mkdir -p \" $PLUGIN_SRC_DIR \" "
490490 runcmd " git clone \" ${x} \" \" $PLUGIN_SRC_DIR \" "
491491 else
492- runcmd " cd \" $PLUGIN_SRC_DIR \" && git pull --ff-only"
493- runcmd " cd $SCRIPT_DIR "
492+ runcmd " git -C \" $PLUGIN_SRC_DIR \" pull --ff-only"
494493 fi
495494
496495 runcmd " cp -r $PLUGIN_SRC_DIR $INSTALLDIR /xo-builds/xen-orchestra-$TIME /packages/"
@@ -601,10 +600,10 @@ function PrepInstall {
601600 runcmd " mkdir -p \" $XO_SRC_DIR \" "
602601 runcmd " git clone \" ${REPOSITORY} \" \" $XO_SRC_DIR \" "
603602 else
604- runcmd " cd \" $XO_SRC_DIR \" && git remote set-url origin \" ${REPOSITORY} \" && \
605- git fetch --prune && \
606- git reset --hard origin/master && \
607- git clean -xdff"
603+ runcmd " git -C \" $XO_SRC_DIR \" remote set-url origin \" ${REPOSITORY} \" && \
604+ git -C \" $XO_SRC_DIR \" fetch --prune && \
605+ git -C \" $XO_SRC_DIR \" reset --hard origin/master && \
606+ git -C \" $XO_SRC_DIR \" clean -xdff"
608607 fi
609608
610609 # Deploy the latest xen-orchestra source to the new install directory.
@@ -618,24 +617,26 @@ function PrepInstall {
618617 echo
619618 printinfo " Checking out source code from branch/commit '$BRANCH '"
620619
621- runcmd " cd $INSTALLDIR /xo-builds/xen-orchestra-$TIME && git checkout $BRANCH "
622- runcmd " cd $SCRIPT_DIR "
620+ runcmd " git -C $INSTALLDIR /xo-builds/xen-orchestra-$TIME checkout $BRANCH "
623621 fi
624622
625623 # Check if the new repo is any different from the currently-installed
626624 # one. If not, then skip the build and delete the repo we just cloned.
627625
628626 # Get the commit ID of the to-be-installed xen-orchestra.
629- local NEW_REPO_HASH=$( runcmd_stdout " cd $INSTALLDIR /xo-builds/xen-orchestra-$TIME && git rev-parse HEAD" )
630- local NEW_REPO_HASH_SHORT=$( runcmd_stdout " cd $INSTALLDIR /xo-builds/xen-orchestra-$TIME && git rev-parse --short HEAD" )
631- runcmd " cd $SCRIPT_DIR "
627+ local NEW_REPO_HASH=$( runcmd_stdout " git -C $INSTALLDIR /xo-builds/xen-orchestra-$TIME rev-parse HEAD" )
628+ local NEW_REPO_HASH_SHORT=$( runcmd_stdout " git -C $INSTALLDIR /xo-builds/xen-orchestra-$TIME rev-parse --short HEAD" )
632629
633630 # Get the commit ID of the currently-installed xen-orchestra (if one
634631 # exists).
635632 if [[ -L " $INSTALLDIR /$XO_SVC " ]] && [[ -n $( runcmd_stdout " readlink -e $INSTALLDIR /$XO_SVC " ) ]]; then
636- local OLD_REPO_HASH=$( runcmd_stdout " cd $INSTALLDIR /$XO_SVC && git rev-parse HEAD" )
637- local OLD_REPO_HASH_SHORT=$( runcmd_stdout " cd $INSTALLDIR /$XO_SVC && git rev-parse --short HEAD" )
638- runcmd " cd $SCRIPT_DIR "
633+ if [[ " $XOUSER " != " root" ]]; then
634+ local OLD_REPO_HASH=$( runcmd_stdout " runuser -u $XOUSER -- git -C $INSTALLDIR /$XO_SVC rev-parse HEAD" )
635+ local OLD_REPO_HASH_SHORT=$( runcmd_stdout " runuser -u $XOUSER -- git -C $INSTALLDIR /$XO_SVC rev-parse --short HEAD" )
636+ else
637+ local OLD_REPO_HASH=$( runcmd_stdout " git -C $INSTALLDIR /$XO_SVC rev-parse HEAD" )
638+ local OLD_REPO_HASH_SHORT=$( runcmd_stdout " git -C $INSTALLDIR /$XO_SVC rev-parse --short HEAD" )
639+ fi
639640 else
640641 # If there's no existing installation, then we definitely want
641642 # to proceed with the bulid.
0 commit comments