Advertisement
Guest User

Untitled

a guest
May 24th, 2017
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.74 KB | None | 0 0
  1. #!/bin/bash
  2. # timestamp
  3. NOW=$(date +"%Y%m%d-%H%M")
  4. # home
  5. # general repo path
  6. REPOPATH="siterepo"
  7. # Where to store the log information about the updates
  8. LOGFILE="$HOME/$REPOPATH/post-receive-$NOW.log"
  9. # target branch
  10. target_branch="master"
  11. # The deployed directory (the running site)
  12. DEPLOYDIR="$HOME/public_html"
  13. # path to build
  14. WORK_TREE="$HOME/$REPOPATH/build"
  15. #[ ! -d "$WORK_TREE" ] && mkdir $WORK_TREE
  16.  
  17. echo " /===============================" | tee -a "$LOGFILE"
  18. echo " | DEPLOYMENT" | tee -a "$LOGFILE"
  19. echo " | Date : $NOW" | tee -a "$LOGFILE"
  20. echo " | Repo : $REPOPATH" | tee -a "$LOGFILE"
  21. echo " | Target branch: $target_branch" | tee -a "$LOGFILE"
  22. echo " | Deploy dir: $DEPLOYDIR" | tee -a "$LOGFILE"
  23. echo " | Work tree: $WORK_TREE" | tee -a "$LOGFILE"
  24.  
  25. #GIT_DIR="/home/karolk/siterepo/site.git"
  26. #[ ! -d "$GIT_DIR" ] && echo "ERROR: $GIT_DIR not found!" && exit 1
  27. #echo "Git dir: $GIT_DIR" | tee -a "$LOGFILE"
  28.  
  29. # Composer setup
  30. export PATH=$PATH:/opt/cpanel/composer/bin
  31. alias composer="php -d allow_url_fopen=1 -d detect_unicode=0 $(which composer)"
  32.  
  33. ## store the arguments given to the script
  34. read oldrev newrev refname
  35.  
  36. ## Record the fact that the push has been received
  37. echo " | Received Push Request at $( date +%F )" | tee -a "$LOGFILE"
  38. echo -e " | Old SHA: $oldrev" | tee -a "$LOGFILE"
  39. echo -e " | New SHA: $newrev" | tee -a "$LOGFILE"
  40. echo " | Branch Name: $refname" | tee -a "$LOGFILE"
  41. GIT_WORK_TREE=$WORK_TREE git checkout $target_branch -f &>> "$LOGFILE"
  42. echo " | Code updated" | tee -a "$LOGFILE"
  43.  
  44. cd "$WORK_TREE" && composer install &>> $LOGFILE
  45. echo " | Composer install done" | tee -a "$LOGFILE"
  46.  
  47. cp -a src/* $DEPLOYDIR
  48. echo " | Files deployed online" | tee -a "$LOGFILE"
  49.  
  50. cd "$DEPLOYDIR"
  51. find . -type f -exec chmod -R 644 {} \;
  52. find . -type d -exec chmod -R 755 {} \;
  53. cd "vendor"
  54. find . -type d -iname .git | xargs rm -rf
  55. find . -type d -iname tests | xargs rm -rf
  56. find . -type d -iname Tests | xargs rm -rf
  57. cd "composer"
  58. find . -type f -name 'autoload_*' | xargs sed -i "s_baseDir . '/src/_baseDir . '/_g" | tee -a "$LOGFILE"
  59. find . -type f -name 'autoload_*' -exec sed -i 's|dirname(dirname($vendorDir))|dirname($vendorDir)|g' {} \;
  60. #find -type f -name 'autoload_*' | xargs sed -i "s_dirname(dirname($vendorDir))_dirname($vendorDir)_g" | tee -a "$LOGFILE"
  61. find . -type f -name 'autoload_*' -exec sed -i "s|__DIR__ . '/../../..' . '/src|__DIR__ . '/../..' . '|g" {} \;
  62. #find . -type f -name 'autoload_*' | xargs sed -i "s|__DIR__ . '/../../..' . '/src|__DIR__ . '/../..' . '|g" | tee -a "$LOGFILE"
  63.  
  64. printenv | while read -r line; do echo " | $line"; done &>> "$LOGFILE"
  65. #git tag release_$NOW $target_branch
  66. echo " | Tag name : release_$NOW" | tee -a "$LOGFILE"
  67. # end
  68. echo " /===============================" | tee -a "$LOGFILE"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement