Make auto-update git aware (#133)

* Make auto-update git aware
Fixes #106

* Some slight tweaking and bug-fixing
This commit is contained in:
Kjeld Schouten-Lebbing 2020-05-26 15:20:44 +02:00 committed by GitHub
parent 80c0580707
commit c35208061c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 15 deletions

View File

@ -24,21 +24,29 @@ parse_yaml() {
# automatic update function # automatic update function
gitupdate() { gitupdate() {
git remote add upstream https://github.com/jailmanager/jailman.git > /dev/null 2>&1 if [ "$(git config --get remote.origin.url)" = "https://github.com/Ornias1993/jailman" ]
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" ];
then then
echo "script requires update" echo "The repository has been moved, please reinstall using the new repository: jailmanager/jailman"
git reset --hard > /dev/null 2>&1 exit 1
git checkout "${1}" > /dev/null 2>&1 fi
git pull > /dev/null 2>&1 if [ "$1" = "" ] || [ "$1" = "HEAD" ];
echo "script updated, please restart the script manually" then
exit 1 echo "Detatched or invalid GIT HEAD detected, please reinstall"
else 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 fi
} }

View File

@ -20,8 +20,7 @@ if ! [ "$(id -u)" = 0 ]; then
fi fi
# Auto Update # Auto Update
BRANCH="upstream/minor-dev" gitupdate $(git for-each-ref --format='%(upstream:short)' "$(git symbolic-ref -q HEAD)") || exit 1
gitupdate "${BRANCH}"
# If no option is given, point to the help menu # If no option is given, point to the help menu
if [ $# -eq 0 ] if [ $# -eq 0 ]