Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Script variables
- SF2_ENVIRONMENT=prod
- REPOSITORY=
- DEPLOY_BASE_DIR=/var/www
- DEPLOY_DIR=$DEPLOY_BASE_DIR/`date +%s`
- USAGE="Usage: $0 install|update [git_repository_url]"
- # Commands
- MKDIR=/bin/mkdir
- GIT=/usr/bin/git
- PHP=/usr/bin/php
- CP=/bin/cp
- RM=/bin/rm
- CHMOD=/bin/chmod
- LN=/bin/ln
- SERVICE=/sbin/service
- if [ $# -lt 1 ]; then
- echo -e $USAGE;
- exit;
- fi
- if [ $# -eq 2 ]; then
- REPOSITORY=$2
- elif [ -z $REPOSITORY ]; then
- echo -e 'No git repository specified!\nEither set the REPOSITORY variable in this script, or specify the git repository url argument';
- exit;
- fi
- if [ $1 == "install" ]; then
- echo 'Fetching the latest code...';
- $MKDIR $DEPLOY_DIR
- $GIT clone $REPOSITORY $DEPLOY_DIR/
- $PHP $DEPLOY_DIR/bin/vendors install
- elif [ $1 == "update" ]; then
- echo 'Fetching the latest code...';
- if [ ! -d $DEPLOY_BASE_DIR/current ]; then
- echo "$DEPLOY_BASE_DIR/current does not exist. Maybe you need to run install first?"
- exit;
- fi
- $CP -LR $DEPLOY_BASE_DIR/current $DEPLOY_DIR
- cd $DEPLOY_DIR;
- $GIT pull origin master
- $GIT reset --hard HEAD
- else
- echo -e $USAGE;
- exit;
- fi
- # Set app/cache permissions
- if [ -d $DEPLOY_DIR/app/cache ]; then
- $CHMOD -R 777 $DEPLOY_DIR/app/cache
- fi
- # Clear and warmup the symfony2 cache
- if [ -f $DEPLOY_DIR/app/console ]; then
- $RM -rf $DEPLOY_DIR/app/cache/$SF2_ENVIRONMENT
- $PHP $DEPLOY_DIR/app/console --env=$SF2_ENVIRONMENT cache:warmup
- fi
- # Set app/cache permissions again
- if [ -d $DEPLOY_DIR/app/cache ]; then
- $CHMOD -R 777 $DEPLOY_DIR/app/cache
- fi
- # Set app/logs permissions
- if [ -d $DEPLOY_DIR/app/logs ];
- then
- $CHMOD -R 777 $DEPLOY_DIR/app/logs
- fi
- # Install and symlink assets
- if [ -f $DEPLOY_DIR/app/console ]; then
- $PHP $DEPLOY_DIR/app/console --env=$SF2_ENVIRONMENT assets:install --symlink $DEPLOY_DIR/web
- fi
- # Update current symlink
- if [ -L $DEPLOY_BASE_DIR/current ] || [ -e $DEPLOY_BASE_DIR/current ]; then
- $RM $DEPLOY_BASE_DIR/current
- fi
- $LN -s $DEPLOY_DIR $DEPLOY_BASE_DIR/current
- # Restart php-fpm to clear the APC caches
- $SERVICE php-fpm restart
- echo 'Deployment complete.';
Add Comment
Please, Sign In to add comment