Project

General

Profile

Paste
Download (2.78 KB) Statistics
| Branch: | Revision:

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

1 0ddd66a7 Julien Enselme
#!/usr/bin/env bash
2 5b5ea032 Julien Enselme
3
help=<<EOF
4 f6a5e032 Julien Enselme
This script is intended to ease the synchronisation of any site hosted by assos.
5 e71cae50 Julien Enselme
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 5b5ea032 Julien Enselme
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 edeafe5e Julien Enselme
TODO: improve chmod on files.
14 5b5ea032 Julien Enselme
EOF
15
16 3e00cc24 Julien Enselme
### Init
17
# Config
18 1bb5a230 Julien Enselme
source d7-sync-config.sh || source d7-sync-config.example.sh
19 3e9236bd Julien Enselme
cd "${DIR_MULTIASSOS}"
20
ret="$?"
21
if [ "${ret}" -ne 0 ] ; then
22 3e00cc24 Julien Enselme
    echo "No config file. Exiting."
23
    exit 2
24
fi
25 0ddd66a7 Julien Enselme
# git
26
git checkout master
27 3e9236bd Julien Enselme
git branch "${LOCAL_BRANCH_NAME}"
28 0ddd66a7 Julien Enselme
29 fdbc8338 Julien Enselme
### sync drupal tree
30 5b5ea032 Julien Enselme
git pull --rebase
31 3e9236bd Julien Enselme
git checkout "${LOCAL_BRANCH_NAME}"
32 651f07b1 Julien Enselme
# Auto solve conflicts: it takes the version from master in case of conflict.
33
git rebase master --strategy-option ours
34 5b5ea032 Julien Enselme
35 fdbc8338 Julien Enselme
### sync files
36 5b5ea032 Julien Enselme
if [ -z "$1" ] ; then
37
    exit 0
38
fi
39
40 3e9236bd Julien Enselme
cd "${DIR_DRUPAL7_SITES}"
41 fdbc8338 Julien Enselme
42 94cf1d43 Julien Enselme
# Some variables are different for default
43 3e9236bd Julien Enselme
if [ "$1" = default ] ; then
44
    dir_site="$1"
45
    base_url="http://${DOMAIN}"
46 94cf1d43 Julien Enselme
    local_db_name=assos_default
47 5b5ea032 Julien Enselme
else
48 3e9236bd Julien Enselme
    dir_site="assos.centrale-marseille.fr.$1"
49
    base_url="http://${DOMAIN}/$1"
50
    local_db_name="$1"
51 5b5ea032 Julien Enselme
fi
52 94cf1d43 Julien Enselme
53 3e9236bd Julien Enselme
mkdir "${dir_site}"
54
cd "${dir_site}"
55
rsync -rltp --progress --delete "${WEBASSOS_ID}:drupal7/sites/${dir_site}/" .
56 fdbc8338 Julien Enselme
# Change permissions for Apache
57
# TODO: do something less permissive than 755
58
chmod -R 755 .
59
chmod -R 777 files
60
61 5b5ea032 Julien Enselme
62 fdbc8338 Julien Enselme
### sync databases
63 8550e097 Julien Enselme
now=$(date +%s)
64 3e9236bd Julien Enselme
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 94cf1d43 Julien Enselme
mysql -u root -e "DROP DATABASE IF EXISTS $local_db_name; CREATE DATABASE $local_db_name"
69 3e9236bd Julien Enselme
ret="$?"
70
if [ "${ret}" -ne 0 ] ; then
71 a500a624 Julien Enselme
    echo "mysql daemon is not started. Exiting."
72 f6a5e032 Julien Enselme
    assos "rm $remote_sql_file"
73 3e9236bd Julien Enselme
    rm "${sql_file}"
74 a500a624 Julien Enselme
    exit 1
75
fi
76 3e9236bd Julien Enselme
mysql -u root "${local_db_name}" < "${sql_file}"
77
rm "${sql_file}"
78
ssh "${WEBASSOS_ID}" "rm ${remote_sql_file}"
79 5b5ea032 Julien Enselme
80 fdbc8338 Julien Enselme
### modify settings.php
81 3e9236bd Julien Enselme
python3 "${DIR_MULTIASSOS}/other-scripts/modify-settings.py" "settings.local.php" --baseurl "${base_url}" --database "${local_db_name}"
82 edeafe5e Julien Enselme
chmod 666 *.php
83 5b5ea032 Julien Enselme
84 0ddd66a7 Julien Enselme
### Modify sites.php
85 3e9236bd Julien Enselme
sed "s/\['assos.centrale-marseille.fr[a-b1-9]*/['$DOMAIN/g" < "${SITES_PHP}" > "${SITES_PHP}.tmp"
86
mv "${SITES_PHP}.tmp" "${SITES_PHP}"
87 0ddd66a7 Julien Enselme
git commit -a -m "Modify sites.php"
88
89 fdbc8338 Julien Enselme
### various drush cmd to finish synchronisation
90 a500a624 Julien Enselme
drush status > /dev/null
91 3e9236bd Julien Enselme
ret="$?"
92
if [ "$ret" -ne 0 ] ; then
93 f6a5e032 Julien Enselme
    echo "drush or site has a problem. Exiting."
94 a500a624 Julien Enselme
    exit 1
95
fi
96 09f08e34 Florent Torregrosa
drush -y dis matomo
97 5b5ea032 Julien Enselme
drush -y vset maintenace_mode 0
98
drush -y vset error_level 2
99 9e14604f Julien Enselme
drush -y dis cas
100
drush -y user-unblock 1
101 5b5ea032 Julien Enselme
drush cc all