# Programs location TAR=`which tar` if [ ! "$TAR" ] ; then echo "ERROR: tar - command not found" exit 1 fi SVN=`which svn` if [ ! "$SVN" ] ; then echo "ERROR: svn - command not found" exit 1 fi MYSQL=`which mysql` if [ ! "$MYSQL" ] ; then echo "ERROR: mysql - command not found" exit 1 fi MYSQL_DUMP=`which mysqldump` if [ ! "$MYSQL_DUMP" ] ; then echo "ERROR: mysqldump - command not found" exit 1 fi # MySQL Access CONFIG_PATH="../www/_lib/config.php"; LOCAL_CONFIG_PATH="../www/_lib/local.config.php"; if [ -f "/usr/bin/php" ] ; then PHP="/usr/bin/php" else PHP="/usr/local/lib/php5.4/bin/php" fi php=" error_reporting(0); \$config = include('$CONFIG_PATH'); \$local = array(); if (is_file('$LOCAL_CONFIG_PATH')) { \$local = include('$LOCAL_CONFIG_PATH'); } /* автоматично визначатись назви БД має тільки якщо вона не задана в конфігах (local.config.php, config.php, default.config.php) */ if (empty(\$local['database']['params']['dbname']) && empty(\$config['database']['params']['dbname'])) { \$path = str_replace(array('_framework', '.'), array('', '_'), strtolower(realpath('../www'))); \$matches = array(); // 1 => project, 2 => subProject, 3 => trunk|branches|tags, 4 => branchPath if (preg_match('@public_html/([^/]+)(?:/([^/]+))?/(trunk|branches|tags)(?:/([^/]+))?/www@', \$path, \$matches)) { \$prefix = ('quick_site' === \$matches[1]) ? '' : 'prj_'; \$project = (empty(\$matches[2])) ? \$matches[1] : \$matches[2]; \$branchPath = (empty(\$matches[4])) ? '' : '_' . \$matches[4]; \$local['database']['params']['dbname'] = \$prefix . \$project . \$branchPath; } } echo \"DB_HOST='\" . ((!empty(\$local['database']['params']['host'])) ? \$local['database']['params']['host'] : \$config['database']['params']['host']) . \"'; \"; echo \"DB_PORT='\" . ((!empty(\$local['database']['params']['port'])) ? \$local['database']['params']['port'] : \$config['database']['params']['port']) . \"'; \"; echo \"DB_USER='\" . ((!empty(\$local['database']['params']['username'])) ? \$local['database']['params']['username'] : \$config['database']['params']['username']) . \"'; \"; echo \"DB_PASS='\" . ((!empty(\$local['database']['params']['password'])) ? \$local['database']['params']['password'] : \$config['database']['params']['password']) . \"'; \"; echo \"DB_NAME='\" . ((!empty(\$local['database']['params']['dbname'])) ? \$local['database']['params']['dbname'] : \$config['database']['params']['dbname']) . \"'; \"; " dbinfo=$($PHP -r "$php" 2>/dev/null) eval $dbinfo if [ ! "$DB_PORT" ] ; then DB_PORT="3306" fi if [ ! "$DB_USER" -o ! "$DB_NAME" ] ; then echo "ERROR: can not read database configuration" exit 1 fi # echo h:$DB_HOST P:$DB_PORT u:$DB_USER p:$DB_PASS d:$DB_NAME ; exit 1 #if [ "1" != "`echo ""select 1"" | $MYSQL -s -h $DB_HOST -P $DB_PORT -u $DB_USER -p$DB_PASS $DB_NAME`" ] ; then # echo "ERROR: can not connect to database" # exit 1 #fi . _defines.sh