Projet

Général

Profil

Scripts et taches planifiees » Historique » Version 48

Julien Enselme, 05/08/2013 16:33
d7-all-update-contrib.sh : d7-all-dump-individual.sh flushes caches. No need for that here.

1 1 Julien Enselme
Afin de gagner du temps et d'éviter les erreurs humaines, des scripts ont été écrits tout au long du projet. Certains sont même exécutés automatiquement toutes les semaines.
2
3 13 Florent Torregrosa
{{>toc}}
4 1 Julien Enselme
5
h1. Les tâches planifiées
6
7 26 Florent Torregrosa
h2. Crontab
8
9 3 Julien Enselme
Pour exécuter ces tâches régulièrement, on utilise le "crontab":http://fr.wikipedia.org/wiki/Crontab. Il s'agit d'un programme installé sur notre serveur.
10 1 Julien Enselme
11 3 Julien Enselme
Pour voir et modifier la liste des actions :
12
# se connecter au serveur : <code>ssh assos@sas1.centrale-marseille</code>
13
# taper la commande pour voir le crontab <code>crontab -l</code>
14 47 Julien Enselme
# taper la commande pour modifier le crontab <code>crontab -e</code>.
15 1 Julien Enselme
16 47 Julien Enselme
{{important(Ne pas effectuer cette opération avant de s'être renseigné sur "vi":http://fr.wikipedia.org/wiki/Vi (l'éditeur de texte utilisé qui n'est pas vraiment intuitif :p) et sur "la syntaxe du crontab":http://fr.wikipedia.org/wiki/Crontab#Modification !
17
Les scripts doivent si possible s’exécuter avant le club Drupal pour que les problèmes éventuels y soient réglés)}}
18
19
{{tip(Pour utiliser un autre éditeur que vi taper : export EDITOR=editor_name exemple : vim, nano)}}
20 26 Florent Torregrosa
21
<pre>
22
<code class="php">
23 42 Florent Torregrosa
######## How to use
24
# mm hh jj MMM JJJ task
25
# minutes hour day_month month day_week
26
# for more informations : https://fr.wikipedia.org/wiki/Crontab#Notation
27
######## End how to
28
29 43 Florent Torregrosa
### Traqu-heure
30
43 6 * * * /users/guest/assos/bin/traqu_heure/script-restitution.sh > /dev/null 2>&1 
31
0 * * * *  /users/guest/assos/bin/traqu_heure/script-traque.sh > /dev/null 2>&1 
32 1 Julien Enselme
33
34 43 Florent Torregrosa
### Cleaning
35
00 22 * * * /users/guest/assos/bin/all-reset-permissions.sh > /dev/null 2>&1
36
00 23 * * * /users/guest/assos/bin/delete-temporary-files.sh > /dev/null 2>&1
37 1 Julien Enselme
38
39 43 Florent Torregrosa
### Databases
40
# Create backup
41
00 21 * * 1 /users/guest/assos/bin/d7-all-dump-full.sh > /dev/null 2>&1
42
00 23 * * 1 /users/guest/assos/bin/d7-all-dump-individual.sh auto > /dev/null 2>&1
43
00 1 * * 2  /users/guest/assos/bin/d6-all-dump-full.sh > /dev/null 2>&1
44 42 Florent Torregrosa
45 43 Florent Torregrosa
# flush backup
46
00 21 * * 2 /users/guest/assos/bin/flush-full-databases-backups.sh d7 > /dev/null 2>&1
47
00 22 * * 2 /users/guest/assos/bin/flush-full-databases-backups.sh d6 > /dev/null 2>&1
48
00 23 * * 2 /users/guest/assos/bin/flush-individual-databases-backups.sh auto d7 > /dev/null 2>&1
49
00 1 * * 3  /users/guest/assos/bin/flush-individual-databases-backups.sh manual d7 > /dev/null 2>&1
50 42 Florent Torregrosa
51
52 43 Florent Torregrosa
### Updates for drupal 7
53
00 22 * * 3 /users/guest/assos/bin/d7-all-update-contrib.sh | mail -s "d7-all-update-contrib.sh" assos
54
00 1 * * 3  /users/guest/assos/bin/d7-all-update-localidation.sh | mail -s "d7-all-update-localidation.sh" assos
55
00 3 * * 3  /users/guest/assos/bin/d7-all-reset-variables.sh > /dev/null 2>&1  
56 42 Florent Torregrosa
57 44 Florent Torregrosa
00 5 * * 3  /users/guest/assos/bin/d7-all-releases-info.sh | mail -s "d7-all-releases-info.sh" assos
58 43 Florent Torregrosa
00 23 * * 4 /users/guest/assos/bin/d7-all-security-review.sh
59 42 Florent Torregrosa
60
61 43 Florent Torregrosa
# Updates for drupal 6
62
00 22 * * 6 /users/guest/assos/bin/d6-all-update-contrib.sh > /dev/null 2>&1
63
00 23 * * 6 /users/guest/assos/bin/d6-all-reset-variables.sh > /dev/null 2>&1 
64 42 Florent Torregrosa
65 43 Florent Torregrosa
# Launch drush cron on fellowings
66
45 17 * * *     /users/guest/assos/bin/drushcronone assos.centrale-marseille.fr.ginfo > /dev/null 2>&1 
67
*/15 * * * *    /users/guest/assos/bin/drushcronone assos.centrale-marseille.fr.clubfinance > /dev/null 2>&1
68
45 3 * * *      /users/guest/assos/bin/drushcronone default > /dev/null 2>&1 
69
35 00 * * *     /users/guest/assos/bin/drushcronone assos.centrale-marseille.fr.cac13 > /dev/null 2>&1 
70
*/45 * * * *    /users/guest/assos/bin/drushcronone assos.centrale-marseille.fr.expat > /dev/null 2>&1 
71 1 Julien Enselme
*/10 * * * *    /users/guest/assos/bin/drushcronone forum.centrale-marseille.fr > /dev/null 2>&1 
72 44 Florent Torregrosa
73
00 22 * * 7 /users/guest/assos/bin/disk-usage.sh | mail -s "disk-usage.sh" assos
74 1 Julien Enselme
75
</code>
76 25 Florent Torregrosa
</pre>
77 1 Julien Enselme
78 25 Florent Torregrosa
Voici la liste des tâches effectuées régulièrement.
79 3 Julien Enselme
80 25 Florent Torregrosa
h2. La réinitialisation des variables
81
82 1 Julien Enselme
Cette tâche consiste à réinitialiser certaines variables qui donnent des droits considérés comme trop permissifs donc dangereux aux administrateurs des sites ou nécessaire pour d'autres scripts tels que piwik ou security_review.
83
84 25 Florent Torregrosa
En voici quelques exemples :
85 1 Julien Enselme
86
<pre>
87
<code class="bash">
88 25 Florent Torregrosa
drush -y vset error_level 0
89
</code>
90 1 Julien Enselme
</pre>
91 21 Florent Torregrosa
92 25 Florent Torregrosa
Cette commande permet de ne pas afficher les messages d'erreurs. En effet, ils contiennent parfois des informations sensibles sur l'installation et ne doivent donc pas être divulgués à n'importe qui.
93
94 3 Julien Enselme
<pre>
95 1 Julien Enselme
<code class="php">
96
drush -y vset --always-set reverse_proxy TRUE
97 25 Florent Torregrosa
drush -y vset --always-set --format=json reverse_proxy_addresses '["147.94.19.16","147.94.19.17"]'
98 1 Julien Enselme
</code>
99 3 Julien Enselme
</pre>
100 1 Julien Enselme
101 3 Julien Enselme
Ces commandes permettent de déclarer à Drupal les serveurs proxy du CRI afin d'éviter qu'il ne répertorie tous les visiteurs comme ayant l'adresse des serveurs sus-cités. **Pas fini : voir http://assos.centrale-marseille.fr/content/t%C3%A2che/d%C3%A9clarer-les-proxy-du-cri-%C3%A0-drupal**
102 1 Julien Enselme
103 6 Julien Enselme
h2. La sauvegarde des bases de données
104 1 Julien Enselme
105 3 Julien Enselme
Sur les installations d6 et d7 : une fois par semaine
106 1 Julien Enselme
107 3 Julien Enselme
On utilise les [[Scripts_et_taches_planifiees#Tout-sauvegarder|scripts de sauvegarde créés par le club Drupal]].
108 1 Julien Enselme
109 3 Julien Enselme
h2. La purge des sauvegardes de bdd
110 1 Julien Enselme
111
Sur les installations d6 et d7 : toutes les semaines
112
113
Cette tâche utilise le script de [[Scripts_et_taches_planifiees#purge_des_sauvegardes.sh|purge des sauvegardes]] afin de libérer de l'espace disque en supprimant les sauvegardes de bdd les plus vieilles.
114
115
h1. Liste des scripts à disposition
116 21 Florent Torregrosa
117
Les scripts utilisés sont hébergés dans le répertoire bin du compte assos.
118
119
h2. all-reset-permissions.sh
120
121
<pre>
122
<code class="php">
123
#!/bin/sh
124
125
. scripts-config.sh
126
127
# This script puts the correct permissions to sites folders, settings.php and scripts.
128
129
######### drupal 6
130
for dir in `find $d6_dir_sites -type d -maxdepth 1 -mindepth 1 ! -name all ! -name images ! -name languages` ; do
131
    chmod 755 $dir
132
    chmod 400 $dir/settings.php
133
done
134
135
######### drupal 7
136
for dir in `find $d7_dir_sites -type d -maxdepth 1 -mindepth 1 ! -name all` ; do
137
    chmod 755 $dir
138
    chmod 400 $dir/settings.php
139 35 Florent Torregrosa
done
140
141
####### bin
142
chmod -R 700 $dir_scripts
143
144
####### backup
145 21 Florent Torregrosa
chmod -R 700 $dir_backup
146
147
####### log
148 1 Julien Enselme
chmod -R 700 $dir_log
149 21 Florent Torregrosa
</code>
150
</pre>
151
152
h2. contrib-usage.sh
153
154
<pre>
155
<code class="php">
156
#!/bin/sh
157
158
. scripts-config.sh
159 29 Florent Torregrosa
. scripts-utils.sh
160 21 Florent Torregrosa
161
# ARGS: Drupal_version, project_status, project_name
162
# List sites that have the project_name with the corresponding project_status.
163
# project status: enabled or disabled
164
165
check_arguments $# 3
166
167
if [ $1 = d6 ] ; then
168
    cd $d6_dir_sites
169 41 Florent Torregrosa
else
170 21 Florent Torregrosa
    cd $d7_dir_sites
171
fi
172
173
for dir in `find . -maxdepth 1 -mindepth 1 -type d ! -name all ! -name languages ! -name images | sort ` ; do
174
    # List non-core projects that correspond to the status.
175
    # Keep project_name if listed.
176
    # Count line result. 0 if not listed or 1 if listed.
177
	# Print site_dir if listed.
178
179 29 Florent Torregrosa
    cd $dir;
180 21 Florent Torregrosa
	if [ 1 -eq `drush pml --no-core --status=$2 | grep $3 | wc -l` ] ; then
181
        echo $dir; 
182
    fi
183
    cd -
184 1 Julien Enselme
done
185 21 Florent Torregrosa
</code>
186
</pre>
187
188
h2. d6-all-drush.sh
189
190
<pre>
191
<code class="php">
192
#!/bin/sh
193
194
. scripts-config.sh
195
. scripts-utils.sh
196
197 41 Florent Torregrosa
# ARGS: drush_command
198 21 Florent Torregrosa
199
check_arguments $# 1
200
201
for dir in `find $d6_dir_sites -maxdepth 1 -mindepth 1 -type d ! -name all ! -name languages ! -name images | sort` ; do
202
    cd $dir
203
    echo $dir
204
    drush $*
205 1 Julien Enselme
done
206 21 Florent Torregrosa
</code>
207
</pre>
208
209
h2. d6-all-dump-full.sh
210
211
<pre>
212
<code class="php">
213
#!/bin/sh
214
215
. scripts-config.sh
216
217
current_date=`date "+%Y-%m-%d-%Hh%Mm%Ss"`
218
219
# Dump D6 database with webassos user.
220 45 Florent Torregrosa
mysqldump --single-transaction webassos -h myweb.serv.int -u webassos --password=password > $d6_dir_full_backup/webassos/$current_date.webassos.sql
221 21 Florent Torregrosa
222
# Dump D6 form database with forum user.
223 45 Florent Torregrosa
mysqldump forum -h myweb.serv.int -u forum --password=password > $d6_dir_full_backup/forum/$current_date.forum.sql
224 37 Florent Torregrosa
</code>
225
</pre>
226
227
h2. d6-all-reset-variables.sh
228
229
<pre>
230
<code class="php">
231
#!/bin/sh
232
233
. scripts-config.sh
234 41 Florent Torregrosa
235 37 Florent Torregrosa
cd $d6_dir_sites
236
d6-all-drush.sh vset --always-set reverse_proxy TRUE
237 39 Florent Torregrosa
d6-all-drush.sh vset --always-set --format=json reverse_proxy_addresses '["147.94.19.16","147.94.19.17"]'
238 1 Julien Enselme
drush @sites -y ev "variable_set('update_notify_emails', array('@email_multi_assos'));"
239 21 Florent Torregrosa
</code>
240
</pre>
241
242
h2. d6-all-update-contrib.sh
243
244
<pre>
245
<code class="php">
246
#!/bin/sh
247
248
. scripts-config.sh
249
250
d6-all-drush.sh -y en update
251
# Launch cron to check for updates.
252
d6-all-drush.sh -q cron
253
254
d6-all-drush.sh cc all
255
d6-all-dump-full.sh
256
257
d6-all-drush.sh -y upc --no-core
258
d6-all-drush.sh -y updb
259
260
d6-all-drush.sh -y dis update
261
262 1 Julien Enselme
d6-all-drush.sh cron
263 21 Florent Torregrosa
</code>
264
</pre>
265
266
h2. d6-dump-individual.sh
267
268
<pre>
269 1 Julien Enselme
<code class="php">
270
#!/bin/sh
271
272
. scripts-config.sh
273
274
# ARGS: auto or manual, site_prefix
275 41 Florent Torregrosa
# WARNING : backup are regularly flushed, put your backup in a safe place.
276
277
cd $dir_individual_backup
278
279
#!/bin/sh
280
281
. scripts-config.sh
282
283
# ARGS: auto or manual, site_prefix
284 21 Florent Torregrosa
# WARNING : backup are regularly flushed, put your backup in a safe place.
285
286
cd $dir_individual_backup
287
288
#récupération des tables du site dans le fichier liste_tables.temp
289 1 Julien Enselme
tables='_%'
290
liste="$1$tables"
291
292
mysql -h myweb.serv.int -u webassos --password=HBVH2ljgyZCA0AP251DY -BNe "show tables like '"$liste"'" webassos | tr '\r\n' ' ' > liste_tables.temp
293 21 Florent Torregrosa
294 1 Julien Enselme
#transformation de cette liste en une variable
295 21 Florent Torregrosa
var=$(cat liste_tables.temp)
296
297
#sauvegarde de toutes ces tables
298
current_date=`date "+%Y-%m-%d-%Hh%Mm%Ss"`
299 41 Florent Torregrosa
suffixe="_dump$current_date.sql"
300
fichier="$1$suffixe"
301
302
if [ $1 = 'auto' ] ; then
303 21 Florent Torregrosa
    mysqldump webassos -h myweb.serv.int -u webassos --password=HBVH2ljgyZCA0AP251DY $var > $d6_dir_individual_auto_backup/$fichier
304
else
305
    mysqldump webassos -h myweb.serv.int -u webassos --password=HBVH2ljgyZCA0AP251DY $var > $d6_dir_individual_manual_backup/$fichier
306
fi
307
308 1 Julien Enselme
#suppression du fichier temporaire utilisé
309 21 Florent Torregrosa
rm liste_tables.temp
310
</code>
311
</pre>
312
313 1 Julien Enselme
h2. d7-all-drush-logged.sh
314 21 Florent Torregrosa
315
<pre>
316
<code class="php">
317
#!/bin/sh
318
319
. scripts-config.sh
320
. scripts-utils.sh
321
322 30 Florent Torregrosa
# ARGS: drush_command
323
324 41 Florent Torregrosa
check_arguments $# 1
325 1 Julien Enselme
326
cd $d7_dir_sites
327 30 Florent Torregrosa
328
for dir in `find . -maxdepth 1 -mindepth 1 -type d ! -name all | sort` ; do
329
    cd $dir
330 21 Florent Torregrosa
    current_date=`date "+%Y-%m-%d_%Hh:%Mm"`
331 30 Florent Torregrosa
    echo "======$current_date======" >> $d7_dir_log/$dir.log
332
    echo "Arguments are: $* " >> $d7_dir_log/$dir.log
333 21 Florent Torregrosa
    drush $* >> $d7_dir_log/$dir.log
334
    #To have the same caracters limit we needed 'end' that have 4 caracters, we used the Croate language for this ! LOL 
335
    echo -e "=============KRAJ=============\n" >> $d7_dir_log/$dir.log
336 1 Julien Enselme
    cd -
337 21 Florent Torregrosa
done
338 1 Julien Enselme
</code>
339 21 Florent Torregrosa
</pre>
340
341
h2. d7-all-drush.sh
342
343
<pre>
344
<code class="php">
345
#!/bin/sh
346
347
. scripts-config.sh
348
. scripts-utils.sh
349
350 41 Florent Torregrosa
# ARGS: drush_command
351 21 Florent Torregrosa
352
check_arguments $# 1
353
354
for dir in `find $d7_dir_sites -maxdepth 1 -mindepth 1 -type d ! -name all | sort` ; do
355
    cd $dir
356
    echo $dir
357
    drush $*
358 1 Julien Enselme
done
359 21 Florent Torregrosa
</code>
360
</pre>
361
362
h2. d7-all-dump-full.sh
363
364
<pre>
365
<code class="php">
366
#!/bin/sh
367
368
. scripts-config.sh
369
370
current_date=`date "+%Y-%m-%d-%Hh%Mm%Ss"`
371
372
# Dump D7 databases at once.
373 45 Florent Torregrosa
mysqldump -h $db_server -u $db_user -ppassword --all-databases > $d7_dir_full_backup/myassos/$current_date.d7_full.sql
374 21 Florent Torregrosa
</code>
375
</pre>
376
377
h2. d7-all-dump-individual.sh
378
379
<pre>
380
<code class="php">
381
#!/bin/sh
382
383
. scripts-config.sh
384
385 34 Florent Torregrosa
# ARGS: auto or manual
386
387
current_date=`date "+%Y-%m-%d-%Hh%Mm%Ss"`
388 21 Florent Torregrosa
389
cd $d7_dir_sites
390
391
for dir in `find . -maxdepth 1 -mindepth 1 -type d ! -name all | cut -c3-` ; do
392
    cd $dir
393 40 Florent Torregrosa
    drush cc all
394 1 Julien Enselme
    if [ $1 = 'auto' ] ; then
395 34 Florent Torregrosa
        drush sql-dump --result-file="$d7_dir_individual_auto_backup/$dir/$current_date.$dir.sql"
396 21 Florent Torregrosa
    else
397
        drush sql-dump --result-file="$d7_dir_individual_manual_backup/$dir/$current_date.$dir.sql"
398
    fi
399
    cd -
400 1 Julien Enselme
done
401 21 Florent Torregrosa
</code>
402
</pre>
403
404
h2. d7-all-releases-info.sh
405
406
<pre>
407
<code class="php">
408
#!/bin/sh
409
410
. scripts-config.sh
411
412 28 Florent Torregrosa
# List version of a module or theme that exists in sites/all/*
413
# and all versions that are available for same project on drupal.org
414
415
# modules
416
cd $d7_dir_sites/all/modules
417 1 Julien Enselme
for dir in `ls -1` ; do
418
    if [ -d $dir ] ; then
419 28 Florent Torregrosa
        drush pm-releases $dir
420
    fi
421
done
422
423
# themes
424 1 Julien Enselme
cd $d7_dir_sites/all/themes
425 21 Florent Torregrosa
for dir in `ls -1` ; do
426
    if [ -d $dir ] ; then
427
        drush pm-releases $dir
428
    fi
429 1 Julien Enselme
done
430 21 Florent Torregrosa
</code>
431
</pre>
432
433
h2. d7-all-reset-variables.sh
434
435
<pre>
436
<code class="php">
437 41 Florent Torregrosa
#!/bin/sh
438 21 Florent Torregrosa
439
. scripts-config.sh
440
441
for dir in `find $d7_dir_sites -maxdepth 1 -mindepth 1 -type d ! -name all | sort` ; do
442
    cd $dir
443
    echo $dir
444
    d7-reset-variables.sh
445 1 Julien Enselme
done
446 21 Florent Torregrosa
</code>
447
</pre>
448
449
h2. d7-all-security-review.sh
450
451
<pre>
452
<code class="php">
453
#!/bin/sh
454
455
. scripts-config.sh
456
457
# grep -v success to keep site_name and error lines.
458 1 Julien Enselme
bash -c 'd7-all-drush.sh security-review |& grep -v success | mail -s "Security review" $email_multi_assos'
459 21 Florent Torregrosa
</code>
460
</pre>
461
462
h2. d7-all-update-contrib.sh
463 1 Julien Enselme
464 21 Florent Torregrosa
<pre>
465
<code class="php">
466
#!/bin/sh
467
468
. scripts-config.sh
469
470
d7-all-drush.sh -y en update
471
# Launch cron to check for updates.
472
d7-all-drush.sh -q cron
473
474
d7-all-dump-individual.sh
475
476
d7-all-drush-logged.sh -y upc --no-core
477 41 Florent Torregrosa
d7-all-drush.sh -y updb
478 21 Florent Torregrosa
479
d7-all-drush.sh -y dis update
480
481 1 Julien Enselme
d7-all-drush.sh cron
482 21 Florent Torregrosa
</code>
483
</pre>
484
485
h2. d7-all-update-localisation.sh
486
487
<pre>
488
<code class="php">
489
#!/bin/sh
490
491
. scripts-config.sh
492
493
d7-all-drush.sh -y en l10n_update
494
d7-all-drush.sh l10n-update-refresh
495
d7-all-drush.sh l10n-update
496 1 Julien Enselme
d7-all-drush.sh -y dis l10n_update
497 21 Florent Torregrosa
</code>
498
</pre>
499
500
h2. d7-create-site.sh
501
502 1 Julien Enselme
<pre>
503 21 Florent Torregrosa
<code class="php">
504
#!/bin/sh
505
506
. scripts-config.sh
507
. scripts-config-site.sh $1
508
. scripts-utils.sh
509
510
# ARGS: site name
511
512 31 Julien Enselme
######## Exceptions
513 21 Florent Torregrosa
check_arguments $# 1
514
515
# "-" is forbidden because it provokes database error.
516
if [ `echo $1 | grep -` ] ; then
517
    echo '"-" is forbidden in the site name'
518 41 Florent Torregrosa
    exit 1
519 21 Florent Torregrosa
fi
520
521
# Site name length must be lower or equal to 16 due to database limitations.
522
if [`echo $1 | wc -c` -gt 16 ] ; then
523
    echo "site name can't have more than 16 characters"
524
    exit 1
525
fi
526 31 Julien Enselme
527 21 Florent Torregrosa
###### Initialisation
528
cd $d7_dir
529
db_password=`ask_password_db $db_server $db_user`
530
site_password=`generate_password`
531
532
# Check if site database already exists.
533
if mysql -h $db_server -u $db_user -e "USE $d7_site_name" -p$db_password 2>/dev/null ; then
534
    echo "Database $d7_site_name already exists"
535
    exit 1
536
fi
537
538
# Check if site folder already exists.
539 1 Julien Enselme
if [ -d $d7_site_dir ] ; then
540 21 Florent Torregrosa
    echo "Folder $d7_site_dir already exists"
541 1 Julien Enselme
    exit 1
542 31 Julien Enselme
fi
543 1 Julien Enselme
544
###### Main
545 31 Julien Enselme
mkdir $d7_site_dir
546
dir_site_name="assos.centrale-marseille.fr.$d7_site_name"
547 21 Florent Torregrosa
548
# Backup requirements
549 31 Julien Enselme
mkdir $d7_dir_individual_auto_backup/$dir_site_name
550
mkdir $d7_dir_individual_manual_backup/$dir_site_name
551
current_date=`date "+%Y-%m-%d-%Hh%Mm%Ss"`
552
553 21 Florent Torregrosa
# NB : ls sort by considering the 1st characters
554
touch $d7_dir_individual_auto_backup/$dir_site_name/$current_date.$dir_site_name.sql
555
touch $d7_dir_individual_auto_backup/$dir_site_name/$current_date.$dir_site_name.sql2
556
touch $d7_dir_individual_auto_backup/$dir_site_name/$current_date.$dir_site_name.sql3
557
558
# Create and grant privileges on database
559
mysql -h $db_server -u $db_user -e "CREATE DATABASE $d7_site_name" -p$db_password
560
mysql -h $db_server -u $db_user -e "GRANT ALL PRIVILEGES ON $d7_site_name.* TO '$d7_site_name'@'%' IDENTIFIED BY '$site_password'" -p$db_password
561
562
# Create settings.php
563
sed "s/\%\%DBUSER\%\%/$d7_site_name/ ; s/\%\%DBNAME\%\%/$d7_site_name/ ; s/\%\%DBPASS\%\%/$site_password/ ; s/\%\%nomsite\%\%/$d7_site_name/" < $d7_settings_template > $d7_site_settings
564
565
# Create symbolic link
566
cd $d7_dir
567
ln -s . $d7_site_name
568
569
# Next Instructions
570
echo "Go to http://assos.centrale-marseille.fr/$d7_site_name/install.php to continue."
571
echo "Press enter when ready to go on."
572
read key
573
574
# Init variables
575
d7-reset-variables.sh $d7_site_name
576
577
# Permissions
578
chmod -R 755 $d7_site_dir
579
chmod 400 $d7_site_settings
580
581
# Last instructions
582
echo "Last instructions:"
583
echo "- Advice the webmaster to close account creation on the website"
584
echo "- Give the webmaster a link to the club Drupal's tutorials "
585
echo "- Create a node of type \"Site\" on default"
586 1 Julien Enselme
echo "- Register the webmaster on webmasters@listes.centrale-marseille.fr"
587 21 Florent Torregrosa
</code>
588
</pre>
589
590
h2. d7-delete-site.sh
591
592
<pre>
593
<code class="php">
594
#!/bin/sh
595
596
. scripts-config.sh
597
. scripts-config-site.sh $1
598
. scripts-utils.sh
599
600
# ARGS: site name.
601
602
check_arguments $# 1
603 38 Julien Enselme
604 21 Florent Torregrosa
db_password=`ask_password_db $db_server $db_user`
605
606
# Delete database.
607
mysql -h $db_server -u $db_user -p$db_password -e "DROP DATABASE $d7_site_name"
608
609
# Delete MYSQL user.
610
mysql -h $db_server -u $db_user -p$db_password -e "DROP USER '$d7_site_name'@'%'"
611
612
# Delete site's folder.
613
chmod -R 700 $d7_site_dir
614
rm -r $d7_site_dir
615
616
# Delete symbolic link.
617
rm $d7_dir/$d7_site_name
618
619
# Delete database backups.
620
rm -r $d7_dir_individual_auto_backup/assos.centrale-marseille.fr.$d7_site_name
621
rm -r $d7_dir_individual_manual_backup/assos.centrale-marseille.fr.$d7_site_name
622
623
echo "Don't forget to:"
624 1 Julien Enselme
echo "- Refresh node site on default"
625 21 Florent Torregrosa
echo "- Check particular behavior (normally detailed on site node)"
626
</code>
627
</pre>
628 1 Julien Enselme
629 21 Florent Torregrosa
h2. d7-reset-variables.sh
630 1 Julien Enselme
631 21 Florent Torregrosa
<pre>
632
<code class="php">
633
#!/bin/sh
634
635
. scripts-config.sh
636
637
# ARGS: [site_name]
638
639
if [ ! -z $1 ] ; then
640
    . scripts-config-site.sh $1
641
    cd $d7_site_dir
642
fi
643
644
current_timestamp=`date "+%s"`
645 41 Florent Torregrosa
646 46 Florent Torregrosa
random_1=`dd if=/dev/urandom count=1 2> /dev/null | cksum | cut -f1 -d" "`
647
random_2=`dd if=/dev/urandom count=1 2> /dev/null | cksum | cut -f1 -d" "`
648
649 21 Florent Torregrosa
####### General variables
650 41 Florent Torregrosa
drush -y vset --always-set reverse_proxy TRUE
651 21 Florent Torregrosa
drush -y vset --always-set --format=json reverse_proxy_addresses '["147.94.19.16","147.94.19.17"]'
652
drush -y ev "variable_set('update_notify_emails', array('@email_multi_assos'));"
653
drush -y vset error_level 0
654
drush -y vset dblog_row_limit 1000
655
656
###### Hidden captcha
657
drush -y en hidden_captcha
658
# Log wrong answers.
659
drush -y vset captcha_log_wrong_responses 1
660
# Use hidden captcha for all forms.
661 1 Julien Enselme
drush -y sqlq --db-prefix "UPDATE {captcha_points} SET module = 'hidden_captcha', captcha_type = 'Hidden CAPTCHA' WHERE module is NULL;"
662
# Flush captcha cache.
663 21 Florent Torregrosa
drush -y vdel captcha_placement_map_cache
664 1 Julien Enselme
# Randomely generate a math question as the label of the hidden captcha field.
665 46 Florent Torregrosa
drush -y vset hidden_captcha_label "$random_1 + $random_2"
666 1 Julien Enselme
667
668 21 Florent Torregrosa
####### Piwik
669
drush -y en piwik
670
drush -y vset piwik_site_id "101"
671
drush -y vset piwik_url_http "http://piwik.centrale-marseille.fr/"
672
drush -y vset piwik_url_https "https://piwik.centrale-marseille.fr/"
673 32 Julien Enselme
# Piwik cache.
674 33 Julien Enselme
drush -y vset piwik_cache 1
675 21 Florent Torregrosa
drush -y vset piwik_visibility_roles "1"
676
# Piwik is enable for everyone except the administrator
677
drush -y vset --format=json piwik_roles '[3]'
678
drush -y vset piwik_page_title_hierarchy 1
679
# Activate local search.
680
drush -y vset piwik_site_search 1
681 41 Florent Torregrosa
682
683
###### Security review
684 21 Florent Torregrosa
# For untrusted roles:
685
# 1: anonymous user
686
# 2: authenticated user
687 41 Florent Torregrosa
# 3: administrator
688
drush -y en security_review
689
drush -y ev "variable_set('security_review_untrusted_roles', array('1'));"
690 21 Florent Torregrosa
# Security review can't check for files permissions on multi_assos.
691
# TODO: the database scheme does'nt exist until security_review is run for the first time. Even with the scheme there are sql error.
692
# drush -y sqlq "UPDATE {security_review} SET skip = '1', skiptime = $current_timestamp, skipuid = '1' WHERE reviewcheck IN ('file_perms');"
693 1 Julien Enselme
# drush -y sqlq "UPDATE {security_review} SET skip = '0', skiptime = '0', skipuid = NULL WHERE reviewcheck NOT IN ('file_perms');"
694 21 Florent Torregrosa
</code>
695
</pre>
696
697
h2. delete-temporary-files.sh
698
699
<pre>
700
<code class="php">
701
#!/bin/sh
702
703
. scripts-config.sh
704
705 1 Julien Enselme
find $dir_multi_assos -name '*~' -delete
706 21 Florent Torregrosa
</code>
707
</pre>
708
709
h2. disk-usage.sh
710
711
<pre>
712
<code class="php">
713
#!/bin/sh
714
715
. scripts-config.sh
716
717 1 Julien Enselme
echo -e "Quotas: 9.1 GB\n"
718
719
echo "Assos:"
720
du -hcs $dir_multi_assos | grep total
721
echo -e "\n"
722
723
echo "D6:"
724
cd $d6_dir_sites
725
du -h -d 1
726
echo -e "\n"
727
728
echo "D7:"
729
cd $d7_dir_sites
730
du -h -d 1
731
echo -e "\n"
732
733
echo "Logs:"
734
du -hcs $dir_log | grep total
735
echo -e "\n"
736 21 Florent Torregrosa
737
echo "Backups:"
738
cd $dir_backup
739 41 Florent Torregrosa
du -h -d 2
740
</code>
741
</pre>
742
743
h2. drushcronone
744
745
<pre>
746
<code class="php">
747
#!/bin/sh
748
749
. scripts-config.sh
750
751
if [ $# -lt 1 ]; then
752
  echo "usage: $0 <site's folder name>"
753
  exit 1
754
fi
755
756
cd "$d6_sites_dir/$*"
757
pwd;
758 1 Julien Enselme
drush cron;
759 21 Florent Torregrosa
</code>
760
</pre>
761
762
h2. flush-files.sh
763
764
<pre>
765
<code class="php">
766
#!/bin/sh
767
768
# ARGS: number of files to keep, email address
769
# usage: flush files from a folder except a number equal to argument.
770
771
# Check if scripts-config.sh is imported.
772
if [ -z $scripts_utils ] ; then
773
    echo "Import of scripts-utils.sh required."
774
    exit 1
775
fi
776
777
check_arguments $# 2
778
779
backups_number=`ls | wc -l`
780 1 Julien Enselme
let "number_of_backups_to_delete = backups_number - $1"
781 21 Florent Torregrosa
782
if [ $number_of_backups_to_delete -gt 0 ] ; then
783
    ls | head -$number_of_backups_to_delete | xargs rm
784
else
785
    dir=`pwd`
786
    echo "There are not enough files in $dir to Flush it. Check if backup script works fine." | mail -s "[db] $dir has a backup problem" $2
787
fi
788 1 Julien Enselme
</code>
789 21 Florent Torregrosa
</pre>
790
791
h2. flush-full-databases-backups.sh
792
793
<pre>
794
<code class="php">
795
#!/bin/sh
796
797
. scripts-config.sh
798
799
# ARGS: Drupal version
800
801
cd $dir_full_backup/$1
802 41 Florent Torregrosa
803 21 Florent Torregrosa
for dir in `ls` ; do
804 1 Julien Enselme
    cd $dir
805 21 Florent Torregrosa
    flush-files.sh $db_full_backup_number $email_multi_assos
806
    cd -
807
done
808 1 Julien Enselme
</code>
809 21 Florent Torregrosa
</pre>
810
811
h2. flush-individual-databases-backups.sh
812
813
<pre>
814
<code class="php">
815
#!/bin/sh
816
817
. scripts-config.sh
818
819
# ARGS: manual or auto, Drupal version
820
821
cd $dir_individual_backup/$1/$2
822
823
for dir in `ls` ; do
824
    cd $dir
825
    if [ $1 = 'auto' ] ; then
826 41 Florent Torregrosa
        flush-files.sh $db_individual_auto_backup_number $email_multi_assos
827 21 Florent Torregrosa
    else
828
        flush-files.sh $db_individual_manual_backup_number $email_multi_assos
829
    fi
830 1 Julien Enselme
    cd -
831 21 Florent Torregrosa
done
832
</code>
833
</pre>
834
835
h2. scripts-config-site.sh
836
837
<pre>
838
<code class="php">
839
#!/bin/sh
840
841
# Sets useful variables of a site.
842
# ARGS: site_name
843
# Requires scripts-config.sh
844
845
# Check if scripts-config.sh is imported.
846
if [ -z $scripts_config ] ; then
847
    echo "Import of scripts-config.sh required."
848
    exit 1
849
fi
850
851
if [ -z $1 ] ; then
852 1 Julien Enselme
    echo "This script needs a site name as argument."
853 21 Florent Torregrosa
    exit 1
854
fi
855
856
scripts_config_site='imported'
857
858
d7_site_name=$1
859
d7_site_dir="$d7_dir_sites/assos.centrale-marseille.fr.$d7_site_name"
860 1 Julien Enselme
d7_site_settings="$d7_site_dir/settings.php"
861 21 Florent Torregrosa
</code>
862
</pre>
863
864
h2. scripts-config.sh
865
866
<pre>
867
<code class="php">
868
#!/bin/sh
869
870
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/local/bin:/users/guest/assos/bin
871
PATH=$PATH:/usr/guest/assos/bin
872
873
scripts_config='imported'
874
875 41 Florent Torregrosa
email_multi_assos="assos@centrale-marseille.fr"
876 21 Florent Torregrosa
877
dir_multi_assos='/users/guest/assos'
878
dir_scripts="$dir_multi_assos/bin"
879
dir_template="$dir_multi_assos/template"
880
881
###### Database
882
db_server="myassos.serv.int"
883
db_user="assos"
884
dir_log="$dir_multi_assos/log"
885
886
###### Backup
887
db_full_backup_number=3
888
db_individual_manual_backup_number=3
889
db_individual_auto_backup_number=3
890
891
dir_backup="$dir_multi_assos/backup"
892
dir_full_backup="$dir_backup/full"
893
dir_individual_backup="$dir_backup/individual"
894
dir_individual_manual_backup="$dir_individual_backup/manual"
895
dir_individual_auto_backup="$dir_individual_backup/auto"
896
897
898
###### D7 variables
899
d7_dir="$dir_multi_assos/htmltest"
900
d7_dir_sites="$d7_dir/sites"
901
902
### Log
903
d7_dir_log="$dir_log/d7"
904
905
### Backup
906
d7_dir_full_backup="$dir_full_backup/d7"
907
d7_dir_individual_manual_backup="$dir_individual_manual_backup/d7"
908
d7_dir_individual_auto_backup="$dir_individual_auto_backup/d7"
909
910
### Template
911
d7_settings_template_name="settings-D7-bddinde-template.php"
912
d7_settings_template="$dir_template/$d7_settings_template_name"
913
914
915
###### D6 variables
916
d6_dir="$dir_multi_assos/html"
917 1 Julien Enselme
d6_dir_sites="$d6_dir/sites"
918 21 Florent Torregrosa
919
### Backup
920
d6_dir_full_backup="$dir_full_backup/d6"
921 1 Julien Enselme
d6_dir_individual_manual_backup="$dir_individual_manual_backup/d6"
922
d6_dir_individual_auto_backup="$dir_individual_auto_backup/d6"
923 21 Florent Torregrosa
</code>
924
</pre>
925
926
h2. scripts-utils.sh
927
928
<pre>
929
<code class="php">
930
#!/bin/sh
931 1 Julien Enselme
932 21 Florent Torregrosa
# This script contains useful functions for other scripts.
933
934
# Check if scripts-config.sh is imported.
935
if [ -z $scripts_config ] ; then
936
    echo "Import of scripts-config.sh required."
937
    exit 1
938
fi
939
940
scripts_utils='imported'
941
942
ask_password() {
943
    # read -s doesn't work with sh.
944 1 Julien Enselme
    # usage: pass=`ask_password "password please:"`
945 41 Florent Torregrosa
    echo $1 >&2
946 21 Florent Torregrosa
    echo -n ">" >&2
947 41 Florent Torregrosa
    stty_avant=`stty -g`
948
    stty -echo
949 21 Florent Torregrosa
    read password
950
    stty $stty_avant
951
    echo "$password"
952
    unset password
953
}
954
955
ask_password_db() {
956
    # ARGS: server_name, user_name
957 1 Julien Enselme
    local db_password="pour_boucler"
958 41 Florent Torregrosa
    # empty db request to validate password
959 21 Florent Torregrosa
    while ! mysql -h $1 -u $2 -p$db_password -e "" 2>/dev/null ; do
960
        db_password=`ask_password "database password:"`
961
    done
962
    echo $db_password
963
}
964
965
generate_password(){
966
    # ARGS: [password_length]
967
    # The password contains special characters. '/' must be excluded to avoid sed malfunction.
968
969
    local site_password='/'
970
971
    if [ -z $1 ] ; then
972 41 Florent Torregrosa
        local password_length=20
973 21 Florent Torregrosa
    else
974
        local password_length=$1
975
    fi
976
977
    while echo "$site_password" | grep -Fq '/' ; do
978
        site_password=`dd if=/dev/urandom count=1 | uuencode -m - | head -n 2 | tail -n 1 | cut -c-$password_length`
979
    done
980
981
    echo $site_password
982
}
983
984
count_d7_sites(){
985
    find $d7_dir_sites -type d ! -name all -maxdepth 1 | wc -l
986 41 Florent Torregrosa
}
987 21 Florent Torregrosa
988
check_arguments() {
989
    # ARGS: number of arguments passed to script, number of arguments required
990 11 Julien Enselme
    if [ $1 -lt $2  ] ; then
991
        echo "Number of arguments insuffisant."
992 1 Julien Enselme
        exit 1
993
    fi
994
}
995
</code>
996
</pre>