#!/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_BIND_PORT="{{SVN_BIND_PORT}}" export PATH="$HOME/bin:$PATH" PHP=`which php` if [ -z "$PHP" ]; then echo "> WARNING: can not find PHP" 1>&2 fi COMPOSER=`which composer` if [ -z "$COMPOSER" ]; then echo "> WARNING: can not find COMPOSER" 1>&2 exit 1 fi MINIFYCSS="$REMOTE_SITE_DIR/vendor/bin/minifycss" if [ ! -e "$MINIFYCSS" ]; then echo "> WARNING: can not find MINIFYCSS ($MINIFYCSS)" 1>&2 exit 1 fi MINIFYJS="$REMOTE_SITE_DIR/vendor/bin/minifyjs" if [ ! -e "$MINIFYJS" ]; then echo "> WARNING: can not find MINIFYJS ($MINIFYJS)" 1>&2 exit 1 fi ERRORS_LIST="" CURRENT_DIR=$(pwd) cd $REMOTE_SITE_DIR echo "> running 'composer install' ..." composer install cd $CURRENT_DIR 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}) echo "> pack js and css files ..." 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 echo "> packing js files ..." for f in $(echo -e $FILE_LIST); do ext=$(echo $f | sed 's/.*\.//') o=$(echo $f | sed "s/\.$ext$/\.pack\.$ext/") echo -n "$f -> $o - " $PHP $MINIFYJS $f > $o if [ "$?" != "0" ] ; then echo "FAILED" ERRORS_LIST=$(echo "$ERRORS_LIST\n$f") else echo "DONE" fi done; fi FILE_LIST=$(find ./css -name '*.css' -type f | grep -Fv '.pack.' | grep -Fv '.merge.') if test -n "$FILE_LIST" ; then echo echo "> packing css files ..." for f in $(echo -e $FILE_LIST); do ext=$(echo $f | sed 's/.*\.//') o=$(echo $f | sed "s/\.$ext$/\.pack\.$ext/") echo -n "$f -> $o - " $PHP $MINIFYCSS $f > $o if [ "$?" != "0" ] ; then echo "FAILED" ERRORS_LIST=$(echo "$ERRORS_LIST\n$f") else echo "DONE" fi done; fi echo if [ "$ERRORS_LIST" != "" ] ; then echo -e "Next files are not packed:\n$ERRORS_LIST" else echo "All files packed successfuly" fi echo echo "> removing *.pack.merge.css files ..." find ${REMOTE_WWW_DIR}/css -type f -name '*.pack.merge.css' -exec rm -f {} \; echo echo "> removing *.pack.merge.js files ..." find ${REMOTE_WWW_DIR}/js -type f -name '*.pack.merge.js' -exec rm -f {} \; cd ${REMOTE_WWW_DIR} || exit ${ERR_CODE_EXEC_ERROR} echo echo "done" echo exit 0