Created
February 26, 2018 05:52
-
-
Save Cat7373/a87c55e24db5640dd120cac6bc73e5ba to your computer and use it in GitHub Desktop.
self update shell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
SCRIPT=$(readlink -f "$0") | |
SCRIPTPATH=$(dirname "$SCRIPT") | |
SCRIPTNAME="$0" | |
ARGS="$@" | |
BRANCH="master" | |
self_update() { | |
cd $SCRIPTPATH | |
git fetch | |
[ -n $(git diff --name-only origin/$BRANCH | grep $SCRIPTNAME) ] && { | |
echo "Found a new version of me, updating myself..." | |
git pull --force | |
git checkout $BRANCH | |
git pull --force | |
echo "Running the new version..." | |
exec "$SCRIPTNAME" "$@" | |
# Now exit this old instance | |
exit 1 | |
} | |
echo "Already the latest version." | |
} | |
main() { | |
echo "Running" | |
} | |
self_update | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment