Projet

Général

Profil

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

root / other-scripts / d7-sync.sh @ 3e00cc24

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 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 fdbc8338 Julien Enselme
### sync drupal tree
24 5b5ea032 Julien Enselme
git pull --rebase
25
26 fdbc8338 Julien Enselme
### sync files
27 5b5ea032 Julien Enselme
if [ -z "$1" ] ; then
28
    exit 0
29
fi
30
31 3e00cc24 Julien Enselme
cd $DIR_DRUPAL7_SITES
32 fdbc8338 Julien Enselme
33 5b5ea032 Julien Enselme
if [ $1 = default ] ; then
34
    dir_site=$1
35
else
36
    dir_site=assos.centrale-marseille.fr.$1
37
fi
38
mkdir $dir_site
39
cd $dir_site
40 94065d4e Julien Enselme
rsync -rl --progress assos:~/drupal7/sites/$dir_site/* .
41 fdbc8338 Julien Enselme
# Change permissions for Apache
42
# TODO: do something less permissive than 755
43
chmod -R 755 .
44
chmod -R 777 files
45
46 5b5ea032 Julien Enselme
47 fdbc8338 Julien Enselme
### sync databases
48 5b5ea032 Julien Enselme
now=$(date +%s)
49
sql_file="$1.$now.sql"
50
remote_sql_file="~/tmp/$sql_file"
51
ssh assos "drush @$1 sql-dump > $remote_sql_file"
52
scp assos:$remote_sql_file .
53
mysql -u root -e "DROP DATABASE IF EXISTS $1; CREATE DATABASE $1"
54 a500a624 Julien Enselme
ret=$?
55
if [ $ret -ne 0 ] ; then
56
    echo "mysql daemon is not started. Exiting."
57
    ssh assos "rm $remote_sql_file"
58
    exit 1
59
fi
60 5b5ea032 Julien Enselme
mysql -u root $1 < $sql_file
61
rm $sql_file
62
ssh assos "rm $remote_sql_file"
63
64 fdbc8338 Julien Enselme
### modify settings.php
65 3e00cc24 Julien Enselme
if [ $1 = 'default' ] ; then
66
    base_url=$DOMAIN
67
else
68
    base_url=$DOMAIN/$1
69
fi
70
python3 $DIR_MULTIASSOS/other-scripts/modify-settings.py settings.local.php --baseurl $base_url
71 5b5ea032 Julien Enselme
72 fdbc8338 Julien Enselme
### various drush cmd to finish synchronisation
73 a500a624 Julien Enselme
drush status > /dev/null
74
ret=$?
75
if [ $ret -neq 0 ] ; then
76
    echo "drush or site has a problem. Exiting"
77
    exit 1
78
fi
79 5b5ea032 Julien Enselme
drush -y dis piwik
80
drush -y vset maintenace_mode 0
81
drush -y vset error_level 2
82
drush cc all