Project

General

Profile

Revision d4c4525a

Added by Julien Enselme almost 9 years ago

Use drush aliases to loop on all sites instead of sites.

Close #535

View differences:

bin/all-reset-permissions.sh
1 1
#!/bin/sh
2 2

  
3 3
. /home/assos/bin/scripts-config.sh
4
. /home/assos/bin/scripts-utils.sh
4 5

  
5 6
# This script puts the correct permissions to sites folders, settings.php and scripts.
6 7

  
7 8
######### drupal 7
8
for dir in $(find "${d7_dir_sites}" -type d -maxdepth 1 -mindepth 1 ! -name all); do
9
for site in $(sites_list); do
10
    dir=$(get_absolute_site_dir_from_name "${site}")
9 11
    chmod 755 "${dir}"
10 12
    chmod 400 "${dir}/settings.php"
11 13
    chmod 400 "${dir}/settings.local.php"
bin/d7-all-drush.sh
19 19

  
20 20
check_arguments "$#" 1 "${help}"
21 21

  
22
for dir in $(find "${d7_dir_sites}" -maxdepth 1 -mindepth 1 -type d ! -name all | sort) ; do
23
    cd "${dir}"
24
    echo "${dir}"
25
    drush "$@"
22
for site in $(sites_list) ; do
23
    echo "${site}"
24
    drush @"${site}" "$@"
26 25
    sleep 5
27 26
done
bin/d7-all-dump-individual.sh
30 30

  
31 31
cd "${d7_dir_sites}"
32 32

  
33
# cut -c3- is used to transform directories from ./<dirname> to <dirname>
34
for dir in $(find . -maxdepth 1 -mindepth 1 -type d ! -name all | cut -c3-); do
35
    cd "${dir}"
36
    drush cc all
33
for site in $(sites_list); do
34
    drush @"${site}" cc all
35

  
36
    dir=$(get_site_dir_from_name "${site}")
37

  
37 38
    if [ "${mode}" = 'auto' ] ; then
38
        drush sql-dump --result-file="${d7_dir_individual_auto_backup}/${dir}/${current_date}.${dir}.sql" --gzip
39
        drush @"${site}" sql-dump --result-file="${d7_dir_individual_auto_backup}/${dir}/${current_date}.${dir}.sql" --gzip
39 40
    else
40
        drush sql-dump --result-file="${d7_dir_individual_manual_backup}/${dir}/${current_date}.${dir}.sql" --gzip
41
        drush @"${site}" sql-dump --result-file="${d7_dir_individual_manual_backup}/${dir}/${current_date}.${dir}.sql" --gzip
41 42
    fi
42 43
    cd -
43 44
done
bin/d7-all-reset-variables.sh
3 3
. /home/assos/bin/scripts-config.sh
4 4
. /home/assos/bin/scripts-utils.sh
5 5

  
6
for dir in $(find "${d7_dir_sites}" -maxdepth 1 -mindepth 1 -type d ! -name all | sort); do
7
    echo "${dir}"
8
    site_name=$(get_site_name_from_dir_name "${dir}")
9
    d7-reset-variables.sh "${site_name}"
6
for site in $(sites_list); do
7
    echo "${site}"
8
    d7-reset-variables.sh "${site}"
10 9
done
bin/d7-reset-piwik-variables.sh
1 1
#!/bin/sh
2 2

  
3
site="$1"
4

  
3 5
###### Common to all sites
4
drush -yq en piwik
5
drush -yq vset piwik_url_http "http://piwik.centrale-marseille.fr/"
6
drush -yq vset piwik_url_https "https://piwik.centrale-marseille.fr/"
6
drush @"${site}" -yq en piwik
7
drush @"${site}" -yq vset piwik_url_http "http://piwik.centrale-marseille.fr/"
8
drush @"${site}" -yq vset piwik_url_https "https://piwik.centrale-marseille.fr/"
7 9
# Piwik cache.
8
drush -yq vset piwik_cache 1
9
drush -yq vset piwik_visibility_roles "1"
10
drush @"${site}" -yq vset piwik_cache 1
11
drush @"${site}" -yq vset piwik_visibility_roles "1"
10 12
# Piwik is enable for everyone except the administrator
11
drush -yq vset --format=json piwik_roles '[3]'
12
drush -yq vset piwik_page_title_hierarchy 1
13
drush @"${site}" -yq vset --format=json piwik_roles '[3]'
14
drush @"${site}" -yq vset piwik_page_title_hierarchy 1
13 15
# Activate local search.
14
drush -yq vset piwik_site_search 1
16
drush @"${site}" -yq vset piwik_site_search 1
15 17

  
16 18
##### Specific
17 19
# Note: you can read the piwik site id from the url in piwik
......
79 81
    ftorregrosa)
