db-update-2016-06-23.sh 1.28 KB
#!/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, utiliser le script macos-db-update.sh
# Sinon, voici la procedure manuelle a suivre:
# 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


# Get login, pass, dbname, and hostname
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)


cp -p ./script_sql/db-update-2016-06-23.sql ./script_sql/db-update-2016-06-23-build.sql

# Execute sql update script
sed -e "s/database/$database/" -i ./script_sql/db-update-2016-06-23-build.sql
mysql --user=$username --password=$password -h $host < ./script_sql/db-update-2016-06-23-build.sql

# Delete 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