#!/bin/bash # Pour Mac OS recent (10.10, Yosemite), la syntaxe du SED est differente # Il faut donc faire une copie de ce fichier et transformer les instructions sed a l'interieur # Pour cela, il suffit d'executer ces 2 lignes : # cp ce_script.sh ce_script_macosx.sh # sed -e "s/ -i / -i '' /" -i '' ce_script_macosx.sh if [ ! -f ../../config/app.php ] ; then echo "Vous devez executer ce script depuis le dossier database/update/" exit 1 fi # Reset config file (app.php) to default cp -p ../../config/app.php ../../config/app.php.ORIG cp ../../config/app.default.php ../../config/app.php # Get login, pass, and db name for PROD and TEST database from current config username=$(grep "/\*d\*/'username'" ../../config/app.php.ORIG | cut -d"'" -f4) password=$(grep "/\*d\*/'password'" ../../config/app.php.ORIG | cut -d"'" -f4) database=$(grep "/\*d\*/'database'" ../../config/app.php.ORIG | cut -d"'" -f4) usernameTEST=$(grep "/\*t\*/'username'" ../../config/app.php.ORIG | cut -d"'" -f4) passwordTEST=$(grep "/\*t\*/'password'" ../../config/app.php.ORIG | cut -d"'" -f4) databaseTEST=$(grep "/\*t\*/'database'" ../../config/app.php.ORIG | cut -d"'" -f4) # Update config file (app.php) for PROD and TEST database sed -e "s/'database' => 'database'/'database' => '$database'/" -i ../../config/app.php sed -e "s/'username' => 'username'/'username' => '$username'/" -i ../../config/app.php sed -e "s/'password' => 'password'/'password' => '$password'/" -i ../../config/app.php sed -e "s/'database' => 'test_database'/'database' => '$databaseTEST'/" -i ../../config/app.php sed -e "s/'username' => 'test_username'/'username' => '$usernameTEST'/" -i ../../config/app.php sed -e "s/'password' => 'test_password'/'password' => '$passwordTEST'/" -i ../../config/app.php # Stop debug mode sed -e "s/'debug' => filter_var(env('DEBUG', true/'debug' => filter_var(env('DEBUG', false/" -i ../../config/app.php # Get login, pass, db name, and host from new config username=$(grep "/\*d\*/'username'" ../../config/app.php | cut -d"'" -f4) password=$(grep "/\*d\*/'password'" ../../config/app.php | cut -d"'" -f4) database=$(grep "/\*d\*/'database'" ../../config/app.php | cut -d"'" -f4) host=$(grep "/\*d\*/'host'" ../../config/app.php | cut -d"'" -f4) # Execute db update sql request cp -p ./script_sql/db-update-2016-06-20.sql ./script_sql/db-update-2016-06-20-build.sql sed -e "s/database/$database/" -i ./script_sql/db-update-2016-06-20-build.sql mysql --user=$username --password=$password -h $host < ./script_sql/db-update-2016-06-20-build.sql # Remove cakephp cache sudo rm ../../tmp/cache/models/* sudo rm ../../tmp/cache/persistent/* sudo chmod -R 777 ../../tmp sudo chmod -R 777 ../../vendor sudo chmod -R 777 ../../webroot