#!/bin/bash . _config.sh case $1 in '--help') echo 'Version: setup.sh QSF 2.1 2010-05-26' echo 'Usage: ./setup.sh [options ...]' echo echo ' --cleanBom Clean BOM marker in .php, .ini, .html and .js files' echo ' --pack Pack .css and .js files with YUI Compressor' echo ' --exportPack Export packed .css and .js files to tar.bz2 archive' echo ' --removePack Remove *.pack.js, *.pack.css files' echo ' --removeThumbnails Remove Thumbnails' echo ' --addClassesWrappers Add wrappers for Qs classes' echo ' --commitFiles Archive and commit "www/userfiles" folder' echo ' --commitDatabase Dump and commit MySQL database tables' echo ' --restoreDatabase Restore database from backup' echo ' --help This page' echo exit;; '--pack' ) shift ./pack.sh $@ exit;; '--cleanBom' ) shift ./cleanBom.sh $@ exit;; '--exportPack' ) shift ./exportPack.sh $@ exit;; '--removePack' ) shift ./removePack.sh $@ exit;; '--removeThumbnails' ) shift ./removeThumbnails.sh $@ exit;; '--addClassesWrappers' ) shift ./addClassesWrappers.sh $@ exit;; '--commitFiles' ) shift ./files_ci.sh $@ exit;; '--restoreDatabase' ) shift ./mysql_restore_db.sh $@ exit;; '--commitDatabase' ) shift ./mysql_ci.sh $@ exit;; esac # report if [ ! -d "$PUB_BASE_PATH/www/report" ] ; then HTACCESS_CONTENT=$(cat < $PUB_BASE_PATH/www/report/.htaccess echo "$HTACCESS_DEV_CONTENT" > $PUB_BASE_PATH/www/report/.htaccess_dev fi if [ -L "$BASE_PATH/www/report" ] ; then unlink $BASE_PATH/www/report fi ln -s $PUB_BASE_PATH/www/report $BASE_PATH/www/report # report-access if [ ! -d "$PUB_BASE_PATH/www/report-access" ] ; then HTACCESS_CONTENT=$(cat < $PUB_BASE_PATH/www/report-access/.htaccess echo "$HTACCESS_DEV_CONTENT" > $PUB_BASE_PATH/www/report-access/.htaccess_dev fi if [ -L "$BASE_PATH/www/report-access" ] ; then unlink $BASE_PATH/www/report-access fi ln -s $PUB_BASE_PATH/www/report-access $BASE_PATH/www/report-access # document begin if [ ! -d "$PUB_BASE_PATH/www/application-document" ] ; then HTACCESS_CONTENT=$(cat < $PUB_BASE_PATH/www/application-document/.htaccess echo "$HTACCESS_DEV_CONTENT" > $PUB_BASE_PATH/www/application-document/.htaccess_dev fi if [ -L "$BASE_PATH/www/application-document" ] ; then unlink $BASE_PATH/www/application-document fi ln -s $PUB_BASE_PATH/www/application-document $BASE_PATH/www/application-document # document end # document access begin if [ ! -d "$PUB_BASE_PATH/www/application-document-access" ] ; then HTACCESS_CONTENT=$(cat < $PUB_BASE_PATH/www/application-document-access/.htaccess echo "$HTACCESS_DEV_CONTENT" > $PUB_BASE_PATH/www/application-document-access/.htaccess_dev fi if [ -L "$BASE_PATH/www/application-document-access" ] ; then unlink $BASE_PATH/www/application-document-access fi ln -s $PUB_BASE_PATH/www/application-document-access $BASE_PATH/www/application-document-access # document access end # userfiles if [ -L "$BASE_PATH/www/$FILES_DIRECTORY" ] ; then unlink $BASE_PATH/www/$FILES_DIRECTORY fi archiveName="`echo $FILES_DIRECTORY | sed 's/\W+/_/'`.tar.bz2" if [ ! -d "$PUB_BASE_PATH/www/$FILES_DIRECTORY" ] ; then mkdir -p $PUB_BASE_PATH/www/$FILES_DIRECTORY mkdir -p $PUB_BASE_PATH/www/$FILES_DIRECTORY/ckfiles mkdir -p $PUB_BASE_PATH/www/$FILES_DIRECTORY/ckfiles/_thumbs mkdir -p $PUB_BASE_PATH/www/$FILES_DIRECTORY/files chmod -R 777 $PUB_BASE_PATH/www/$FILES_DIRECTORY 2>/dev/null CURRENT_DIR=`pwd` cd $PUB_BASE_PATH/www/$FILES_DIRECTORY/ ln -s files images cd $CURRENT_DIR echo 'Options -Indexes' > $PUB_BASE_PATH/www/$FILES_DIRECTORY/.htaccess $SVN export $REPOSITORY_URL/$PROJECT_NAME/$FILES_BACKUP_DIR/$BRANCHE_PATH/$archiveName $PUB_BASE_PATH/www/$FILES_DIRECTORY/$archiveName 2>/dev/null if [ -f "$PUB_BASE_PATH/www/$FILES_DIRECTORY/$archiveName" ] ; then cd $PUB_BASE_PATH/www/$FILES_DIRECTORY/ $TAR -xjf $archiveName rm -f $archiveName cd $CURRENT_DIR else echo 'WARNING: Can not export project files' fi fi ln -s $PUB_BASE_PATH/www/$FILES_DIRECTORY $BASE_PATH/www/$FILES_DIRECTORY # end userfiles if [ -L "$BASE_PATH/site/tmp/cache" ] ; then unlink $BASE_PATH/site/tmp/cache fi if [ -d "$BASE_PATH/site/tmp/cache" ] ; then rm -Rf $BASE_PATH/site/tmp/cache fi if [ ! -d "$PUB_BASE_PATH/site/tmp/cache" ] ; then mkdir -p $PUB_BASE_PATH/site/tmp/cache chmod 777 $PUB_BASE_PATH/site/tmp/cache 2>/dev/null fi ln -s $PUB_BASE_PATH/site/tmp/cache $BASE_PATH/site/tmp/cache chmod -R 777 $PUB_BASE_PATH/site/tmp 2>/dev/null rm -Rf $PUB_BASE_PATH/site/tmp/cache/* rm -Rf $BASE_PATH/site/tmp/tpl_c/*.php 2>/dev/null chmod -R 777 $BASE_PATH/www/images/captcha 2>/dev/null find $BASE_PATH/www/js -name '*.merge.js' -type f -exec rm '{}' \; find $BASE_PATH/www/css -name '*.merge.css' -type f -exec rm '{}' \; # database dataBase=$(echo 'SHOW DATABASES' | $MYSQL -s -h $DB_HOST -u $DB_USER -p$DB_PASS -P $DB_PORT | grep -E "^${DB_NAME}$"); if [ ! "$dataBase" ] ; then echo "CREATE DATABASE \`$DB_NAME\` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci" | $MYSQL -B -h $DB_HOST -u $DB_USER -p$DB_PASS -P $DB_PORT if [ ! -d "$PROJECT_PATH/$DB_BACKUP_DIR" ] ; then $SVN up $PROJECT_PATH/$DB_BACKUP_DIR fi if [ -d "$DB_BACKUP_PATH" ] ; then for dump in $(find $DB_BACKUP_PATH -name '*.sql' -type f) ; do $MYSQL -h $DB_HOST -u $DB_USER -p$DB_PASS -P $DB_PORT -D $DB_NAME < $dump done else echo 'WARNING: Can not export DB dump' fi fi # end database