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