Projet

Général

Profil

Scripts et taches planifiees » Historique » Version 43

Florent Torregrosa, 04/08/2013 23:42
proposition de nouveau crontab

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