I\'m writing a script to execute tasks before my end to end tests. One of the steps is to select the branch where those tests were written. Sometimes the script changes betw
This is the script I came up with:
#!/bin/bash
SCRIPT=$(readlink -f "$0")
SCRIPTPATH=$(dirname "$SCRIPT")
SCRIPTNAME="$0"
ARGS="$@"
BRANCH="Your_git_branch"
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