1 |
0ddd66a7
|
Julien Enselme
|
#!/usr/bin/env bash
|
2 |
5b5ea032
|
Julien Enselme
|
|
3 |
|
|
help=<<EOF
|
4 |
f6a5e032
|
Julien Enselme
|
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 |
5b5ea032
|
Julien Enselme
|
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 |
edeafe5e
|
Julien Enselme
|
TODO: improve chmod on files.
|
13 |
5b5ea032
|
Julien Enselme
|
EOF
|
14 |
|
|
|
15 |
3e00cc24
|
Julien Enselme
|
### Init
|
16 |
|
|
# Config
|
17 |
e8e4ed1e
|
Julien Enselme
|
source d7-sync-config.sh || source d7-sync-config.example.shc
|
18 |
|
|
source ~/.bashrc
|
19 |
af06b65b
|
Julien Enselme
|
shopt -s expand_aliases
|
20 |
3e00cc24
|
Julien Enselme
|
cd $DIR_MULTIASSOS
|
21 |
|
|
ret=$?
|
22 |
|
|
if [ $ret -ne 0 ] ; then
|
23 |
|
|
echo "No config file. Exiting."
|
24 |
|
|
exit 2
|
25 |
|
|
fi
|
26 |
0ddd66a7
|
Julien Enselme
|
# git
|
27 |
|
|
git checkout master
|
28 |
|
|
git branch $LOCAL_BRANCH_NAME
|
29 |
|
|
|
30 |
fdbc8338
|
Julien Enselme
|
### sync drupal tree
|
31 |
5b5ea032
|
Julien Enselme
|
git pull --rebase
|
32 |
0ddd66a7
|
Julien Enselme
|
git checkout $LOCAL_BRANCH_NAME
|
33 |
651f07b1
|
Julien Enselme
|
# Auto solve conflicts: it takes the version from master in case of conflict.
|
34 |
|
|
git rebase master --strategy-option ours
|
35 |
5b5ea032
|
Julien Enselme
|
|
36 |
fdbc8338
|
Julien Enselme
|
### sync files
|
37 |
5b5ea032
|
Julien Enselme
|
if [ -z "$1" ] ; then
|
38 |
|
|
exit 0
|
39 |
|
|
fi
|
40 |
|
|
|
41 |
3e00cc24
|
Julien Enselme
|
cd $DIR_DRUPAL7_SITES
|
42 |
fdbc8338
|
Julien Enselme
|
|
43 |
94cf1d43
|
Julien Enselme
|
# Some variables are different for default
|
44 |
5b5ea032
|
Julien Enselme
|
if [ $1 = default ] ; then
|
45 |
|
|
dir_site=$1
|
46 |
94cf1d43
|
Julien Enselme
|
base_url=http://$DOMAIN
|
47 |
|
|
local_db_name=assos_default
|
48 |
5b5ea032
|
Julien Enselme
|
else
|
49 |
|
|
dir_site=assos.centrale-marseille.fr.$1
|
50 |
94cf1d43
|
Julien Enselme
|
base_url=http://$DOMAIN/$1
|
51 |
|
|
local_db_name=$1
|
52 |
5b5ea032
|
Julien Enselme
|
fi
|
53 |
94cf1d43
|
Julien Enselme
|
|
54 |
5b5ea032
|
Julien Enselme
|
mkdir $dir_site
|
55 |
|
|
cd $dir_site
|
56 |
b79523b7
|
Julien Enselme
|
rsync_from_assos -rltp --progress --delete drupal7/sites/$dir_site/* .
|
57 |
fdbc8338
|
Julien Enselme
|
# Change permissions for Apache
|
58 |
|
|
# TODO: do something less permissive than 755
|
59 |
|
|
chmod -R 755 .
|
60 |
|
|
chmod -R 777 files
|
61 |
|
|
|
62 |
5b5ea032
|
Julien Enselme
|
|
63 |
fdbc8338
|
Julien Enselme
|
### sync databases
|
64 |
5b5ea032
|
Julien Enselme
|
now=$(date +%s)
|
65 |
|
|
sql_file="$1.$now.sql"
|
66 |
|
|
remote_sql_file="~/tmp/$sql_file"
|
67 |
f6a5e032
|
Julien Enselme
|
assos "drush @$1 sql-dump > $remote_sql_file"
|
68 |
|
|
scp_from_assos $remote_sql_file .
|
69 |
94cf1d43
|
Julien Enselme
|
mysql -u root -e "DROP DATABASE IF EXISTS $local_db_name; CREATE DATABASE $local_db_name"
|
70 |
a500a624
|
Julien Enselme
|
ret=$?
|
71 |
|
|
if [ $ret -ne 0 ] ; then
|
72 |
|
|
echo "mysql daemon is not started. Exiting."
|
73 |
f6a5e032
|
Julien Enselme
|
assos "rm $remote_sql_file"
|
74 |
fd64390e
|
Julien Enselme
|
rm $sql_file
|
75 |
a500a624
|
Julien Enselme
|
exit 1
|
76 |
|
|
fi
|
77 |
94cf1d43
|
Julien Enselme
|
mysql -u root $local_db_name < $sql_file
|
78 |
5b5ea032
|
Julien Enselme
|
rm $sql_file
|
79 |
f6a5e032
|
Julien Enselme
|
assos "rm $remote_sql_file"
|
80 |
5b5ea032
|
Julien Enselme
|
|
81 |
fdbc8338
|
Julien Enselme
|
### modify settings.php
|
82 |
4d8cf5d8
|
Julien Enselme
|
python3 $DIR_MULTIASSOS/other-scripts/modify-settings.py settings.local.php --baseurl $base_url --database $local_db_name
|
83 |
edeafe5e
|
Julien Enselme
|
chmod 666 *.php
|
84 |
5b5ea032
|
Julien Enselme
|
|
85 |
0ddd66a7
|
Julien Enselme
|
### 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 |
fdbc8338
|
Julien Enselme
|
### various drush cmd to finish synchronisation
|
91 |
a500a624
|
Julien Enselme
|
drush status > /dev/null
|
92 |
|
|
ret=$?
|
93 |
edeafe5e
|
Julien Enselme
|
if [ $ret -ne 0 ] ; then
|
94 |
f6a5e032
|
Julien Enselme
|
echo "drush or site has a problem. Exiting."
|
95 |
a500a624
|
Julien Enselme
|
exit 1
|
96 |
|
|
fi
|
97 |
5b5ea032
|
Julien Enselme
|
drush -y dis piwik
|
98 |
|
|
drush -y vset maintenace_mode 0
|
99 |
|
|
drush -y vset error_level 2
|
100 |
9e14604f
|
Julien Enselme
|
drush -y dis cas
|
101 |
|
|
drush -y user-unblock 1
|
102 |
5b5ea032
|
Julien Enselme
|
drush cc all |