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