Projet

Général

Profil

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

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

1
#!/usr/bin/env bash
2

    
3
help=<<EOF
4
This script is intended to ease the synchronisation of any site hosted by assos.
5
It relies on bash, drush and requires a valid d7-sync-config.sh.
6
The drupal installation is synched using git, the website files and database using rsync.
7

    
8
usage: d7-sync.sh [SITENAME]
9
If a sitename is provided, the script will sync the drupal installation and the sites'
10
folders and database. Othewise, only the drupal installation is synched.
11

    
12
TODO: improve chmod on files.
13
EOF
14

    
15
### Init
16
# Config
17
source d7-sync-config.sh || source d7-sync-config.example.sh
18
cd $DIR_MULTIASSOS
19
ret=$?
20
if [ $ret -ne 0 ] ; then
21
    echo "No config file. Exiting."
22
    exit 2
23
fi
24
# git
25
git checkout master
26
git branch $LOCAL_BRANCH_NAME
27

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

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

    
39
cd $DIR_DRUPAL7_SITES
40

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

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

    
60

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

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

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

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