diff --git a/lib/functions.sh b/lib/functions.sh old mode 100755 new mode 100644 index 1ac7d60..9296414 --- a/lib/functions.sh +++ b/lib/functions.sh @@ -119,9 +119,13 @@ fixPermissions() { source lib/monitoring.sh -fail_and_report() { +report_error() { log ERROR "$2" hc_send $1 "$2" +} + +fail_and_report() { + report_error $@ exit $1 } @@ -135,8 +139,3 @@ setHostname() { ##Setting Network properties # currently not needed #export HOSTIP=$(MSYS_NO_PATHCONV=1 docker run --rm --add-host=host.docker.internal:host-gateway ubuntu cat /etc/hosts | grep 'host.docker.internal' | awk '{print $1}'); - -export PRODUCTION="false"; -if [ "$(git branch --show-current)" == "main" ]; then - export PRODUCTION="true"; -fi diff --git a/lib/prerequisites.sh b/lib/prerequisites.sh index 859b690..c2a4e34 100755 --- a/lib/prerequisites.sh +++ b/lib/prerequisites.sh @@ -71,7 +71,10 @@ else exit 1 fi -log INFO "Success - all prerequisites are met!" -hc_send log "Success - all prerequisites are met!" +COMMIT_ETC=$(git -C /etc/bridgehead rev-parse HEAD | cut -c -8) +COMMIT_SRV=$(git -C /srv/docker/bridgehead rev-parse HEAD | cut -c -8) + +log INFO "Success - all prerequisites are met! Git commits: etc:$COMMIT_ETC srv:$COMMIT_SRV" +hc_send log "Success - all prerequisites are met! Git commits: etc:$COMMIT_ETC srv:$COMMIT_SRV" exit 0 diff --git a/lib/update-bridgehead.sh b/lib/update-bridgehead.sh index 7212d13..69b3887 100755 --- a/lib/update-bridgehead.sh +++ b/lib/update-bridgehead.sh @@ -36,6 +36,11 @@ CHANGES="" git_updated="false" for DIR in /etc/bridgehead $(pwd); do log "INFO" "Checking for updates to git repo $DIR ..." + OUT="$(git -C $DIR status --porcelain)" + if [ -n "$OUT" ]; then + log WARN "The working directory $DIR is modified. Changed files: $OUT" + report_error 1 "The working directory $DIR is modified. Changed files: $OUT" + fi if [ "$(git -C $DIR config --get credential.helper)" != "$CREDHELPER" ]; then log "INFO" "Configuring repo to use bridgehead git credential helper." git -C $DIR config credential.helper "$CREDHELPER" @@ -43,13 +48,15 @@ for DIR in /etc/bridgehead $(pwd); do old_git_hash="$(git -C $DIR rev-parse --verify HEAD)" if [ -z "$HTTP_PROXY_URL" ]; then log "INFO" "Git is using no proxy!" - git -C $DIR fetch 2>&1 - git -C $DIR pull 2>&1 + OUT=$(git -C $DIR fetch 2>&1 && git -C $DIR pull 2>&1) else log "INFO" "Git is using proxy ${HTTP_PROXY_URL} from ${CONFFILE}" - git -c http.proxy=$HTTP_PROXY_URL -c https.proxy=$HTTPS_PROXY_URL -C $DIR fetch 2>&1 - git -c http.proxy=$HTTP_PROXY_URL -c https.proxy=$HTTPS_PROXY_URL -C $DIR pull 2>&1 + OUT=$(git -c http.proxy=$HTTP_PROXY_URL -c https.proxy=$HTTPS_PROXY_URL -C $DIR fetch 2>&1 && git -c http.proxy=$HTTP_PROXY_URL -c https.proxy=$HTTPS_PROXY_URL -C $DIR pull 2>&1) fi + if [ $? -ne 0 ]; then + report_error 1 "Unable to update git $DIR: $OUT" + fi + new_git_hash="$(git -C $DIR rev-parse --verify HEAD)" if [ "$old_git_hash" != "$new_git_hash" ]; then CHANGE="Updated git repository in ${DIR} from commit $old_git_hash to $new_git_hash"