Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- #
- # ///////////////////////
- # // Code auto-updater //
- # ///////////////////////
- #
- # Update all site's codebases by pulling the latest changes to master branch,
- # preserving any existing work in the process.
- # NOTE: This script is designed to be run from whatever environment Git lives in
- #
- SOURCE=${1:-~/var/www/transfer/databases-all.txt}
- if [ ! -f "$SOURCE" ]; then
- echo -e "\nSource file '$SOURCE' not found. Are you running this script in the right environment i.e. Windows vs Vagrant/Linux?\n\nUsage:\n\nbash code-update-all-master.sh /my/source/file.txt.\n"
- exit
- fi
- echo -e "\nUpdating all master branches for sites listed in '$SOURCE'\n";
- while read -r site; do
- # Put the site information in a variable for easier access
- SITE=${site}
- echo -e "\n-------------------------------\n Updating code for $SITE\n"
- cd ~/Documents/repositories/"$SITE" || exit
- # Get the name of the current branch so we can put things back how they were after updating master
- BRANCH=$(git rev-parse --abbrev-ref HEAD)
- if [ "${BRANCH}" = 'master' ]; then
- echo "Already on master branch, pulling down latest tags, refs and changes..." && git fetch --tags && git pull --ff-only
- else
- # Save any non-committed work so we aren't being destructive, then checkout master
- echo -e "\nStashing any uncommitted changes...\n" && git stash
- echo -e "\nChecking out master branch...\n" && git checkout master
- echo -e "\nPulling down latest changes and tags...\n" && git fetch --tags && git pull --ff-only
- # Go back to the original branch and put the changes back
- echo -e "\nPutting things back how they were...\n" && git checkout "$BRANCH"
- echo -e "\nRe-applying those uncommitted changes, if any...\n" && git stash apply
- fi
- done < "$SOURCE"
- echo -e "\n-------------------------------\nScript complete!\n"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement