#!/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_NO_CHECKOUT="{{ERR_CODE_NO_CHECKOUT}}" ERR_CODE_EXEC_ERROR="{{ERR_CODE_EXEC_ERROR}}" REMOTE_SITE_DIR="{{REMOTE_SITE_DIR}}" REMOTE_WWW_DIR="{{REMOTE_WWW_DIR}}" SVN_BIND_PORT="{{SVN_BIND_PORT}}" SVN_REPO_PATH="{{SVN_REPO_PATH}}" JAVA=$(which java) SVN=$(which svn) COMPRESSOR="${REMOTE_SITE_DIR}/bin/yuicompressor.jar" COMPRESSOR_OPT="-Xmx128m" SITE_PARENT_DIR=$(dirname ${REMOTE_SITE_DIR}) #if test $(uname -n) = "CatZilla"; then # echo "> ERROR: remote script should not be executed on CatZilla" 1>&2 # exit 1 #fi if [[ ! -d "${REMOTE_SITE_DIR}" && ! -f "${REMOTE_WWW_DIR}/index.php" ]] ; then exit ${ERR_CODE_NO_CHECKOUT} fi # check if where are site and www directories if [[ ! -d "${REMOTE_SITE_DIR}" ]] ; then echo "> ERROR: can not found site folder '${REMOTE_SITE_DIR}' (remove site and www/index.php to make checkout)" 1>&2 exit 1 elif [[ ! -f "${REMOTE_WWW_DIR}/index.php" ]] ; then echo "> ERROR: can not found www/index.php '${REMOTE_WWW_DIR}/index.php' (remove site and www/index.php to make checkout)" 1>&2 exit 1 fi echo "> updating sources from svn ..." if test -z "$JAVA" ; then echo "> WARNING: can not found java" 1>&2 else if test ! -f "$COMPRESSOR" ; then echo "> WARNING: can not found compressor file '${COMPRESSOR}'" 1>&2 else echo "> collenting chaged js and css files ..." cd ${REMOTE_WWW_DIR} || exit ${ERR_CODE_EXEC_ERROR} CHANGED_FILES=`svn st -u --non-interactive --ignore-externals | grep '^\s*\*' | awk '{if ($3 == "") print $2; else print $3}' | grep -E '\.(css|js)$'` CHANGED_JS=`echo "$CHANGED_FILES" | grep -E '\.js$'` CHANGED_CSS=`echo "$CHANGED_FILES" | grep -E '\.css$'` fi fi echo echo "> updating externals ..." cd ${REMOTE_WWW_DIR}/js/ckeditor || exit ${ERR_CODE_EXEC_ERROR} svn up --ignore-externals cd ${REMOTE_SITE_DIR}/lib/Smarty || exit ${ERR_CODE_EXEC_ERROR} svn up --ignore-externals cd ${REMOTE_SITE_DIR}/lib/Zend || exit ${ERR_CODE_EXEC_ERROR} svn up --ignore-externals echo echo "> updating site ..." cd ${REMOTE_SITE_DIR} || exit ${ERR_CODE_EXEC_ERROR} CHANGED_SITE_PHP=`svn st -u --non-interactive --ignore-externals | grep '^\s*\*' | awk '{if ($3 == "") print $2; else print $3}' | grep '\.php$'` svn up --ignore-externals --accept theirs-full echo echo "> updating www ..." cd ${REMOTE_WWW_DIR} || exit ${ERR_CODE_EXEC_ERROR} CHANGED_WWW_PHP=`svn st -u --non-interactive --ignore-externals | grep '^\s*\*' | awk '{if ($3 == "") print $2; else print $3}' | grep '\.php$'` svn up --ignore-externals --accept theirs-full if test -d "${SITE_PARENT_DIR}/.updates" ; then echo echo "> updating .updates ..." cd $SITE_PARENT_DIR/.updates || exit ${ERR_CODE_EXEC_ERROR} CHANGED_SQL=`svn st -u --non-interactive --ignore-externals | grep '^\s*\*' | awk '{if ($3 == "") print $2; else print $3}' | grep '\.sql$'` svn up --ignore-externals --accept theirs-full fi if test -d "${SITE_PARENT_DIR}/db" ; then echo echo "> updating db ..." cd $SITE_PARENT_DIR/db || exit ${ERR_CODE_EXEC_ERROR} CHANGED_SQL=`svn st -u --non-interactive --ignore-externals | grep '^\s*\*' | awk '{if ($3 == "") print $2; else print $3}' | grep '\.sql$'` svn up --ignore-externals --accept theirs-full fi echo echo "> cleaning cache..." cd ${REMOTE_SITE_DIR}/tmp/cache rm -f ./zend_cache* cd ${REMOTE_SITE_DIR}/tmp/tpl_c rm -f ./%* COMPRESS_JS_CODE=0 if test -n "$CHANGED_JS" ; then echo echo "> packing js files ..." echo "$CHANGED_JS" cd ${REMOTE_WWW_DIR} || exit ${ERR_CODE_EXEC_ERROR} $JAVA $COMPRESSOR_OPT -jar $COMPRESSOR -o '.js$:.pack.js' $CHANGED_JS 2>&1 COMPRESS_JS_CODE=$? echo echo "> removing *.pack.merge.css files ..." find ${REMOTE_WWW_DIR}/js -type f -name '*.pack.merge.js' -exec rm -f {} \; fi COMPRESS_CSS_CODE=0 if test -n "$CHANGED_CSS" ; then echo echo "> packing css files ..." echo "$CHANGED_CSS" cd ${REMOTE_WWW_DIR} || exit ${ERR_CODE_EXEC_ERROR} $JAVA $COMPRESSOR_OPT -jar $COMPRESSOR -o '.css$:.pack.css' $CHANGED_CSS 2>&1 COMPRESS_CSS_CODE=$? echo echo "> removing *.pack.merge.css files ..." find ${REMOTE_WWW_DIR}/css -type f -name '*.pack.merge.css' -exec rm -f {} \; fi echo echo "> creating rev file ..." cd ${REMOTE_WWW_DIR} || exit ${ERR_CODE_EXEC_ERROR} SOURCE_REV=$(svn info http://127.0.0.1:${SVN_BIND_PORT}/${SVN_REPO_PATH} --non-interactive 2>&1 | grep "Last Changed Rev:" | awk '{print $4}') echo $SOURCE_REV > rev # full permission fix code # find ${REMOTE_SITE_DIR} -type d -exec chmod 755 {} \; # find ${REMOTE_SITE_DIR} -type f -name "*.php" -exec chmod 644 {} \; # find ${REMOTE_WWW_DIR} -type f -name "*.php" -exec chmod 644 {} \; if test -n "$CHANGED_SITE_PHP" ; then echo echo "> fixing permissions in site ..." cd ${REMOTE_SITE_DIR} for FILE in "$CHANGED_SITE_PHP" ; do if test -f "$FILE" ; then chmod 644 "$FILE" fi done fi if test -n "$CHANGED_WWW_PHP" ; then echo echo "> fixing permissions in www ..." cd ${REMOTE_WWW_DIR} for FILE in "$CHANGED_WWW_PHP" ; do if test -f "$FILE" ; then chmod 644 "$FILE" fi done fi if test -n "$CHANGED_SQL" ; then echo echo "> NOTE: patches that should be applied manually:" echo "========================================" for PATCH in $CHANGED_SQL ; do echo $PATCH done echo "========================================" fi if test $COMPRESS_JS_CODE -ne 0 ; then echo "> WARNING: Error packing JS files: $CHANGED_JS" fi if test $COMPRESS_CSS_CODE -ne 0 ; then echo "> WARNING: Error packing CSS files: $CHANGED_CSS" fi echo "> done" exit 0