1
|
#!/usr/bin/env bash
|
2
|
|
3
|
help=<<EOF
|
4
|
This script is intended to ease the synchronisation of any site hosted by assos.
|
5
|
It relies on bash, drush and requires a valid d7-sync-config.sh.
|
6
|
The drupal installation is synched using git, the website files and database using rsync.
|
7
|
|
8
|
usage: d7-sync.sh [SITENAME]
|
9
|
If a sitename is provided, the script will sync the drupal installation and the sites'
|
10
|
folders and database. Othewise, only the drupal installation is synched.
|
11
|
|
12
|
TODO: improve chmod on files.
|
13
|
EOF
|
14
|
|
15
|
### Init
|
16
|
# Config
|
17
|
source d7-sync-config.sh || source d7-sync-config.example.sh
|
18
|
source ~/.bashrc
|
19
|
shopt -s expand_aliases
|
20
|
cd $DIR_MULTIASSOS
|
21
|
ret=$?
|
22
|
if [ $ret -ne 0 ] ; then
|
23
|
echo "No config file. Exiting."
|
24
|
exit 2
|
25
|
fi
|
26
|
# git
|
27
|
git checkout master
|
28
|
git branch $LOCAL_BRANCH_NAME
|
29
|
|
30
|
### sync drupal tree
|
31
|
git pull --rebase
|
32
|
git checkout $LOCAL_BRANCH_NAME
|
33
|
# Auto solve conflicts: it takes the version from master in case of conflict.
|
34
|
git rebase master --strategy-option ours
|
35
|
|
36
|
### sync files
|
37
|
if [ -z "$1" ] ; then
|
38
|
exit 0
|
39
|
fi
|
40
|
|
41
|
cd $DIR_DRUPAL7_SITES
|
42
|
|
43
|
# Some variables are different for default
|
44
|
if [ $1 = default ] ; then
|
45
|
dir_site=$1
|
46
|
base_url=http://$DOMAIN
|
47
|
local_db_name=assos_default
|
48
|
else
|
49
|
dir_site=assos.centrale-marseille.fr.$1
|
50
|
base_url=http://$DOMAIN/$1
|
51
|
local_db_name=$1
|
52
|
fi
|
53
|
|
54
|
mkdir $dir_site
|
55
|
cd $dir_site
|
56
|
rsync_from_assos -rltp --progress --delete drupal7/sites/$dir_site/ .
|
57
|
# Change permissions for Apache
|
58
|
# TODO: do something less permissive than 755
|
59
|
chmod -R 755 .
|
60
|
chmod -R 777 files
|
61
|
|
62
|
|
63
|
### sync databases
|
64
|
now=$(date +%s)
|
65
|
sql_file="$1.$now.sql"
|
66
|
remote_sql_file="~/tmp/$sql_file"
|
67
|
assos "drush @$1 sql-dump > $remote_sql_file"
|
68
|
scp_from_assos $remote_sql_file .
|
69
|
mysql -u root -e "DROP DATABASE IF EXISTS $local_db_name; CREATE DATABASE $local_db_name"
|
70
|
ret=$?
|
71
|
if [ $ret -ne 0 ] ; then
|
72
|
echo "mysql daemon is not started. Exiting."
|
73
|
assos "rm $remote_sql_file"
|
74
|
rm $sql_file
|
75
|
exit 1
|
76
|
fi
|
77
|
mysql -u root $local_db_name < $sql_file
|
78
|
rm $sql_file
|
79
|
assos "rm $remote_sql_file"
|
80
|
|
81
|
### modify settings.php
|
82
|
python3 $DIR_MULTIASSOS/other-scripts/modify-settings.py settings.local.php --baseurl $base_url --database $local_db_name
|
83
|
chmod 666 *.php
|
84
|
|
85
|
### Modify sites.php
|
86
|
sed "s/\['assos.centrale-marseille.fr[a-b1-9]*/['$DOMAIN/g" < $SITES_PHP > $SITES_PHP.tmp
|
87
|
mv $SITES_PHP.tmp $SITES_PHP
|
88
|
git commit -a -m "Modify sites.php"
|
89
|
|
90
|
### various drush cmd to finish synchronisation
|
91
|
drush status > /dev/null
|
92
|
ret=$?
|
93
|
if [ $ret -ne 0 ] ; then
|
94
|
echo "drush or site has a problem. Exiting."
|
95
|
exit 1
|
96
|
fi
|
97
|
drush -y dis piwik
|
98
|
drush -y vset maintenace_mode 0
|
99
|
drush -y vset error_level 2
|
100
|
drush -y dis cas
|
101
|
drush -y user-unblock 1
|
102
|
drush cc all
|