Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Shell script to deploy site on server
- # Copy files from git repository and update site
- # It also applies database migrations based on zend framework tool
- # Last updated: Feb - 2012
- # @author miholeus
- # --------------------------------------------------------------------
- # -------------------------------------------------------
- # General settings
- # -------------------------------------------------------
- # General folder to create project's archives
- # DO NOT USE SLASH AT THE END!!
- ARCHIVE_DIR=/tmp/project
- # git arhive with project's sources
- # DO NOT USE SLASH AT THE END!!
- PROJECT_GIT_DIR=/var/git/project.git
- # project's current directory
- # DO NOT USE SLASH AT THE END!!
- PROJECT_DIR=/home/project/htdocs
- # -------------------------------------------------------
- # These settings may be left as is
- # -------------------------------------------------------
- # folder that will be created after unpacking an archive
- DESTINATION_FOLDER=$ARCHIVE_DIR/release_`date +"%Y_%m_%d_%H_%M_%S"`
- ZF_BIN=/usr/bin/zf
- NODE_BIN=/usr/local/bin/node
- # database migration command
- # default branch name to deploy
- BRANCH=master
- APP_ENV=production
- while getopts ":s:d:g:e:" optname
- do
- case "$optname" in
- "s")
- BRANCH="$OPTARG"
- ;;
- "d")
- PROJECT_DIR=$OPTARG
- ;;
- "g")
- PROJECT_GIT_DIR=$OPTARG
- ;;
- "e")
- APP_ENV=$OPTARG
- ;;
- esac
- done
- MIGRATE_COMMAND="$ZF_BIN update database-schema $APP_ENV"
- BUILD_COMMAND="$NODE_BIN ./bin/tools/build.js deploy"
- # rsync command, you may change it on your own
- SYNC_COMMAND="rsync -uthrO --delete $DESTINATION_FOLDER/ $PROJECT_DIR --exclude public/upload --exclude .gitignore --exclude data --exclude logs --exclude var --exclude public/phpmy"
- #SYNC_COMMAND="cp -f -r -p $DESTINATION_FOLDER/* $PROJECT_DIR"
- if [ ! -d "$PROJECT_DIR" ]; then
- echo "::=> Project's directory doesn't exist :: $PROJECT_DIR"
- exit 1
- fi
- mkdir -p $DESTINATION_FOLDER
- if [ ! -d "$DESTINATION_FOLDER" ]; then
- echo "::=> Directory can't be created :: $DESTINATION_FOLDER"
- exit 1
- fi
- git archive --remote $PROJECT_GIT_DIR $BRANCH | tar -x -C $DESTINATION_FOLDER
- echo "Updating site..."
- $SYNC_COMMAND
- cd $PROJECT_DIR
- echo "Applying migrations..."
- $MIGRATE_COMMAND
- cd $PROJECT_DIR
- echo "Building js & css..."
- $BUILD_COMMAND
- echo "Done!"
Advertisement
Add Comment
Please, Sign In to add comment