Projet

Général

Profil

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

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

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. You must have
6
configured SSH so that ssh webassos connects you to the webserver.
7
The drupal installation is synched using git, the website files and database using rsync.
8

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

    
13
TODO: improve chmod on files.
14
EOF
15

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

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

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

    
40
cd $DIR_DRUPAL7_SITES
41

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

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

    
61

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

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

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

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