Blame view

database/update/old/db-update-2016-06-20.sh 2.67 KB
e9a0cc56   Alexandre   Version: 2.4.6.0
1
2
#!/bin/bash

ac74090b   Etienne Pallier   commentaires et t...
3
4
5
6
7
8
9
10
11
12
13
14
# 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
e9a0cc56   Alexandre   Version: 2.4.6.0
15
16
17
cp -p ../../config/app.php ../../config/app.php.ORIG
cp ../../config/app.default.php ../../config/app.php

ac74090b   Etienne Pallier   commentaires et t...
18
# Get login, pass, and db name for PROD and TEST database from current config
e9a0cc56   Alexandre   Version: 2.4.6.0
19
20
21
22
23
24
25
26
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)

ac74090b   Etienne Pallier   commentaires et t...
27
# Update config file (app.php) for PROD and TEST database
e9a0cc56   Alexandre   Version: 2.4.6.0
28
29
30
31
32
33
34
35
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

ac74090b   Etienne Pallier   commentaires et t...
36
# Stop debug mode
e9a0cc56   Alexandre   Version: 2.4.6.0
37
38
sed -e "s/'debug' => filter_var(env('DEBUG', true/'debug' => filter_var(env('DEBUG', false/" -i ../../config/app.php

ac74090b   Etienne Pallier   commentaires et t...
39
# Get login, pass, db name, and host from new config
e9a0cc56   Alexandre   Version: 2.4.6.0
40
41
42
43
44
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)

ac74090b   Etienne Pallier   commentaires et t...
45
# Execute db update sql request
e9a0cc56   Alexandre   Version: 2.4.6.0
46
cp -p ./script_sql/db-update-2016-06-20.sql ./script_sql/db-update-2016-06-20-build.sql
e9a0cc56   Alexandre   Version: 2.4.6.0
47
48
49
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

ac74090b   Etienne Pallier   commentaires et t...
50
# Remove cakephp cache
e9a0cc56   Alexandre   Version: 2.4.6.0
51
52
53
54
55
56
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