#!/bin/true # REMOTE SCRIPT (can not interact with user) # turn on debug mode (use 'set +x' to disable it) # set -x # {{VAR_NAME}} - template variables ERR_CODE_EXEC_ERROR="{{ERR_CODE_EXEC_ERROR}}" REMOTE_SITE_DIR="{{REMOTE_SITE_DIR}}" REMOTE_WWW_DIR="{{REMOTE_WWW_DIR}}" SVN_BASE_URL="{{SVN_BASE_URL}}" SVN_REPO_PATH="{{SVN_REPO_PATH}}" SVN_USER="{{SVN_USER}}" SVN_PASSWORD="{{SVN_PASSWORD}}" SVN=$(which svn) JAVA=$(which java) #if test $(uname -n) = "CatZilla"; then # echo "> ERROR: remote script should not be executed on CatZilla" 1>&2 # exit 1 #fi echo "> checking out sources from svn ..." if test -z $SVN ; then echo "> ERROR: svn command not found" 1>&2 exit 1 fi if test -z "$JAVA" ; then echo "> WARNING: can not found java" 1>&2 fi CURRENT_DIR=$(pwd) SITE_PARENT_DIR=$(dirname ${REMOTE_SITE_DIR}) SITE_DIR_NAME=$(basename ${REMOTE_SITE_DIR}) WWW_PARENT_DIR=$(dirname ${REMOTE_WWW_DIR}) WWW_DIR_NAME=$(basename ${REMOTE_WWW_DIR}) # checkout site and www echo "> checking out site ..." cd $SITE_PARENT_DIR || exit ${ERR_CODE_EXEC_ERROR} $SVN co --force $SVN_BASE_URL/${SVN_REPO_PATH}/site $SITE_DIR_NAME --no-auth-cache --username=$SVN_USER --password=$SVN_PASSWORD echo "> checking out www ..." cd $WWW_PARENT_DIR || exit ${ERR_CODE_EXEC_ERROR} $SVN co --force $SVN_BASE_URL/${SVN_REPO_PATH}/www $WWW_DIR_NAME --no-auth-cache --username=$SVN_USER --password=$SVN_PASSWORD $SVN ls --depth empty $SVN_BASE_URL/${SVN_REPO_PATH}/.updates --no-auth-cache --username=$SVN_USER --password=$SVN_PASSWORD if test $? -eq 0 ; then echo "> checking out .updates ..." cd $SITE_PARENT_DIR || exit ${ERR_CODE_EXEC_ERROR} $SVN co --force $SVN_BASE_URL/${SVN_REPO_PATH}/.updates --no-auth-cache --username=$SVN_USER --password=$SVN_PASSWORD fi $SVN ls --depth empty $SVN_BASE_URL/${SVN_REPO_PATH}/db if test $? -eq 0 ; then echo "> checking out db ..." cd $SITE_PARENT_DIR || exit ${ERR_CODE_EXEC_ERROR} $SVN co --force $SVN_BASE_URL/${SVN_REPO_PATH}/db fi # create cache folders echo "> creating tmp folders (cache, session) ..." cd ${REMOTE_SITE_DIR}/tmp || exit ${ERR_CODE_EXEC_ERROR} mkdir cache mkdir session # fix permissions echo "> fixing folder and file permissions ..." find ${REMOTE_SITE_DIR} -type d -exec chmod 755 {} \; find ${REMOTE_SITE_DIR} -type f -exec chmod 644 {} \; find ${REMOTE_WWW_DIR} -type d -exec chmod 755 {} \; find ${REMOTE_WWW_DIR} -type f -exec chmod 644 {} \; # pack js and css files if test -n "$JAVA" ; then COMPRESSOR="${REMOTE_SITE_DIR}/bin/yuicompressor.jar" COMPRESSOR_OPT="-Xmx128m" echo "> pack js and css files ..." if test ! -f "$COMPRESSOR" ; then echo "> WARNING: can not found compressor file '${COMPRESSOR}'" 1>&2 else cd ${REMOTE_WWW_DIR} || exit ${ERR_CODE_EXEC_ERROR} FILE_LIST=$(find ./js -name '*.js' -type f | grep -Fv '.pack.' | grep -Fv '.merge.' | grep -Fv './js/ckeditor/') FILE_LIST="$FILE_LIST ./js/ckeditor/ckeditor.js" if test -n "$FILE_LIST" ; then echo "> packing js files ..." $JAVA $COMPRESSOR_OPT -jar $COMPRESSOR -o '.js$:.pack.js' $FILE_LIST 2>&1 fi FILE_LIST=$(find ./css -name '*.css' -type f | grep -Fv '.pack.' | grep -Fv '.merge.') if test -n "$FILE_LIST" ; then echo "> packing css files ..." $JAVA $COMPRESSOR_OPT -jar $COMPRESSOR -o '.css$:.pack.css' $FILE_LIST 2>&1 fi fi fi cd ${REMOTE_SITE_DIR} $HOME/bin/php $HOME/bin/composer install cd ${REMOTE_WWW_DIR} || exit ${ERR_CODE_EXEC_ERROR} echo '> creating symlink local.config.php --> server.local.config.php'; cd _lib ln -sfn server.local.config.php local.config.php cd ${REMOTE_WWW_DIR} || exit ${ERR_CODE_EXEC_ERROR} echo echo "----------------------------------------" echo "> NOTE: you should manually do following tasks:" echo "- setup database dump" echo "- setup cronjobs" echo "- upload userfiles (if option '--upload-userfiles' was not used)" if test -z "$JAVA" ; then echo "- pack css, js files manually" fi echo "----------------------------------------" echo exit 0