Projet

Général

Profil

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

root / other-scripts / d7-sync.sh @ 94cf1d43

1
#!/usr/bin/env 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
TODO: improve chmod on files.
12
EOF
13

    
14
### 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
# git
24
git checkout master
25
git branch $LOCAL_BRANCH_NAME
26

    
27
### sync drupal tree
28
git pull --rebase
29
git checkout $LOCAL_BRANCH_NAME
30
# Auto solve conflicts: it takes the version from master in case of conflict.
31
git rebase master --strategy-option ours
32

    
33
### sync files
34
if [ -z "$1" ] ; then
35
    exit 0
36
fi
37

    
38
cd $DIR_DRUPAL7_SITES
39

    
40
# Some variables are different for default
41
if [ $1 = default ] ; then
42
    dir_site=$1
43
    base_url=http://$DOMAIN
44
    local_db_name=assos_default
45
else
46
    dir_site=assos.centrale-marseille.fr.$1
47
    base_url=http://$DOMAIN/$1
48
    local_db_name=$1
49
fi
50

    
51
mkdir $dir_site
52
cd $dir_site
53
rsync -rltp --progress --delete assos:~/drupal7/sites/$dir_site/* .
54
# Change permissions for Apache
55
# TODO: do something less permissive than 755
56
chmod -R 755 .
57
chmod -R 777 files
58

    
59

    
60
### sync databases
61
now=$(date +%s)
62
sql_file="$1.$now.sql"
63
remote_sql_file="~/tmp/$sql_file"
64
ssh assos "drush @$1 sql-dump > $remote_sql_file"
65
scp assos:$remote_sql_file .
66
mysql -u root -e "DROP DATABASE IF EXISTS $local_db_name; CREATE DATABASE $local_db_name"
67
ret=$?
68
if [ $ret -ne 0 ] ; then
69
    echo "mysql daemon is not started. Exiting."
70
    ssh assos "rm $remote_sql_file"
71
    rm $sql_file
72
    exit 1
73
fi
74
mysql -u root $local_db_name < $sql_file
75
rm $sql_file
76
ssh assos "rm $remote_sql_file"
77

    
78
### modify settings.php
79
python3 $DIR_MULTIASSOS/other-scripts/modify-settings.py settings.local.php --baseurl $base_url
80
chmod 666 *.php
81

    
82
### Modify sites.php
83
sed "s/\['assos.centrale-marseille.fr[a-b1-9]*/['$DOMAIN/g" < $SITES_PHP > $SITES_PHP.tmp
84
mv $SITES_PHP.tmp $SITES_PHP
85
git commit -a -m "Modify sites.php"
86

    
87
### various drush cmd to finish synchronisation
88
drush status > /dev/null
89
ret=$?
90
if [ $ret -ne 0 ] ; then
91
    echo "drush or site has a problem. Exiting"
92
    exit 1
93
fi
94
drush -y dis piwik
95
drush -y vset maintenace_mode 0
96
drush -y vset error_level 2
97
drush -y dis cas
98
drush -y user-unblock 1
99
drush cc all