Projet

Général

Profil

Paste
Télécharger (2,25 ko) Statistiques
| Branche: | Révision:

root / other-scripts / d7-sync.sh @ 0ddd66a7

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