Skip to content

Commit

Permalink
add files for disable, disableHardReset, checkEveryTime
Browse files Browse the repository at this point in the history
  • Loading branch information
joe128 committed Nov 25, 2021
1 parent d5ef30a commit b3dde4d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
disableAutoUpdate
.autoUpdate*
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## [2.0.0] - 2021-11-25
### Changed
- change ``disableAutoUpdate`` to ``.autoUpdateDisable``

### Added
- add ``.autoUpdateDisableHardReset`` to skip a local git-hard-reset
- add ``.autoUpdateCheckEveryTime`` to check updates every call
- add ``[ERR]`` and ``[WARN]`` to log-messages

## [1.0.0] - 2021-11-05
### Added
- first Release, including
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# autoupdateBashScript
template to auto-update bash-scripts
template to auto-update a project over bash-script

## configuration
* set AUTOUPDATE_DISABLE or add file ``disableAutoUpdate`` to disable auto-update
* set AUTOUPDATE_NO_LOCAL_RESET to skip a local git-hard-reset
* set AUTOUPDATE_CHECK_EVERY_TIME to check updates every call (default once per day)
* set AUTOUPDATE_DISABLE or add file ``.autoUpdateDisable`` to disable auto-update
* set AUTOUPDATE_NO_LOCAL_RESET or add file ``.autoUpdateDisableHardReset`` to skip a local git-hard-reset
* set AUTOUPDATE_CHECK_EVERY_TIME or add file ``.autoUpdateCheckEveryTime`` to check updates every call (default once per day)
* set AUTOUPDATE_BRANCH to use a different branch (default: main)
* set AUTOUPDATE_GIT_BIN if there is a problem detecting git-binary
11 changes: 6 additions & 5 deletions anyScript.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,32 @@ if [ -z $gitbin ]; then
elif command -v /opt/bin/git > /dev/null; then
gitbin="/opt/bin/git"
else
echo "[autoUpdate] Git not found, define env-var 'AUTOUPDATE_GIT_BIN' to use autoupdate."
echo "[WARN][autoUpdate] Git not found, define env-var 'AUTOUPDATE_GIT_BIN' to use autoupdate."
gitbin=""
fi
fi

# run auto-update daily, not if file disableAutoUpdate exists or env AUTOUPDATE_DISABLE is set
if [ ! -z "${gitbin}" ] && [ ! -f "$(dirname "$0")/disableAutoUpdate" ] && [ -z "$AUTOUPDATE_DISABLE" ] && [ -d "$(dirname "$0")/.git" ]; then
if [ -n "${gitbin}" ] && [ ! -f "$(dirname "$0")/.autoUpdateDisable" ] && [ -z "$AUTOUPDATE_DISABLE" ] && [ -d "$(dirname "$0")/.git" ]; then
[ -z "${AUTOUPDATE_NO_LOCAL_RESET}" ] && [ ! -f "$(dirname "$0")/.autoUpdateDisableHardReset" ] && doHardReset=1 || doHardReset=0
gitBranch=${AUTOUPDATE_BRANCH:=main}
scriptName=$(basename "$0")
today=$(date +'%Y-%m-%d')
autoUpdateStatusFile="/tmp/.${scriptName}-autoUpdate"
if [ -n "${AUTOUPDATE_CHECK_EVERY_TIME}" ] || [ ! -f "$autoUpdateStatusFile" ] || [ "${today}" != "$(date -r ${autoUpdateStatusFile} +'%Y-%m-%d')" ]; then
if [ -n "${AUTOUPDATE_CHECK_EVERY_TIME}" ] || [ -f "$(dirname "$0")/.autoUpdateCheckEveryTime" ] || [ ! -f "$autoUpdateStatusFile" ] || [ "${today}" != "$(date -r ${autoUpdateStatusFile} +'%Y-%m-%d')" ]; then
echo "[autoUpdate] Checking git-updates of ${scriptName}..."
touch "$autoUpdateStatusFile"
cd "$(dirname "$0")" || exit 1
$gitbin fetch
commits=$(git rev-list HEAD...origin/"$gitBranch" --count)
if [ $commits -gt 0 ]; then
echo "[autoUpdate] Found updates ($commits commits)..."
[ -z "${AUTOUPDATE_NO_LOCAL_RESET}" ] && $gitbin reset --hard
[ $doHardReset -gt 0 ] && $gitbin reset --hard
$gitbin pull --force
echo "[autoUpdate] Executing new version..."
exec "$(pwd -P)/${scriptName}" "$@"
# In case executing new fails
echo "[autoUpdate] Executing new version failed."
echo "[ERR][autoUpdate] Executing new version failed."
exit 1
fi
echo "[autoUpdate] No updates available."
Expand Down

0 comments on commit b3dde4d

Please sign in to comment.