Projet

Général

Profil

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

root / other-scripts / d7-sync.sh @ 4d8cf5d8

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 edeafe5e Julien Enselme
TODO: improve chmod on files.
12 5b5ea032 Julien Enselme
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 651f07b1 Julien Enselme
# Auto solve conflicts: it takes the version from master in case of conflict.
31
git rebase master --strategy-option ours
32 5b5ea032 Julien Enselme
33 fdbc8338 Julien Enselme
### sync files
34 5b5ea032 Julien Enselme
if [ -z "$1" ] ; then
35
    exit 0
36
fi
37
38 3e00cc24 Julien Enselme
cd $DIR_DRUPAL7_SITES
39 fdbc8338 Julien Enselme
40 94cf1d43 Julien Enselme
# Some variables are different for default
41 5b5ea032 Julien Enselme
if [ $1 = default ] ; then
42
    dir_site=$1
43 94cf1d43 Julien Enselme
    base_url=http://$DOMAIN
44
    local_db_name=assos_default
45 5b5ea032 Julien Enselme
else
46
    dir_site=assos.centrale-marseille.fr.$1
47 94cf1d43 Julien Enselme
    base_url=http://$DOMAIN/$1
48
    local_db_name=$1
49 5b5ea032 Julien Enselme
fi
50 94cf1d43 Julien Enselme
51 5b5ea032 Julien Enselme
mkdir $dir_site
52
cd $dir_site
53 22928687 Julien Enselme
rsync -rltp --progress --delete assos:~/drupal7/sites/$dir_site/* .
54 fdbc8338 Julien Enselme
# Change permissions for Apache
55
# TODO: do something less permissive than 755
56
chmod -R 755 .
57
chmod -R 777 files
58
59 5b5ea032 Julien Enselme
60 fdbc8338 Julien Enselme
### sync databases
61 5b5ea032 Julien Enselme
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 94cf1d43 Julien Enselme
mysql -u root -e "DROP DATABASE IF EXISTS $local_db_name; CREATE DATABASE $local_db_name"
67 a500a624 Julien Enselme
ret=$?
68
if [ $ret -ne 0 ] ; then
69
    echo "mysql daemon is not started. Exiting."
70
    ssh assos "rm $remote_sql_file"
71 fd64390e Julien Enselme
    rm $sql_file
72 a500a624 Julien Enselme
    exit 1
73
fi
74 94cf1d43 Julien Enselme
mysql -u root $local_db_name < $sql_file
75 5b5ea032 Julien Enselme
rm $sql_file
76
ssh assos "rm $remote_sql_file"
77
78 fdbc8338 Julien Enselme
### modify settings.php
79 4d8cf5d8 Julien Enselme
python3 $DIR_MULTIASSOS/other-scripts/modify-settings.py settings.local.php --baseurl $base_url --database $local_db_name
80 edeafe5e Julien Enselme
chmod 666 *.php
81 5b5ea032 Julien Enselme
82 0ddd66a7 Julien Enselme
### 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 fdbc8338 Julien Enselme
### various drush cmd to finish synchronisation
88 a500a624 Julien Enselme
drush status > /dev/null
89
ret=$?
90 edeafe5e Julien Enselme
if [ $ret -ne 0 ] ; then
91 a500a624 Julien Enselme
    echo "drush or site has a problem. Exiting"
92
    exit 1
93
fi
94 5b5ea032 Julien Enselme
drush -y dis piwik
95
drush -y vset maintenace_mode 0
96
drush -y vset error_level 2
97 9e14604f Julien Enselme
drush -y dis cas
98
drush -y user-unblock 1
99 5b5ea032 Julien Enselme
drush cc all