#!/bin/bash USER_NAME=$(whoami) PUB_NAME="pub" BASE_PATH="$( cd "$( dirname "$BASH_SOURCE[0]" )" && pwd)" PUB_BASE_PATH=$( cd "$BASE_PATH" && pwd | sed "s/\/home\/$USER_NAME\//\/home\/$PUB_NAME\//") MEDIA_DIRECTORY="media" PROJECT_PATH=`expr match "$BASE_PATH" '^\(\/[^\/]\+\/[^\/]\+\/[^\/]\+\/[^\/]\+\)'` #local.xml install #Creating symlink local.xml to local.xml.dev #if not existing local.xml.dev renaming local.xml to local.xml.dev function link_local_xml () { if [ ! -f "$BASE_PATH/app/etc/local.xml.dev" ] ; then echo -n 'local.xml.dev is not existing renaming local.xml...' mv $BASE_PATH/app/etc/local.xml $BASE_PATH/app/etc/local.xml.dev echo ' done!' fi if [ -h "$BASE_PATH/app/etc/local.xml" ] ; then echo -n '@local.xml is alredy existing. deleting it...' unlink $BASE_PATH/app/etc/local.xml echo ' done!' fi echo -n 'linking local.xml.dev...' ln -s $BASE_PATH/app/etc/local.xml.dev $BASE_PATH/app/etc/local.xml echo ' done!' } #local.xml end # media start function link_media_folder () { echo -n 'creating link to media folder' if [ -L "$BASE_PATH/$MEDIA_DIRECTORY" ] ; then echo -n 'media folder is existing unlinking, it...' unlink $BASE_PATH/$MEDIA_DIRECTORY echo ' done!' fi if [ ! -d "$PUB_BASE_PATH/$MEDIA_DIRECTORY" ] ; then echo -n 'creating pub/media...' mkdir -p $PUB_BASE_PATH/$MEDIA_DIRECTORY chmod -R 775 $PUB_BASE_PATH echo 'Options -Indexes' > $PUB_BASE_PATH/$MEDIA_DIRECTORY/.htaccess echo ' done!' fi if [ -d "$BASE_PATH/$MEDIA_DIRECTORY" ] ; then echo -n 'dir exists' if [ "$(ls -A $BASE_PATH/$MEDIA_DIRECTORY)" ] ; then echo -n 'moving contend to pub/media...' mv $BASE_PATH/$MEDIA_DIRECTORY/* $PUB_BASE_PATH/$MEDIA_DIRECTORY chmod -R 775 $PUB_BASE_PATH/$MEDIA_DIRECTORY echo ' done!' fi echo -n "removing $USER_NAME/media..." rm -Rf $BASE_PATH/$MEDIA_DIRECTORY echo ' done!' fi echo 'making link to a pub/media...' ln -sT $PUB_BASE_PATH/$MEDIA_DIRECTORY $BASE_PATH/$MEDIA_DIRECTORY echo ' done!' } #echo Public link on $MEDIA_DIRECTORY created "$BASE_PATH/$MEDIA_DIRECTORY" # media end #------------------------------- set ignores ----------------------------- function set_svn_ignore () { if [ ! -d "$BASE_PATH/var" ] ; then echo -n 'var folder is not exist. creating...' mkdir -p var/cache var/report var/locks var/log var/session var/logging fi echo -n 'setting up svn ignore on var...' svn propset svn:ignore "report cache tmp import export backups" var svn propset svn:ignore "*" var/locks svn propset svn:ignore "*" var/log svn propset svn:ignore "*" var/session svn propset svn:ignore "*" var/logging if [ ! -d "$BASE_PATH/media" ] ; then echo -n 'media folder is not exist. creating...' mkdir -p media fi echo -n 'setting up svn ignore on media...' svn propset svn:ignore "*" media if [ ! -d "$BASE_PATH/webservice" ] ; then echo -n 'webservice folder is not exist. creating...' mkdir -p webservice fi if [ ! -d "$BASE_PATH/webservice/uploads" ] ; then echo -n 'webservice/uploads folder is not exist. creating...' mkdir -p webservice/uploads fi echo -n 'setting up svn ignore on webservice/uploads...' svn propset svn:ignore "*" webservice/uploads if [ ! -d "$BASE_PATH/app/etc" ] ; then echo -n 'app/etc folder is not exist. creating...' mkdir -p app/etc fi echo -n 'setting up svn ignore on webservice/uploads...' svn propset svn:ignore "local.xml use_cache.ser" app/etc echo ' done!' } function svn_auto_add() { cd $BASE_PATH find . -type f \( -name "*.phtml*" -o -name "*.js*" -o -name "*.php*" -o -name "*.css*" \) | xargs dos2unix svn_add_all } ######################################################################################### # Скрипт Створює симулінк для папки media, та додає в SVN ignone папки з кешем # # Скрипт потрібно запускати на проекті який вже доданий до SVN репозиторію ######################################################################################### case $1 in '--help') echo 'Usage: ./setup-magento.sh [options ...]' echo echo ' --help This Page' echo ' --test test dir paths' echo echo 'To Use this script you must place it to magento folder, whitch you have check out from SVN' echo 'ex. ~/public_html/magento_project/trunk' echo echo 'This script will make simulink to media folder of this project, and add to SVN ignore files' echo 'whitch not allow to be comited to SVN repository.' exit;; '--test') echo "BASE_PATH $BASE_PATH" echo "PUB_BASE_PATH $PUB_BASE_PATH" echo "PROJECT_PATH $PROJECT_PATH" exit;; esac set_svn_ignore svn_auto_add link_local_xml link_media_folder echo -n "installing is finnished"