80 82
	piwik_id=314
81 83
	;;
84
    default)
85
	piwik_id=101
86
	;;
82 87
    *)
83 88
	piwik_id=287
84 89
	;;
85 90
esac
86 91

  
87
# Default is an exception and cannot be treated in the case
88
if [ "$1" = 'default' ] ; then
89
    piwik_id=101
90
fi
91

  
92
drush -yq vset piwik_site_id "${piwik_id}"
92
drush @"${site}" -yq vset piwik_site_id "${piwik_id}"
bin/d7-reset-variables.sh
7 7
. /home/assos/bin/scripts-config.sh
8 8
. /home/assos/bin/print-help-if-required.sh
9 9

  
10
if [ -n "$1" ] ; then
11
    param="$1" . /home/assos/bin/scripts-config-site.sh
12
    if [ "$1" = 'default' ] ; then
13
	cd "${d7_dir_sites}/default"
14
    else
15
	cd "${d7_site_dir}"
16
    fi
17
fi
10
site="$1"
18 11

  
19 12
current_timestamp=$(date "+%s")
20 13

  
......
22 15
random_2=$(dd if=/dev/urandom count=1 2> /dev/null | cksum | cut -f1 -d" ")
23 16

  
24 17
####### General variables
25
drush -yq vset --always-set reverse_proxy TRUE
26
drush -yq vset --always-set --format=json reverse_proxy_addresses '["147.94.19.16","147.94.19.17"]'
27
drush -yq ev "variable_set('update_notify_emails', array('$email_multi_assos_update'));"
28
drush -yq vset error_level 0
29
drush -yq vset dblog_row_limit 1000
30
drush -yq vset cron_safe_threshold 0
31
drush -yq vset file_temporary_path /var/tmp/assos/tmp
18
drush @"${site}" -yq vset --always-set reverse_proxy TRUE
19
drush @"${site}" -yq vset --always-set --format=json reverse_proxy_addresses '["147.94.19.16","147.94.19.17"]'
20
drush @"${site}" -yq ev "variable_set('update_notify_emails', array('$email_multi_assos_update'));"
21
drush @"${site}" -yq vset error_level 0
22
drush @"${site}" -yq vset dblog_row_limit 1000
23
drush @"${site}" -yq vset cron_safe_threshold 0
24
drush @"${site}" -yq vset file_temporary_path /var/tmp/assos/tmp
32 25

  
33 26
###### Captcha
34
drush -yq en hidden_captcha
27
drush @"${site}" -yq en hidden_captcha
35 28
# Do not log wrong answers.
36
drush -yq vset captcha_enable_stats 0
37
drush -yq vset captcha_log_wrong_responses 0
29
drush @"${site}" -yq vset captcha_enable_stats 0
30
drush @"${site}" -yq vset captcha_log_wrong_responses 0
38 31
# Use hidden captcha for all forms.
39
drush -yq sqlq --db-prefix "UPDATE {captcha_points} SET module = 'hidden_captcha', captcha_type = 'Hidden CAPTCHA' WHERE module is NULL;"
32
drush @"${site}" -yq sqlq --db-prefix "UPDATE {captcha_points} SET module = 'hidden_captcha', captcha_type = 'Hidden CAPTCHA' WHERE module is NULL;"
40 33
# Flush captcha cache.
41
drush -yq vdel captcha_placement_map_cache
34
drush @"${site}" -yq vdel captcha_placement_map_cache
42 35
# Randomly generate a math question as the label of the hidden captcha field.
43
drush -yq vset hidden_captcha_label "$random_1 + $random_2"
36
drush @"${site}" -yq vset hidden_captcha_label "$random_1 + $random_2"
44 37

  
45 38

  
46 39
####### Piwik
47
d7-reset-piwik-variables.sh "${d7_site_name}"
40
d7-reset-piwik-variables.sh "${site}"
48 41

  
49 42
###### Security review
50 43
# For untrusted roles:
51 44
# 1: anonymous user
52 45
# 2: authenticated user
53 46
# 3: administrator
54
drush -yq en security_review
55
drush -yq ev "variable_set('security_review_untrusted_roles', array('1'));"
47
drush @"${site}" -yq en security_review
48
drush @"${site}" -yq ev "variable_set('security_review_untrusted_roles', array('1'));"
56 49
# The default method to check settings.php do not work because we include a global and local settings.php
57
drush -yq vset security_review_base_url_method include
50
drush @"${site}" -yq vset security_review_base_url_method include
58 51
# Used to initialise entries in the database schema.
59
drush -yq security-review --store
52
drush @"${site}" -yq security-review --store
60 53
# file_perms : Security Review can't check for files permissions on multi_assos if launched within the web interface.
61 54
# private_files : we have chosen a private path in the files repository and Security Review raise errors but this path is secure.
62
drush -yq sqlq --db-prefix "UPDATE {security_review} SET skip = '1', skiptime = $current_timestamp, skipuid = '1' WHERE reviewcheck IN ('file_perms', 'private_files');"
63
drush -yq sqlq --db-prefix "UPDATE {security_review} SET skip = '0', skiptime = '0', skipuid = NULL WHERE reviewcheck NOT IN ('file_perms', 'private_files');"
55
drush @"${site}" -yq sqlq --db-prefix "UPDATE {security_review} SET skip = '1', skiptime = $current_timestamp, skipuid = '1' WHERE reviewcheck IN ('file_perms', 'private_files');"
56
drush @"${site}" -yq sqlq --db-prefix "UPDATE {security_review} SET skip = '0', skiptime = '0', skipuid = NULL WHERE reviewcheck NOT IN ('file_perms', 'private_files');"
64 57

  
65 58
###### Performance
66 59
# Active cache
67
drush -yq vset cache 1
68
drush -yq vset block_cache 1
60
drush @"${site}" -yq vset cache 1
61
drush @"${site}" -yq vset block_cache 1
69 62
# Lifetime : 0, 60, 180, 300, 600, 900, 1800, 2700, 3600, 10800, 21600, 32400, 43200
70
drush -yq vset cache_lifetime 0
71
drush -yq vset page_cache_maximum_age 300
63
drush @"${site}" -yq vset cache_lifetime 0
64
drush @"${site}" -yq vset page_cache_maximum_age 300
72 65
# Compression
73
drush -yq vset page_compression 1
74
drush -yq vset preprocess_css 1
75
drush -yq vset preprocess_js 1
66
drush @"${site}" -yq vset page_compression 1
67
drush @"${site}" -yq vset preprocess_css 1
68
drush @"${site}" -yq vset preprocess_js 1
bin/scripts-utils.sh
42 42
    echo "$site_password"
