1
|
#!/usr/bin/bash
|
2
|
|
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
|
You must launch this script at the root of the drupal instance.
|
12
|
EOF
|
13
|
|
14
|
### sync drupal tree
|
15
|
git pull --rebase
|
16
|
|
17
|
### sync files
|
18
|
if [ -z "$1" ] ; then
|
19
|
exit 0
|
20
|
fi
|
21
|
|
22
|
root=$(pwd)
|
23
|
cd htmltest/sites
|
24
|
|
25
|
ret=$?
|
26
|
if [ $ret -ne 0 ] ; then
|
27
|
echo 'Not in the right directory. Exiting.'
|
28
|
exit 1
|
29
|
fi
|
30
|
|
31
|
if [ $1 = default ] ; then
|
32
|
dir_site=$1
|
33
|
else
|
34
|
dir_site=assos.centrale-marseille.fr.$1
|
35
|
fi
|
36
|
mkdir $dir_site
|
37
|
cd $dir_site
|
38
|
rsync -rl --progress assos:~/htmltest/sites/$dir_site/* .
|
39
|
# Change permissions for Apache
|
40
|
# TODO: do something less permissive than 755
|
41
|
chmod -R 755 .
|
42
|
chmod -R 777 files
|
43
|
|
44
|
|
45
|
### sync databases
|
46
|
now=$(date +%s)
|
47
|
sql_file="$1.$now.sql"
|
48
|
remote_sql_file="~/tmp/$sql_file"
|
49
|
ssh assos "drush @$1 sql-dump > $remote_sql_file"
|
50
|
scp assos:$remote_sql_file .
|
51
|
mysql -u root -e "DROP DATABASE IF EXISTS $1; CREATE DATABASE $1"
|
52
|
ret=$?
|
53
|
if [ $ret -ne 0 ] ; then
|
54
|
echo "mysql daemon is not started. Exiting."
|
55
|
ssh assos "rm $remote_sql_file"
|
56
|
exit 1
|
57
|
fi
|
58
|
mysql -u root $1 < $sql_file
|
59
|
rm $sql_file
|
60
|
ssh assos "rm $remote_sql_file"
|
61
|
|
62
|
### modify settings.php
|
63
|
python3 $root/other-scripts/modify-settings.py settings.local.php --baseurl assos.local/$1
|
64
|
|
65
|
### various drush cmd to finish synchronisation
|
66
|
drush status > /dev/null
|
67
|
ret=$?
|
68
|
if [ $ret -neq 0 ] ; then
|
69
|
echo "drush or site has a problem. Exiting"
|
70
|
exit 1
|
71
|
fi
|
72
|
drush -y dis piwik
|
73
|
drush -y vset maintenace_mode 0
|
74
|
drush -y vset error_level 2
|
75
|
drush cc all
|