Projet

Général

Profil

Paste
Télécharger (1,81 ko) Statistiques
| Branche: | Révision:

root / other-scripts / d7-sync.sh @ 94065d4e

1 5b5ea032 Julien Enselme
#!/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 fdbc8338 Julien Enselme
### sync drupal tree
15 5b5ea032 Julien Enselme
git pull --rebase
16
17 fdbc8338 Julien Enselme
### sync files
18 5b5ea032 Julien Enselme
if [ -z "$1" ] ; then
19
    exit 0
20
fi
21
22 ef903da4 Julien Enselme
root=$(pwd)
23 94065d4e Julien Enselme
cd drupal7/sites
24 fdbc8338 Julien Enselme
25
ret=$?
26
if [ $ret -ne 0 ] ; then
27
    echo 'Not in the right directory. Exiting.'
28
    exit 1
29
fi
30
31 5b5ea032 Julien Enselme
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 94065d4e Julien Enselme
rsync -rl --progress assos:~/drupal7/sites/$dir_site/* .
39 fdbc8338 Julien Enselme
# Change permissions for Apache
40
# TODO: do something less permissive than 755
41
chmod -R 755 .
42
chmod -R 777 files
43
44 5b5ea032 Julien Enselme
45 fdbc8338 Julien Enselme
### sync databases
46 5b5ea032 Julien Enselme
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 a500a624 Julien Enselme
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 5b5ea032 Julien Enselme
mysql -u root $1 < $sql_file
59
rm $sql_file
60
ssh assos "rm $remote_sql_file"
61
62 fdbc8338 Julien Enselme
### modify settings.php
63
python3 $root/other-scripts/modify-settings.py settings.local.php --baseurl assos.local/$1
64 5b5ea032 Julien Enselme
65 fdbc8338 Julien Enselme
### various drush cmd to finish synchronisation
66 a500a624 Julien Enselme
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 5b5ea032 Julien Enselme
drush -y dis piwik
73
drush -y vset maintenace_mode 0
74
drush -y vset error_level 2
75
drush cc all