db-update-2016-06-20.sh
2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/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