#!/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}}' export PATH="$HOME/bin:$PATH" SVN=$(which svn) if test -z $SVN ; then echo "> ERROR: svn command not found" 1>&2 exit 1 fi 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="" echo "> checking out sources from svn ..." 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}) # 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 --no-auth-cache --username=$SVN_USER --password="$SVN_PASSWORD" 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 --no-auth-cache --username=$SVN_USER --password="$SVN_PASSWORD" 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 echo 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 cd ${REMOTE_WWW_DIR} || exit ${ERR_CODE_EXEC_ERROR} echo 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)" echo "----------------------------------------" echo exit 0