# 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" 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_CSS_JS=`svn st -u --non-interactive --ignore-externals | grep '^\s*\*' | awk '{if ($3 == "") print $2; else print $3}' | grep -E '\.(css|js)$'` 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 echo echo "> cleaning cache..." cd ${REMOTE_SITE_DIR}/tmp/cache rm -f ./zend_cache* cd ${REMOTE_SITE_DIR}/tmp/tpl_c rm -f ./%* if test -n "$CHANGED_CSS_JS" ; then echo echo "> packing js, css files ..." cd ${REMOTE_WWW_DIR} || exit ${ERR_CODE_EXEC_ERROR} for FILE in $CHANGED_CSS_JS ; do if test -f "$FILE" ; then EXT=$(echo $FILE | sed 's/.*\.//') OUT=$(echo $FILE | sed "s/$EXT$/pack\.$EXT/") echo "> compressing $FILE -> $OUT" $JAVA -jar $COMPRESSOR $FILE -o $OUT 2>&1 fi done echo echo "> removing *.pack.merge.css, *.pack.merge.css files ..." find ${REMOTE_WWW_DIR}/js -type f -name '*.pack.merge.js' -exec rm -f {} \; 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 echo "> done" exit 0