Projet

Général

Profil

Scripts et taches planifiees » Historique » Version 59

Florent Torregrosa, 05/08/2013 17:56
code after test of d7-all-security-review.sh

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