Advertisement
Guest User

Untitled

a guest
Sep 19th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. #!/bin/sh
  2. #
  3. # ///////////////////////
  4. # // Code auto-updater //
  5. # ///////////////////////
  6. #
  7. # Update all site's codebases by pulling the latest changes to master branch,
  8. # preserving any existing work in the process.
  9.  
  10. # NOTE: This script is designed to be run from whatever environment Git lives in
  11. #
  12.  
  13. SOURCE=${1:-~/var/www/transfer/databases-all.txt}
  14.  
  15. if [ ! -f "$SOURCE" ]; then
  16. 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"
  17. exit
  18. fi
  19.  
  20. echo -e "\nUpdating all master branches for sites listed in '$SOURCE'\n";
  21.  
  22. while read -r site; do
  23.  
  24. # Put the site information in a variable for easier access
  25. SITE=${site}
  26.  
  27. echo -e "\n-------------------------------\n Updating code for $SITE\n"
  28. cd ~/Documents/repositories/"$SITE" || exit
  29.  
  30. # Get the name of the current branch so we can put things back how they were after updating master
  31. BRANCH=$(git rev-parse --abbrev-ref HEAD)
  32.  
  33. if [ "${BRANCH}" = 'master' ]; then
  34. echo "Already on master branch, pulling down latest tags, refs and changes..." && git fetch --tags && git pull --ff-only
  35. else
  36. # Save any non-committed work so we aren't being destructive, then checkout master
  37. echo -e "\nStashing any uncommitted changes...\n" && git stash
  38. echo -e "\nChecking out master branch...\n" && git checkout master
  39. echo -e "\nPulling down latest changes and tags...\n" && git fetch --tags && git pull --ff-only
  40.  
  41. # Go back to the original branch and put the changes back
  42. echo -e "\nPutting things back how they were...\n" && git checkout "$BRANCH"
  43. echo -e "\nRe-applying those uncommitted changes, if any...\n" && git stash apply
  44. fi
  45. done < "$SOURCE"
  46.  
  47. echo -e "\n-------------------------------\nScript complete!\n"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement