Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #**********************************************************************************
- #title :deploy.sh
- #description :This script will deploy and update laravel project from git repo.
- #author :Maxel Thierry
- #version :1.0
- #usage :./deploy.sh [branchName]
- #**********************************************************************************
- # Vars ==================================================
- # Repo url
- repo="git@github.com:user/repo.git"
- # Required dependencies
- dependencies=('node' 'npm' 'composer' 'less' 'gulp' 'bower')
- # Functions ==============================================
- # return 1 if global command line program installed, else 0
- # example
- # echo "node: $(program_is_installed node)"
- function program_is_installed {
- # set to 1 initially
- local return_=1
- # set to 0 if not found
- type $1 >/dev/null 2>&1 || { local return_=0; }
- # return value
- echo "$return_"
- }
- # return 1 if local npm package is installed at ./node_modules, else 0
- # example
- # echo "gruntacular : $(npm_package_is_installed gruntacular)"
- function npm_package_is_installed {
- # set to 1 initially
- local return_=1
- # set to 0 if not found
- ls node_modules | grep $1 >/dev/null 2>&1 || { local return_=0; }
- # return value
- echo "$return_"
- }
- # display a message in red with a cross by it
- # example
- # echo echo_fail "No"
- function echo_fail {
- # echo first argument in red
- printf "\e[31m✘ ${1}"
- # reset colours back to normal
- tput sgr0
- # set fail var
- fail=true
- }
- # display a message in green with a tick by it
- # example
- # echo echo_fail "Yes"
- function echo_pass {
- # echo first argument in green
- printf "\e[32m✔ ${1}"
- # reset colours back to normal
- tput sgr0
- }
- # echo pass or fail
- # example
- # echo echo_if 1 "Passed"
- # echo echo_if 0 "Failed"
- function echo_if {
- if [ $1 == 1 ]; then
- echo_pass $2
- else
- echo_fail $2
- fi
- }
- # Test required =========================================
- echo "➤ Check dependencies"
- fail=false
- for i in "${dependencies[@]}"
- do
- echo "$(echo_if $(program_is_installed $i)) $i"
- done
- if [ -z "$fail" ]; then
- printf "\e[31m Install dependencies before project! ☠ \n";
- tput sgr0
- exit;
- else
- printf "\e[32m Well done! all dependencies are installed ! 🍺 \n";
- tput sgr0
- fi
- # Install ==============================================
- echo ""
- echo "➤ Get or update repo"
- # Exit if no release
- if [ ! -d "gitrepo" ]; then
- git clone $repo gitrepo
- else
- branch=master
- if [ ! -z "$1" ]; then
- branch="$1"
- fi
- cd gitrepo
- git checkout $branch
- git pull
- cd ..
- fi
- cp -r ./gitrepo ./deploying
- cp .env ./deploying/.env
- cd ./deploying
- echo ""
- echo "➤ Install project"
- # Install release dependencies
- composer install
- npm install
- bower install --allow-root
- # Gulp
- gulp --production
- # Bdd migration
- php artisan migrate
- cd ..
- cp -r ./deploying ./deployed
- rm -rf ./deploying
- # Edit owner
- chown -R www-data:www-data ./deployed
- # Edit access permissions
- chmod -R 0755 ./deployed
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement