Advertisement
Guest User

Untitled

a guest
Sep 5th, 2015
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.91 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. #**********************************************************************************
  4. #title :deploy.sh
  5. #description :This script will deploy and update laravel project from git repo.
  6. #author :Maxel Thierry
  7. #version :1.0
  8. #usage :./deploy.sh [branchName]
  9. #**********************************************************************************
  10.  
  11. # Vars ==================================================
  12. # Repo url
  13. repo="git@github.com:user/repo.git"
  14. # Required dependencies
  15. dependencies=('node' 'npm' 'composer' 'less' 'gulp' 'bower')
  16.  
  17. # Functions ==============================================
  18.  
  19. # return 1 if global command line program installed, else 0
  20. # example
  21. # echo "node: $(program_is_installed node)"
  22. function program_is_installed {
  23. # set to 1 initially
  24. local return_=1
  25. # set to 0 if not found
  26. type $1 >/dev/null 2>&1 || { local return_=0; }
  27. # return value
  28. echo "$return_"
  29. }
  30.  
  31. # return 1 if local npm package is installed at ./node_modules, else 0
  32. # example
  33. # echo "gruntacular : $(npm_package_is_installed gruntacular)"
  34. function npm_package_is_installed {
  35. # set to 1 initially
  36. local return_=1
  37. # set to 0 if not found
  38. ls node_modules | grep $1 >/dev/null 2>&1 || { local return_=0; }
  39. # return value
  40. echo "$return_"
  41. }
  42.  
  43.  
  44. # display a message in red with a cross by it
  45. # example
  46. # echo echo_fail "No"
  47. function echo_fail {
  48. # echo first argument in red
  49. printf "\e[31m✘ ${1}"
  50. # reset colours back to normal
  51. tput sgr0
  52. # set fail var
  53. fail=true
  54. }
  55.  
  56. # display a message in green with a tick by it
  57. # example
  58. # echo echo_fail "Yes"
  59. function echo_pass {
  60. # echo first argument in green
  61. printf "\e[32m✔ ${1}"
  62. # reset colours back to normal
  63. tput sgr0
  64. }
  65.  
  66. # echo pass or fail
  67. # example
  68. # echo echo_if 1 "Passed"
  69. # echo echo_if 0 "Failed"
  70. function echo_if {
  71. if [ $1 == 1 ]; then
  72. echo_pass $2
  73. else
  74. echo_fail $2
  75. fi
  76. }
  77.  
  78. # Test required =========================================
  79. echo "➤ Check dependencies"
  80. fail=false
  81. for i in "${dependencies[@]}"
  82. do
  83. echo "$(echo_if $(program_is_installed $i)) $i"
  84. done
  85. if [ -z "$fail" ]; then
  86. printf "\e[31m Install dependencies before project! ☠ \n";
  87. tput sgr0
  88. exit;
  89. else
  90. printf "\e[32m Well done! all dependencies are installed ! 🍺 \n";
  91. tput sgr0
  92. fi
  93.  
  94. # Install ==============================================
  95. echo ""
  96. echo "➤ Get or update repo"
  97.  
  98. # Exit if no release
  99. if [ ! -d "gitrepo" ]; then
  100. git clone $repo gitrepo
  101. else
  102. branch=master
  103. if [ ! -z "$1" ]; then
  104. branch="$1"
  105. fi
  106. cd gitrepo
  107. git checkout $branch
  108. git pull
  109. cd ..
  110. fi
  111.  
  112. cp -r ./gitrepo ./deploying
  113. cp .env ./deploying/.env
  114.  
  115. cd ./deploying
  116.  
  117.  
  118. echo ""
  119. echo "➤ Install project"
  120.  
  121. # Install release dependencies
  122. composer install
  123. npm install
  124. bower install --allow-root
  125.  
  126. # Gulp
  127. gulp --production
  128.  
  129. # Bdd migration
  130. php artisan migrate
  131.  
  132. cd ..
  133. cp -r ./deploying ./deployed
  134. rm -rf ./deploying
  135.  
  136. # Edit owner
  137. chown -R www-data:www-data ./deployed
  138.  
  139. # Edit access permissions
  140. chmod -R 0755 ./deployed
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement