From c35208061c8b991fbd55064f55b5d934bd4316bf Mon Sep 17 00:00:00 2001 From: Kjeld Schouten-Lebbing Date: Tue, 26 May 2020 15:20:44 +0200 Subject: [PATCH] Make auto-update git aware (#133) * Make auto-update git aware Fixes #106 * Some slight tweaking and bug-fixing --- global.sh | 34 +++++++++++++++++++++------------- jailman.sh | 3 +-- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/global.sh b/global.sh index 37a1d607..1276b098 100755 --- a/global.sh +++ b/global.sh @@ -24,21 +24,29 @@ parse_yaml() { # automatic update function gitupdate() { -git remote add upstream https://github.com/jailmanager/jailman.git > /dev/null 2>&1 -echo "checking for updates using Branch: $1" -git fetch upstream > /dev/null 2>&1 -git update-index -q --refresh > /dev/null 2>&1 -CHANGED=$(git diff --name-only "$1") -if [ -n "$CHANGED" ]; +if [ "$(git config --get remote.origin.url)" = "https://github.com/Ornias1993/jailman" ] then - echo "script requires update" - git reset --hard > /dev/null 2>&1 - git checkout "${1}" > /dev/null 2>&1 - git pull > /dev/null 2>&1 - echo "script updated, please restart the script manually" - exit 1 + echo "The repository has been moved, please reinstall using the new repository: jailmanager/jailman" + exit 1 +fi +if [ "$1" = "" ] || [ "$1" = "HEAD" ]; +then + echo "Detatched or invalid GIT HEAD detected, please reinstall" else - echo "script up-to-date" + echo "checking for updates using Branch: $1" + git fetch > /dev/null 2>&1 + git update-index -q --refresh > /dev/null 2>&1 + CHANGED=$(git diff --name-only "$1") + if [ -n "$CHANGED" ]; + then + echo "script requires update" + git reset --hard > /dev/null 2>&1 + git pull > /dev/null 2>&1 + echo "script updated, please restart the script manually" + exit 1 + else + echo "script up-to-date" + fi fi } diff --git a/jailman.sh b/jailman.sh index e68a013a..1841bd53 100755 --- a/jailman.sh +++ b/jailman.sh @@ -20,8 +20,7 @@ if ! [ "$(id -u)" = 0 ]; then fi # Auto Update -BRANCH="upstream/minor-dev" -gitupdate "${BRANCH}" +gitupdate $(git for-each-ref --format='%(upstream:short)' "$(git symbolic-ref -q HEAD)") || exit 1 # If no option is given, point to the help menu if [ $# -eq 0 ]