Projet

Général

Profil

Scripts et taches planifiees » Historique » Version 45

Florent Torregrosa, 05/08/2013 11:48
remove password

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