43 43
}
44 44

  
45
count_d7_sites() {
46
    find "${d7_dir_sites}" -type d ! -name all -maxdepth 1 | wc -l
47
}
48

  
49 45
check_arguments() {
50 46
    # ARGS: number of arguments passed to script, number of arguments required, [help text]
51 47
    if [ "$1" -lt "$2"  ] ; then
......
116 112
    return 1
117 113
}
118 114

  
119
get_site_name_from_dir_name() {
120
    # ${1##*/} get the part after the last / ie default in /home/assos/drupal7/sites/default
121
    # $(tr '.' '\n' | tail -n 1) get the part after the last .
122
    # ie tvp in assos.centrale-marseille.fr.tvp
123
    echo ${1##*/} | tr '.' '\n' | tail -n 1
115
get_site_dir_from_name() {
116
    if [ "$1" = 'default' ]; then
117
	dir='default'
118
    else
119
	dir="assos.centrale-marseille.fr.$1"
120
    fi
121

  
122
    echo "${dir}"
123
}
124

  
125
get_absolute_site_dir_from_name() {
126
    dir=$(get_site_dir_from_name "$1")
127
    echo "${d7_dir_sites}/${dir}"
128
}
129

  
130
sites_list() {
131
    drush sa --format=csv --fields="name","uri" | awk '{FS=","; if ($2 != "") { print $1;}}' | sort
124 132
}
bin/usage.sh
41 41
. /home/assos/bin/scripts-utils.sh
42 42

  
43 43

  
44
if [ "${drupal_version}" = d7 ] ; then
45
    cd "${d7_dir_sites}"
46
else
47
    echo Unrecognize version.
44
if [ ! "${drupal_version}" = d7 ] ; then
45
    echo Unrecognize version. >&2
46
    exit 1
48 47
fi
49 48

  
50 49
number_found=0
51 50

  
52
for dir in $(find . -maxdepth 1 -mindepth 1 -type d ! -name all ! -name languages ! -name images | sort) ; do
51
for site in $(sites_list) ; do
53 52
    # List projects that correspond to the status.
54 53
    # Keep project_name if listed.
55 54
    # Count line result. 0 if not listed or 1 if listed.
56 55
    # Print site_dir if listed.
57 56

  
58
    cd "${dir}";
59
	if [ 1 -le $(drush pml --status="${project_status}" | grep "${project_name}" | wc -l) ] ; then
60
        echo "${dir}";
57
    if [ 1 -le $(drush @"${site}" pml --status="${project_status}" | grep "${project_name}" | wc -l) ] ; then
58
        echo "${site}";
61 59
        number_found=$((${number_found} + 1))
62 60
    fi
63 61
    cd -

Also available in: Unified diff