Projet

Général

Profil

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

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

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
source d7-sync-functions.sh
19
source ~/.bashrc
20
shopt -s expand_aliases
21
cd $DIR_MULTIASSOS
22
ret=$?
23
if [ $ret -ne 0 ] ; then
24
    echo "No config file. Exiting."
25
    exit 2
26
fi
27
# git
28
git checkout master
29
git branch $LOCAL_BRANCH_NAME
30

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

    
37
### sync files
38
if [ -z "$1" ] ; then
39
    exit 0
40
fi
41

    
42
cd $DIR_DRUPAL7_SITES
43

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

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

    
63

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

    
82
### modify settings.php
83
python3 $DIR_MULTIASSOS/other-scripts/modify-settings.py settings.local.php --baseurl $base_url --database $local_db_name
84
chmod 666 *.php
85

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

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