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
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 "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 "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 checkout "${1}" > /dev/null 2>&1
git pull > /dev/null 2>&1
echo "script updated, please restart the script manually"
exit 1
else
else
echo "script up-to-date"
fi
fi
}

View File

@ -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 ]