#!/bin/bash #echo 'temporary disabled' #exit ################################################################################ # THIS SCRIPT USED FOR CHECKOUT/UPDATE REMOTE SITE USING SVN # # VERSION 1.0.3 # # 1. place scripts in save level with site and www folders # 2. update variables in the remote-update-config.sh # 3. make sure there no site and www/index.php in remote server to make checkout # 4. run this script # 5. you should manually do following tasks: # - setup database dump # - setup cronjobs # - upload userfiles # - upload local.config.php # 6. use the same script to upload changed files to remote server # ################################################################################ if test $(uname -n) != "CatZilla"; then echo "> ERROR: script should be executed on CatZilla" 1>&2 exit 1 fi SCRIPT_DIR=$(dirname $0) if [[ ! -f "$SCRIPT_DIR/template-remote-update.sh" || ! -f "$SCRIPT_DIR/template-remote-checkout.sh" ]] ; then echo "> ERROR: can not found script templates" 1>&2 exit 1 fi # custom exit codes ERR_CODE_NO_CHECKOUT=75 ERR_CODE_EXEC_ERROR=77 SVN_HOST="svn.adaptainc.com:80" SVN_BIND_PORT="8888" SVN_WK_PATH=$(svn info | grep "^URL:" | awk '{print $2}' | cut -d/ -f4-) substVars() { sed -e "s|{{ERR_CODE_NO_CHECKOUT}}|$ERR_CODE_NO_CHECKOUT|g" \ | sed -e "s|{{ERR_CODE_EXEC_ERROR}}|$ERR_CODE_EXEC_ERROR|g" \ | sed -e "s|{{REMOTE_HOST}}|$REMOTE_HOST|g" \ | sed -e "s|{{REMOTE_SITE_DIR}}|$REMOTE_SITE_DIR|g" \ | sed -e "s|{{REMOTE_WWW_DIR}}|$REMOTE_WWW_DIR|g" \ | sed -e "s|{{SVN_REPO_PATH}}|$SVN_REPO_PATH|g" \ | sed -e "s|{{SVN_QSF_REPO_PATH}}|$SVN_QSF_REPO_PATH|g" \ | sed -e "s|{{SVN_HOST}}|$SVN_HOST|g" \ | sed -e "s|{{SVN_BIND_PORT}}|$SVN_BIND_PORT|g" } validate() { if [ "$SVN_REPO_PATH" != "$SVN_WK_PATH" ]; then echo -e "\e[0;38;05;196mERROR:\e[0m The working copy URL path \e[0;38;05;196m\"$SVN_WK_PATH\"\e[0m different from one that is set in the SVN_REPO_PATH=\e[0;38;05;120m\"$SVN_REPO_PATH\"\e[0m." echo -e "Please make sure that the configuration is correct!!!" exit 1; fi } upload() { read -p "> Update project sources from SVN (Y/N)? " -n 1 echo if [[ ! $REPLY =~ ^[Yy]$ ]] ; then exit 1 fi CMD_REMOTE_UPDATE=$(cat $SCRIPT_DIR/template-remote-update.sh | substVars) CMD_REMOTE_CHECKOUT=$(cat $SCRIPT_DIR/template-remote-checkout.sh | substVars) echo "> running remote command ..." if [ "" != "$SSH_PASSWORD" ] ; then sshpass -p "$SSH_PASSWORD" ssh -TR ${SVN_BIND_PORT}:${SVN_HOST} ${REMOTE_HOST} "$CMD_REMOTE_UPDATE" else ssh -TR ${SVN_BIND_PORT}:${SVN_HOST} ${REMOTE_HOST} "$CMD_REMOTE_UPDATE" fi CODE=$? if [[ $CODE -eq $ERR_CODE_EXEC_ERROR ]] ; then echo "> error executing command" 1>&2 exit 1 elif [[ $CODE -eq $ERR_CODE_NO_CHECKOUT ]] ; then read -p "> Checkout project sources from SVN (Y/N)? " -n 1 echo if [[ ! $REPLY =~ ^[Yy]$ ]] ; then exit 1 fi if [ "" != "$SSH_PASSWORD" ] ; then sshpass -p "$SSH_PASSWORD" ssh -TR ${SVN_BIND_PORT}:${SVN_HOST} ${REMOTE_HOST} "$CMD_REMOTE_CHECKOUT" else ssh -TR ${SVN_BIND_PORT}:${SVN_HOST} ${REMOTE_HOST} "$CMD_REMOTE_CHECKOUT" fi CODE=$? if [[ $CODE -eq $ERR_CODE_EXEC_ERROR ]] ; then echo "> error executing command" 1>&2 exit 1 fi fi echo "> done" } #---------------------------------------------------------------------------------------------------------------------- # MAIN #---------------------------------------------------------------------------------------------------------------------- for file in remote-update-config* do . $file echo "REMOTE_HOST: ${REMOTE_HOST}" echo "REMOTE_SITE_DIR: ${REMOTE_SITE_DIR}" echo "REMOTE_WWW_DIR: ${REMOTE_WWW_DIR}" echo "SVN_REPO_PATH: ${SVN_REPO_PATH}" echo "SVN_QSF_REPO_PATH: ${SVN_QSF_REPO_PATH}" echo validate for opt in $@ ; do case ${opt} in ( '--force-pack-all' ) shift read -p "> Do you want to repack all js/css files (Y/N)? " -n 1 echo if [[ ! $REPLY =~ ^[Yy]$ ]] ; then exit 1 fi REMOTE_CMD=$(cat $SCRIPT_DIR/template-remote-pack.sh | substVars) echo "> running remote command ..." if [ "" != "$SSH_PASSWORD" ] ; then sshpass -p "$SSH_PASSWORD" ssh -TR ${SVN_BIND_PORT}:${SVN_HOST} ${REMOTE_HOST} "$REMOTE_CMD" else ssh -TR ${SVN_BIND_PORT}:${SVN_HOST} ${REMOTE_HOST} "$REMOTE_CMD" fi CODE=$? if [[ $CODE -eq $ERR_CODE_EXEC_ERROR ]] ; then echo "> error executing command" 1>&2 exit 1 fi echo "> done" exit ;; esac done upload if [ -f "site/bin/hart" ] ; then if [ "" != "$SSH_PASSWORD" ] ; then sshpass -p "$SSH_PASSWORD" scp site/bin/hart "$REMOTE_HOST:$REMOTE_SITE_DIR/bin/hart" else scp site/bin/hart "$REMOTE_HOST:$REMOTE_SITE_DIR/bin/hart" fi fi done exit 0