Project

General

Profile

Paste
Download (1.56 KB) Statistics
| Branch: | Revision:

root / other-scripts / d7-sync.sh @ fdbc8338

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
mysql -u root $1 < $sql_file
53
rm $sql_file
54
ssh assos "rm $remote_sql_file"
55

    
56
### modify settings.php
57
python3 $root/other-scripts/modify-settings.py settings.local.php --baseurl assos.local/$1
58

    
59
### various drush cmd to finish synchronisation
60
drush -y dis piwik
61
drush -y vset maintenace_mode 0
62
drush -y vset error_level 2
63
drush cc all