Created
October 1, 2015 21:34
-
-
Save jesusgoku/5e1d9f6b5b6d468ad767 to your computer and use it in GitHub Desktop.
Symfony2 deploy script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| COMPOSER_EXECUTABLE="composer" | |
| NPM_EXECUTABLE="npm" | |
| BOWER_EXECUTABLE="bower" | |
| CONSOLE_COMMAND="php app/console" | |
| SYMFONY_ENV="prod" | |
| SET_PERMISSIONS=false | |
| PREFIX="eval" | |
| SHOW_HELP=false | |
| # Process parameters | |
| for i in "$@"; do | |
| case $i in | |
| -e=*|--env=*) | |
| SYMFONY_ENV="${i#*=}" | |
| shift | |
| ;; | |
| -p|--permissions) | |
| SET_PERMISSIONS=true | |
| ;; | |
| -n|--dry-run) | |
| PREFIX="echo" | |
| ;; | |
| -h|--help) | |
| SHOW_HELP=true | |
| ;; | |
| esac | |
| done | |
| function showHelp | |
| { | |
| echo | |
| echo "Usage:" | |
| echo | |
| echo "$0 [-n|--dry-run] [-p|--permissions] [[-e|--env]=[dev|prod]]" | |
| echo | |
| printf "\\t%-20s %s\\n" "-n|--dry-run" "Simulate run" | |
| printf "\\t%-20s %s\\n" "-p|--permissions" "Set permissions for symfony folders" | |
| printf "\\t%-20s %s\\n" "-e|--env" "Set environment. Default: prod" | |
| echo | |
| } | |
| function existsCommand | |
| { | |
| if $(command -v "$1" >/dev/null 2>&1); then return 0; else return 1; fi; | |
| } | |
| function existsCommandAndAbort | |
| { | |
| if ! $(existsCommand $1); then | |
| echo "I require ${1} but it's not installed. Aborting."; | |
| exit 1; | |
| fi; | |
| } | |
| function downloadComposer | |
| { | |
| $PREFIX php -r "readfile('https://getcomposer.org/installer');" | php | |
| } | |
| function existsFolder | |
| { | |
| if [ -d "$1" ]; then return 0; else return 1; fi; | |
| } | |
| function existsFile | |
| { | |
| if [ -f "$1" ]; then return 0; else return 1; fi; | |
| } | |
| function installVendors | |
| { | |
| if ! $(existsFolder "./vendor"); then | |
| if ! $(existsCommand composer); then | |
| downloadComposer | |
| COMPOSER_EXECUTABLE="php composer.phar" | |
| fi | |
| $PREFIX $COMPOSER_EXECUTABLE install; | |
| fi | |
| } | |
| function installBowerAssets | |
| { | |
| if $(existsFile "./bower.json"); then | |
| if ! $(existsCommand bower); then | |
| existsCommandAndAbort npm | |
| $PREFIX $NPM_EXECUTABLE install -g bower | |
| fi | |
| $PREFIX $BOWER_EXECUTABLE install --production | |
| fi; | |
| } | |
| function setSymfonyPermissions | |
| { | |
| echo rm -rf app/cache/* app/logs/** | |
| HTTPDUSER=`ps aux | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data|[n]ginx' | grep -v root | head -1 | cut -d\ -f1` | |
| if $(existsCommand setfacl); then | |
| $PREFIX sudo setfacl -R -m u:"$HTTPDUSER":rwX -m u:`whoami`:rwX app/cache app/logs | |
| $PREFIX sudo setfacl -dR -m u:"$HTTPDUSER":rwX -m u:`whoami`:rwX app/cache app/logs | |
| else | |
| $PREFIX sudo chmod +a "$HTTPDUSER allow delete,write,append,file_inherit,directory_inherit" app/cache app/logs | |
| $PREFIX sudo chmod +a "`whoami` allow delete,write,append,file_inherit,directory_inherit" app/cache app/logs | |
| fi | |
| } | |
| if $SHOW_HELP; then | |
| showHelp | |
| exit; | |
| fi | |
| installVendors | |
| installBowerAssets | |
| $SET_PERMISSIONS && setSymfonyPermissions | |
| $PREFIX $CONSOLE_COMMAND clear:cache --env="$SYMFONY_ENV" | |
| $PREFIX $CONSOLE_COMMAND assets:install --symlink | |
| $PREFIX $CONSOLE_COMMAND assetic:dump --env="$SYMFONY_ENV" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment