#!/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_REPO_PATH="{{SVN_REPO_PATH}}" SVN_QSF_REPO_PATH="{{SVN_QSF_REPO_PATH}}" SVN_BIND_PORT="{{SVN_BIND_PORT}}" 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 --ignore-externals http://127.0.0.1:${SVN_BIND_PORT}/${SVN_REPO_PATH}/site $SITE_DIR_NAME echo "> checking out www ..." cd $WWW_PARENT_DIR || exit ${ERR_CODE_EXEC_ERROR} $SVN co --force --ignore-externals http://127.0.0.1:${SVN_BIND_PORT}/${SVN_REPO_PATH}/www $WWW_DIR_NAME $SVN ls --depth empty http://127.0.0.1:${SVN_BIND_PORT}/${SVN_REPO_PATH}/.updates if test $? -eq 0 ; then echo "> checking out .updates ..." cd $SITE_PARENT_DIR || exit ${ERR_CODE_EXEC_ERROR} $SVN co --force --ignore-externals http://127.0.0.1:${SVN_BIND_PORT}/${SVN_REPO_PATH}/.updates fi $SVN ls --depth empty http://127.0.0.1:${SVN_BIND_PORT}/${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 --ignore-externals http://127.0.0.1:${SVN_BIND_PORT}/${SVN_REPO_PATH}/db fi if [ -n "$SVN_QSF_REPO_PATH" ]; then echo "> checking out www/js/ckeditor ..." cd ${REMOTE_WWW_DIR}/js || exit ${ERR_CODE_EXEC_ERROR} svn co --force --ignore-externals http://127.0.0.1:${SVN_BIND_PORT}/${SVN_QSF_REPO_PATH}/www/js/ckeditor echo "> checking out externals from site/lib/Smarty ..." cd ${REMOTE_SITE_DIR}/lib/Smarty || exit ${ERR_CODE_EXEC_ERROR} svn co --force --ignore-externals http://127.0.0.1:${SVN_BIND_PORT}/${SVN_QSF_REPO_PATH}/site/lib/Smarty/Smarty # checkout site/lib externals echo "> checking out externals from site/lib ..." cd ${REMOTE_SITE_DIR}/lib || exit ${ERR_CODE_EXEC_ERROR} svn propget svn:externals http://127.0.0.1:${SVN_BIND_PORT}/${SVN_REPO_PATH}/site/lib \ | while read name ; do if test -n "$name" ; then name=$(echo $name | awk '{ print $1 }' | xargs basename) svn co --force --ignore-externals http://127.0.0.1:${SVN_BIND_PORT}/${SVN_QSF_REPO_PATH}/site/lib/${name} fi done 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_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