#!/bin/bash . _config.sh case $1 in '--help') echo 'Version: setup.sh QSF 4 2012-10-19' 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 ' --repack Repack all .css and .js files and remove merged files' 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 ' --commitFiles Archive and commit "www/userfiles" folder' echo ' --commitDatabase Dump and commit MySQL database tables' echo ' --update-google-fonts Update google fonts' echo ' --help This page' echo exit;; '--pack' ) shift ./pack.sh $@ exit;; '--repack' ) shift ./repack.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;; '--update-google-fonts' ) shift ./update-google-fonts $@ exit;; '--commitDatabase' ) shift ./mysql_ci.sh $@ exit;; esac # thumbnails start if [ -d "$BASE_PATH/www/$THUMBNAILS_DIRECTORY" -a ! -L "$BASE_PATH/www/$THUMBNAILS_DIRECTORY" ] ; then cecho "WARNING: \"www/$THUMBNAILS_DIRECTORY\" is directory instead of symlink. Delete \"www/$THUMBNAILS_DIRECTORY\" directory and run \"setup.sh\" again.\n" $CL_RED else if [ -L "$BASE_PATH/www/$THUMBNAILS_DIRECTORY" ] ; then unlink $BASE_PATH/www/$THUMBNAILS_DIRECTORY fi if [ ! -d "$PUB_BASE_PATH/www/$THUMBNAILS_DIRECTORY" ] ; then mkdir -p $PUB_BASE_PATH/www/$THUMBNAILS_DIRECTORY echo 'Options -Indexes' > $PUB_BASE_PATH/www/$THUMBNAILS_DIRECTORY/.htaccess fi ln -sT $PUB_BASE_PATH/www/$THUMBNAILS_DIRECTORY $BASE_PATH/www/$THUMBNAILS_DIRECTORY fi # thumbnails end # userfiles start if [ -d "$BASE_PATH/www/$FILES_DIRECTORY" -a ! -L "$BASE_PATH/www/$FILES_DIRECTORY" ] ; then cecho "WARNING: \"www/$FILES_DIRECTORY\" is directory instead of symlink. Delete \"www/$FILES_DIRECTORY\" directory and run \"setup.sh\" again.\n" $CL_RED else 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/files CURRENT_DIR=`pwd` cd $PUB_BASE_PATH/www/$FILES_DIRECTORY/ ln -sT 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 -sT $PUB_BASE_PATH/www/$FILES_DIRECTORY $BASE_PATH/www/$FILES_DIRECTORY fi # userfiles end initTempSymlink "cache"; initTempSymlink "session"; # permissions start find $PUB_PUBLIC_HTML/$PROJECT_NAME -name '*' -type d -print0 | while read -d $'\0' dir ; do setPermissions "$dir" done setPermissions "$BASE_PATH/www/images/captcha" setPermissions "$BASE_PATH/site/tmp/tpl_c" # permissions end rm -Rf $PUB_BASE_PATH/site/tmp/cache/* rm -Rf $BASE_PATH/site/tmp/tpl_c/*.php 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 '{}' \; if [ ! -f "$BASE_PATH/site/bin/hart" ] ; then hartUrl=$(svn pg svn:externals http://svn.fr-wd.com/hart/tags | grep 'latest$' | awk '{print $1}'|sed 's~\^~http://svn.fr-wd.com/hart~') svn export $hartUrl "$BASE_PATH/site/bin/hart" > /dev/null 2>&1 fi # 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