Scripts et taches planifiees » Historique » Version 99
Julien Enselme, 22/10/2013 00:15
d7-delete-site.sh: Prise en compte sites.php
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 | 69 | Julien Enselme | {{tip( |
20 | * Pour utiliser un autre éditeur que vi taper : export EDITOR=editor_name exemple : vim, nano. |
||
21 | 74 | Florent Torregrosa | )}} |
22 | |||
23 | {{important( |
||
24 | * d7-all-update-contrib.sh fait des sauvegardes automatiques individuelles pour les sites Drupal 7 en faisant appel à d7-all-dump-indiviual.sh auto |
||
25 | * C'est pour cela que d7-all-dump-individual.sh auto n'est pas appelé dans le crontab. |
||
26 | )}} |
||
27 | 26 | Florent Torregrosa | |
28 | <pre> |
||
29 | <code class="php"> |
||
30 | 42 | Florent Torregrosa | ######## How to use |
31 | # mm hh jj MMM JJJ task |
||
32 | # minutes hour day_month month day_week |
||
33 | # for more informations : https://fr.wikipedia.org/wiki/Crontab#Notation |
||
34 | ######## End how to |
||
35 | |||
36 | 1 | Julien Enselme | |
37 | ### Cleaning |
||
38 | 91 | Julien Enselme | 00 5 * * * /users/guest/assos/bin/all-reset-permissions.sh > /dev/null |
39 | 00 6 * * * /users/guest/assos/bin/delete-temporary-files.sh > /dev/null |
||
40 | 1 | Julien Enselme | |
41 | |||
42 | 67 | Julien Enselme | ### Traqu-heure |
43 | 91 | Julien Enselme | 00 7 * * * /users/guest/assos/bin/traqu_heure/script-restitution.sh > /dev/null |
44 | 0 * * * * /users/guest/assos/bin/traqu_heure/script-traque.sh > /dev/null |
||
45 | 1 | Julien Enselme | |
46 | |||
47 | 91 | Julien Enselme | ### Drupal 7 cron |
48 | 93 | Julien Enselme | 00 * * * * /users/guest/assos/bin/d7-all-drush.sh -q cron > /dev/null |
49 | 91 | Julien Enselme | |
50 | |||
51 | 68 | Florent Torregrosa | ### Databases |
52 | 43 | Florent Torregrosa | # Create backup |
53 | 91 | Julien Enselme | 00 8 1,15 * * /users/guest/assos/bin/d7-all-dump-full.sh > /dev/null |
54 | 00 1 * * 2 /users/guest/assos/bin/d6-all-dump-full.sh > /dev/null |
||
55 | 67 | Julien Enselme | |
56 | 68 | Florent Torregrosa | # flush backup |
57 | 91 | Julien Enselme | 00 8 2,16 * * /users/guest/assos/bin/flush-full-databases-backups.sh d7 > /dev/null |
58 | 00 22 * * 2 /users/guest/assos/bin/flush-full-databases-backups.sh d6 > /dev/null |
||
59 | 00 23 * * 2 /users/guest/assos/bin/flush-individual-databases-backups.sh auto d7 > /dev/null |
||
60 | 00 1 * * 3 /users/guest/assos/bin/flush-individual-databases-backups.sh manual d7 > /dev/null |
||
61 | 1 | Julien Enselme | |
62 | |||
63 | 68 | Florent Torregrosa | ### Drupal 7 |
64 | 91 | Julien Enselme | 00 3 * * 4 /users/guest/assos/bin/d7-all-reset-variables.sh > /dev/null |
65 | 42 | Florent Torregrosa | 00 22 * * 3 /users/guest/assos/bin/d7-all-update-contrib.sh | mail -s "d7-all-update-contrib.sh" assos |
66 | 67 | Julien Enselme | 00 1 * * 4 /users/guest/assos/bin/d7-all-update-localisation.sh | mail -s "d7-all-update-localisation.sh" assos |
67 | 43 | Florent Torregrosa | 00 2 * * 4 /users/guest/assos/bin/d7-all-security-review.sh |
68 | 67 | Julien Enselme | 00 4 * * 4 /users/guest/assos/bin/d7-all-releases-info.sh | mail -s "d7-all-releases-info.sh" assos |
69 | 42 | Florent Torregrosa | |
70 | 43 | Florent Torregrosa | |
71 | 67 | Julien Enselme | ### Drupal 6 |
72 | 91 | Julien Enselme | 00 22 * * 6 /users/guest/assos/bin/d6-all-update-contrib.sh > /dev/null |
73 | 00 23 * * 6 /users/guest/assos/bin/d6-all-reset-variables.sh > /dev/null |
||
74 | 68 | Florent Torregrosa | |
75 | # Launch drush cron on fellowings |
||
76 | 96 | Julien Enselme | 45 17 * * * /users/guest/assos/bin/drushcronone assos.centrale-marseille.fr.ginfo > /dev/null 2>&1 |
77 | 91 | Julien Enselme | 35 00 * * * /users/guest/assos/bin/drushcronone assos.centrale-marseille.fr.cac13 > /dev/null |
78 | */45 * * * * /users/guest/assos/bin/drushcronone assos.centrale-marseille.fr.expat > /dev/null |
||
79 | 1 | Julien Enselme | |
80 | 67 | Julien Enselme | 00 22 * * 7 /users/guest/assos/bin/disk-usage.sh | mail -s "disk-usage.sh" assos |
81 | 3 | Julien Enselme | </code> |
82 | 83 | Julien Enselme | </pre> |
83 | |||
84 | 25 | Florent Torregrosa | La liste des tâches effectuées régulièrement est ci-dessous. |
85 | |||
86 | 1 | Julien Enselme | {{important(Lors de l’import d’un script de configuration comme _scripts-config.sh_ sont chemin doit être donné de façon absolue. Sinon le crontab ne trouvera pas le script !)}} |
87 | |||
88 | 25 | Florent Torregrosa | h2. La réinitialisation des variables |
89 | 1 | Julien Enselme | |
90 | 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. |
||
91 | |||
92 | 25 | Florent Torregrosa | En voici quelques exemples : |
93 | |||
94 | 1 | Julien Enselme | <pre> |
95 | 21 | Florent Torregrosa | <code class="bash"> |
96 | 25 | Florent Torregrosa | drush -y vset error_level 0 |
97 | </code> |
||
98 | 3 | Julien Enselme | </pre> |
99 | 1 | Julien Enselme | |
100 | 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. |
||
101 | 25 | Florent Torregrosa | |
102 | 1 | Julien Enselme | <pre> |
103 | 3 | Julien Enselme | <code class="php"> |
104 | 1 | Julien Enselme | drush -y vset --always-set reverse_proxy TRUE |
105 | 70 | Julien Enselme | drush -y vset --always-set --format=json reverse_proxy_addresses '["147.94.19.16","147.94.19.17"]' |
106 | 1 | Julien Enselme | </code> |
107 | 6 | Julien Enselme | </pre> |
108 | 1 | Julien Enselme | |
109 | 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/lessive/content/t%C3%A2che/rendre-les-settingsphp-conformes-%C3%A0-la-version-712-de-drupal** |
110 | 1 | Julien Enselme | |
111 | 73 | Julien Enselme | h2. La sauvegarde des bases de données |
112 | |||
113 | Sur les installations d6 et d7 : une fois par semaine |
||
114 | |||
115 | On utilise les scripts de sauvegardes : |
||
116 | |||
117 | 1 | Julien Enselme | * [[Scripts_et_taches_planifiees#d6-all-dump-fullsh|d6-all-dump-full.sh]] |
118 | 72 | Julien Enselme | * [[Scripts_et_taches_planifiees#d6-dump-individualsh|d6-dump-individual.sh]] |
119 | 1 | Julien Enselme | * [[Scripts_et_taches_planifiees#d7-all-dump-fullsh|d7-all-dump-full.sh]] |
120 | * [[Scripts_et_taches_planifiees#d7-all-dump-individualsh|d7-all-dump-individual.sh]]. |
||
121 | |||
122 | 72 | Julien Enselme | h2. La purge des sauvegardes de bases de données |
123 | 1 | Julien Enselme | |
124 | Sur les installations d6 et d7 : toutes les semaines |
||
125 | 21 | Florent Torregrosa | |
126 | 75 | Julien Enselme | Cette tâche utilise les scripts de purges des sauvegardes ([[Scripts_et_taches_planifiees#flush-full-databases-backupssh|flush-full-databases-backups.sh]] et [[Scripts_et_taches_planifiees#flush-individual-databases-backupssh|flush-individual-databases-backups.sh]]) afin de libérer de l'espace disque en supprimant les sauvegardes de bdd les plus vieilles. |
127 | |||
128 | h1. Liste des scripts à disposition |
||
129 | 21 | Florent Torregrosa | |
130 | 78 | Julien Enselme | Les scripts utilisés sont hébergés dans le répertoire bin du compte assos. Ce dossier est dans le PATH l'utilisateur assos ce qui permet d'utiliser les scripts comme les commandes ususelles du shell. Les script doivent exécutales pour fonctionner ainsi. Le script @all-reset-permissions.sh@ remet les bonnes permissions sur ce dossier. |
131 | |||
132 | 82 | Julien Enselme | Le PATH est par sécurité entièrement récrit dans @scripts-config.sh@ (on est certain que les commandes seront trouvées même si on ne les appelle pas avec leur chemin absolu). Le PATH contient alors les chemins vers les dossiers contenant les exécutales du système ainsi que les dossiers bin de assos. |
133 | |||
134 | 53 | Julien Enselme | La plupart des scripts ont besoin d’importer un des scripts de configuration. L’import se fait grâce à la commande @. SCRIPT@. Ces scripts doivent être importés explicitement. On réalise un test en début de script. Ce test permet de savoir si le script importé a besoin de l’import d’un autre script. Si ce n’est pas le cas, on affiche un message d’avertissement et on arrête l’exécution. |
135 | 1 | Julien Enselme | |
136 | 85 | Julien Enselme | Les scripts nécessitant un argument contiennent une ligne commençant par ARGS détaillant la liste des arguments nécessaires à l’exécution du script. Les arguments entre crochets sont facultatifs. Si vous lancez un tel script sans argument, il affichera un message d’aide donnant la liste des arguments. |
137 | 53 | Julien Enselme | |
138 | 76 | Julien Enselme | h2. Configuration et utilitaires |
139 | |||
140 | 53 | Julien Enselme | h3. scripts-config.sh |
141 | |||
142 | Ce script contient toutes les variables indispensables à l’exécution des autres scripts (adresse du serveur de la base de données, emplacement des sauvegardes,…). Ce script a été créé de façon a pouvoir rendre les scripts les plus indépendants possible de la configuration actuelle et de façon à pouvoir la modifier facilement sans avoir à réécrire les scripts et à les vérifier. *Ces variables doivent donc être utilisées dans les scripts.* |
||
143 | |||
144 | <pre> |
||
145 | <code class="php"> |
||
146 | #!/bin/sh |
||
147 | |||
148 | PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/local/bin:/users/guest/assos/bin |
||
149 | PATH=$PATH:/usr/guest/assos/bin |
||
150 | |||
151 | scripts_config='imported' |
||
152 | |||
153 | email_multi_assos="assos@centrale-marseille.fr" |
||
154 | |||
155 | dir_multi_assos='/users/guest/assos' |
||
156 | dir_scripts="$dir_multi_assos/bin" |
||
157 | dir_template="$dir_multi_assos/template" |
||
158 | |||
159 | ###### Database |
||
160 | db_server="myassos.serv.int" |
||
161 | db_user="assos" |
||
162 | 63 | Julien Enselme | dir_log="$dir_multi_assos/log" |
163 | 53 | Julien Enselme | |
164 | ###### Backup |
||
165 | db_full_backup_number=3 |
||
166 | db_individual_manual_backup_number=2 |
||
167 | db_individual_auto_backup_number=3 |
||
168 | 1 | Julien Enselme | |
169 | dir_backup="$dir_multi_assos/backup" |
||
170 | dir_full_backup="$dir_backup/full" |
||
171 | dir_individual_backup="$dir_backup/individual" |
||
172 | dir_individual_manual_backup="$dir_individual_backup/manual" |
||
173 | dir_individual_auto_backup="$dir_individual_backup/auto" |
||
174 | |||
175 | |||
176 | ###### D7 variables |
||
177 | d7_dir="$dir_multi_assos/htmltest" |
||
178 | d7_dir_sites="$d7_dir/sites" |
||
179 | |||
180 | ### Log |
||
181 | d7_dir_log="$dir_log/d7" |
||
182 | |||
183 | ### Backup |
||
184 | d7_dir_full_backup="$dir_full_backup/d7" |
||
185 | 87 | Julien Enselme | d7_dir_individual_manual_backup="$dir_individual_manual_backup/d7" |
186 | d7_dir_individual_auto_backup="$dir_individual_auto_backup/d7" |
||
187 | |||
188 | 88 | Julien Enselme | ### Template |
189 | 1 | Julien Enselme | d7_settings_name="d7-settings.php" |
190 | d7_settings_local_template_name="d7-settings-local-template.php" |
||
191 | d7_settings="$dir_template/$d7_settings_name" |
||
192 | d7_settings_local_template="$dir_template/$d7_settings_local_template_name" |
||
193 | |||
194 | |||
195 | ###### D6 variables |
||
196 | d6_dir="$dir_multi_assos/html" |
||
197 | d6_dir_sites="$d6_dir/sites" |
||
198 | |||
199 | 64 | Julien Enselme | ### Backup |
200 | d6_dir_full_backup="$dir_full_backup/d6" |
||
201 | d6_dir_individual_manual_backup="$dir_individual_manual_backup/d6" |
||
202 | d6_dir_individual_auto_backup="$dir_individual_auto_backup/d6" |
||
203 | </code> |
||
204 | 77 | Julien Enselme | </pre> |
205 | |||
206 | h3. scripts-config-site.sh |
||
207 | |||
208 | 64 | Julien Enselme | Ce script est complémentaire du précédent. Il permet d’initialiser les variables spécifiques à un site. Il prend le nom du site en question comme argument. *Il doit être utilisé pour les mêmes raisons que le précédent*. |
209 | |||
210 | La commande @check_arguments@ n’est pas utilisée afin de ne pas avoir à importer @scripts-utils.sh@ et ainsi éviter des imports multiples. |
||
211 | |||
212 | <pre> |
||
213 | <code class="php"> |
||
214 | #!/bin/sh |
||
215 | |||
216 | # Sets useful variables of a site. |
||
217 | # ARGS: site_name |
||
218 | # Requires scripts-config.sh |
||
219 | |||
220 | # Check if scripts-config.sh is imported. |
||
221 | if [ -z $scripts_config ] ; then |
||
222 | echo "Import of scripts-config.sh required." |
||
223 | exit 1 |
||
224 | fi |
||
225 | |||
226 | if [ -z $1 ] ; then |
||
227 | echo "This script needs a site name as argument." |
||
228 | exit 1 |
||
229 | fi |
||
230 | 1 | Julien Enselme | |
231 | 64 | Julien Enselme | scripts_config_site='imported' |
232 | 87 | Julien Enselme | |
233 | 53 | Julien Enselme | d7_site_name=$1 |
234 | d7_site_dir="$d7_dir_sites/assos.centrale-marseille.fr.$d7_site_name" |
||
235 | d7_site_settings="$d7_site_dir/settings.php" |
||
236 | d7_site_settings_local="$d7_site_dir/settings.local.php" |
||
237 | </code> |
||
238 | 79 | Julien Enselme | </pre> |
239 | |||
240 | 53 | Julien Enselme | h3. scripts-utils.sh |
241 | |||
242 | Ce script propose des commandes utiles qui peuvent être utilisées dans divers script. Il a été écrit afin de factoriser au maximum le code. |
||
243 | |||
244 | <pre> |
||
245 | <code class="php"> |
||
246 | 1 | Julien Enselme | #!/bin/sh |
247 | 53 | Julien Enselme | |
248 | # This script contains useful functions for other scripts. |
||
249 | 87 | Julien Enselme | |
250 | 53 | Julien Enselme | # Check if scripts-config.sh is imported. |
251 | if [ -z $scripts_config ] ; then |
||
252 | echo "Import of scripts-config.sh required." |
||
253 | . scripts-config.sh |
||
254 | fi |
||
255 | |||
256 | scripts_utils='imported' |
||
257 | |||
258 | ask_password() { |
||
259 | # read -s doesn't work with sh. |
||
260 | # usage: pass=`ask_password "password please:"` |
||
261 | echo $1 >&2 |
||
262 | echo -n ">" >&2 |
||
263 | stty_avant=`stty -g` |
||
264 | stty -echo |
||
265 | read password |
||
266 | stty $stty_avant |
||
267 | echo "$password" |
||
268 | unset password |
||
269 | } |
||
270 | |||
271 | ask_password_db() { |
||
272 | # ARGS: server_name, user_name |
||
273 | local db_password="pour_boucler" |
||
274 | # empty db request to validate password |
||
275 | while ! mysql -h $1 -u $2 -p$db_password -e "" 2>/dev/null ; do |
||
276 | db_password=`ask_password "database password:"` |
||
277 | done |
||
278 | echo $db_password |
||
279 | } |
||
280 | |||
281 | generate_password(){ |
||
282 | # ARGS: [password_length] |
||
283 | # The password contains special characters. '/' must be excluded to avoid sed malfunction. |
||
284 | |||
285 | local site_password='/' |
||
286 | |||
287 | if [ -z $1 ] ; then |
||
288 | local password_length=20 |
||
289 | else |
||
290 | local password_length=$1 |
||
291 | fi |
||
292 | |||
293 | while echo "$site_password" | grep -Fq '/' ; do |
||
294 | site_password=`dd if=/dev/urandom count=1 | uuencode -m - | head -n 2 | tail -n 1 | cut -c-$password_length` |
||
295 | done |
||
296 | |||
297 | echo $site_password |
||
298 | } |
||
299 | |||
300 | 1 | Julien Enselme | count_d7_sites(){ |
301 | 65 | Julien Enselme | find $d7_dir_sites -type d ! -name all -maxdepth 1 | wc -l |
302 | 53 | Julien Enselme | } |
303 | 1 | Julien Enselme | |
304 | 87 | Julien Enselme | check_arguments() { |
305 | 1 | Julien Enselme | # ARGS: number of arguments passed to script, number of arguments required, [help text] |
306 | if [ $1 -lt $2 ] ; then |
||
307 | echo "Number of arguments insuffisant." |
||
308 | 87 | Julien Enselme | echo -e $3 |
309 | exit 1 |
||
310 | fi |
||
311 | } |
||
312 | |||
313 | generate_settings_local() { |
||
314 | # ARGS: site_name, site_password, d7_settings_local_template, d7_site_settings_local |
||
315 | sed "s/\%\%DBUSER\%\%/$1/ ; s/\%\%DBNAME\%\%/$1/ ; s/\%\%DBPASS\%\%/$2/ ; s/\%\%SITE_NAME\%\%/$1/" < $3 > $4 |
||
316 | } |
||
317 | |||
318 | give_dir(){ |
||
319 | # ARG: file |
||
320 | 53 | Julien Enselme | # Return the abosulte directory path of a file or a dir. |
321 | settings_location=`realpath $1` |
||
322 | echo `dirname $settings_location` |
||
323 | } |
||
324 | </code> |
||
325 | </pre> |
||
326 | |||
327 | h2. Scripts généraux |
||
328 | |||
329 | h3. all-reset-permissions.sh |
||
330 | |||
331 | 84 | Julien Enselme | <pre> |
332 | 21 | Florent Torregrosa | <code class="php"> |
333 | #!/bin/sh |
||
334 | |||
335 | . /users/guest/assos/bin/scripts-config.sh |
||
336 | |||
337 | # This script puts the correct permissions to sites folders, settings.php and scripts. |
||
338 | |||
339 | 35 | Florent Torregrosa | ######### drupal 6 |
340 | for dir in `find $d6_dir_sites -type d -maxdepth 1 -mindepth 1 ! -name all ! -name images ! -name languages` ; do |
||
341 | 1 | Julien Enselme | chmod 755 $dir |
342 | 35 | Florent Torregrosa | chmod 400 $dir/settings.php |
343 | done |
||
344 | |||
345 | 87 | Julien Enselme | ######### drupal 7 |
346 | 21 | Florent Torregrosa | for dir in `find $d7_dir_sites -type d -maxdepth 1 -mindepth 1 ! -name all` ; do |
347 | chmod 755 $dir |
||
348 | 1 | Julien Enselme | chmod 400 $dir/settings.php |
349 | 21 | Florent Torregrosa | chmod 400 $dir/settings.local.php |
350 | done |
||
351 | |||
352 | ####### bin |
||
353 | chmod -R 700 $dir_scripts |
||
354 | |||
355 | ####### backup |
||
356 | chmod -R 700 $dir_backup |
||
357 | 1 | Julien Enselme | |
358 | 21 | Florent Torregrosa | ####### log |
359 | 53 | Julien Enselme | chmod -R 700 $dir_log |
360 | 29 | Florent Torregrosa | </code> |
361 | 21 | Florent Torregrosa | </pre> |
362 | |||
363 | h3. contrib-usage.sh |
||
364 | |||
365 | 84 | Julien Enselme | <pre> |
366 | 21 | Florent Torregrosa | <code class="php"> |
367 | #!/bin/sh |
||
368 | 66 | Julien Enselme | |
369 | . /users/guest/assos/bin/scripts-config.sh |
||
370 | . scripts-utils.sh |
||
371 | 21 | Florent Torregrosa | |
372 | 66 | Julien Enselme | help="# ARGS: Drupal_version, project_status, project_name\n |
373 | 21 | Florent Torregrosa | # List sites that have the project_name with the corresponding project_status.\n |
374 | # project status: enabled or disabled" |
||
375 | |||
376 | check_arguments $# 3 "$help" |
||
377 | |||
378 | if [ $1 = d6 ] ; then |
||
379 | 29 | Florent Torregrosa | cd $d6_dir_sites |
380 | 21 | Florent Torregrosa | else |
381 | cd $d7_dir_sites |
||
382 | fi |
||
383 | |||
384 | 1 | Julien Enselme | for dir in `find . -maxdepth 1 -mindepth 1 -type d ! -name all ! -name languages ! -name images | sort ` ; do |
385 | 21 | Florent Torregrosa | # List non-core projects that correspond to the status. |
386 | # Keep project_name if listed. |
||
387 | # Count line result. 0 if not listed or 1 if listed. |
||
388 | # Print site_dir if listed. |
||
389 | |||
390 | cd $dir; |
||
391 | if [ 1 -eq `drush pml --no-core --status=$2 | grep $3 | wc -l` ] ; then |
||
392 | 1 | Julien Enselme | echo $dir; |
393 | 21 | Florent Torregrosa | fi |
394 | cd - |
||
395 | 53 | Julien Enselme | done |
396 | 21 | Florent Torregrosa | </code> |
397 | 41 | Florent Torregrosa | </pre> |
398 | 21 | Florent Torregrosa | |
399 | 1 | Julien Enselme | h3. delete-temporary-files.sh |
400 | |||
401 | 84 | Julien Enselme | <pre> |
402 | 53 | Julien Enselme | <code class="php"> |
403 | #!/bin/sh |
||
404 | |||
405 | . /users/guest/assos/bin/scripts-config.sh |
||
406 | |||
407 | find $dir_multi_assos -name '*~' -delete |
||
408 | </code> |
||
409 | </pre> |
||
410 | |||
411 | h3. disk-usage.sh |
||
412 | |||
413 | 84 | Julien Enselme | <pre> |
414 | 53 | Julien Enselme | <code class="php"> |
415 | #!/bin/sh |
||
416 | |||
417 | . /users/guest/assos/bin/scripts-config.sh |
||
418 | |||
419 | echo -e "Quotas: 9.1 GB\n" |
||
420 | |||
421 | echo "Assos:" |
||
422 | du -hcs $dir_multi_assos | grep total |
||
423 | echo -e "\n" |
||
424 | |||
425 | echo "D6:" |
||
426 | cd $d6_dir_sites |
||
427 | du -h -d 1 |
||
428 | echo -e "\n" |
||
429 | |||
430 | echo "D7:" |
||
431 | cd $d7_dir_sites |
||
432 | du -h -d 1 |
||
433 | echo -e "\n" |
||
434 | |||
435 | echo "Logs:" |
||
436 | du -hcs $dir_log | grep total |
||
437 | echo -e "\n" |
||
438 | |||
439 | echo "Backups:" |
||
440 | cd $dir_backup |
||
441 | du -h -d 2 |
||
442 | </code> |
||
443 | 81 | Julien Enselme | </pre> |
444 | |||
445 | 53 | Julien Enselme | h3. flush-files.sh |
446 | |||
447 | Ce script se contente d’afficher un warning si scripts-utils.sh afin de pouvoir l’utiliser directement depuis le terminal. |
||
448 | |||
449 | 66 | Julien Enselme | <pre> |
450 | 53 | Julien Enselme | <code class="php"> |
451 | 1 | Julien Enselme | #!/bin/sh |
452 | 81 | Julien Enselme | |
453 | 53 | Julien Enselme | help="# ARGS: number of files to keep, [email address]\n |
454 | # usage: flush files from a folder except a number equal to argument." |
||
455 | 57 | Julien Enselme | |
456 | 53 | Julien Enselme | # Check if scripts-utils.sh is imported. |
457 | if [ -z $scripts_utils ] ; then |
||
458 | 66 | Julien Enselme | echo "Import of scripts-utils.sh required." |
459 | 53 | Julien Enselme | . scripts-utils.sh |
460 | fi |
||
461 | 60 | Julien Enselme | |
462 | 53 | Julien Enselme | check_arguments $# 1 "$help" |
463 | 1 | Julien Enselme | |
464 | backups_number=`ls | wc -l` |
||
465 | 53 | Julien Enselme | let "number_of_backups_to_delete = backups_number - $1" > /dev/null |
466 | 60 | Julien Enselme | |
467 | if [ $number_of_backups_to_delete -gt 0 ] ; then |
||
468 | ls | head -$number_of_backups_to_delete | xargs rm |
||
469 | else |
||
470 | 53 | Julien Enselme | if [ ! -z $2 ] ; then |
471 | dir=`pwd` |
||
472 | 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 |
||
473 | fi |
||
474 | fi |
||
475 | </code> |
||
476 | </pre> |
||
477 | |||
478 | h3. flush-full-databases-backups.sh |
||
479 | |||
480 | 84 | Julien Enselme | <pre> |
481 | 53 | Julien Enselme | <code class="php"> |
482 | #!/bin/sh |
||
483 | |||
484 | . /users/guest/assos/bin/scripts-config.sh |
||
485 | |||
486 | # ARGS: Drupal version |
||
487 | |||
488 | cd $dir_full_backup/$1 |
||
489 | |||
490 | for dir in `ls` ; do |
||
491 | cd $dir |
||
492 | flush-files.sh $db_full_backup_number $email_multi_assos |
||
493 | cd - |
||
494 | done |
||
495 | </code> |
||
496 | </pre> |
||
497 | |||
498 | h3. flush-individual-databases-backups.sh |
||
499 | |||
500 | 84 | Julien Enselme | <pre> |
501 | 1 | Julien Enselme | <code class="php"> |
502 | #!/bin/sh |
||
503 | |||
504 | . /users/guest/assos/bin/scripts-config.sh |
||
505 | |||
506 | # ARGS: manual or auto, Drupal version |
||
507 | |||
508 | cd $dir_individual_backup/$1/$2 |
||
509 | |||
510 | for dir in `ls` ; do |
||
511 | cd $dir |
||
512 | if [ $1 = 'auto' ] ; then |
||
513 | flush-files.sh $db_individual_auto_backup_number $email_multi_assos |
||
514 | else |
||
515 | flush-files.sh $db_individual_manual_backup_number |
||
516 | fi |
||
517 | cd - |
||
518 | done |
||
519 | 80 | Julien Enselme | </code> |
520 | </pre> |
||
521 | |||
522 | h2. Scripts Drupal 6 |
||
523 | |||
524 | h3. drushcronone |
||
525 | |||
526 | Ce script permet de lancer les tâches planifiées sur un site Drupal 6. En effet, sous Drupal 6 les webmasters ne peuvent choisir via l’interface d’administration de Drupal. |
||
527 | |||
528 | 84 | Julien Enselme | <pre> |
529 | 80 | Julien Enselme | <code class="php"> |
530 | #!/bin/sh |
||
531 | |||
532 | . /users/guest/assos/bin/scripts-config.sh |
||
533 | |||
534 | if [ $# -lt 1 ]; then |
||
535 | echo "usage: $0 <site's folder name>" |
||
536 | exit 1 |
||
537 | fi |
||
538 | |||
539 | cd "$d6_sites_dir/$*" |
||
540 | 53 | Julien Enselme | pwd; |
541 | drush cron; |
||
542 | </code> |
||
543 | </pre> |
||
544 | |||
545 | h3. d6-all-drush.sh |
||
546 | |||
547 | 84 | Julien Enselme | <pre> |
548 | 21 | Florent Torregrosa | <code class="php"> |
549 | #!/bin/sh |
||
550 | 66 | Julien Enselme | |
551 | 21 | Florent Torregrosa | . /users/guest/assos/bin/scripts-config.sh |
552 | 66 | Julien Enselme | . scripts-utils.sh |
553 | 21 | Florent Torregrosa | |
554 | help="# ARGS: drush_command" |
||
555 | |||
556 | check_arguments $# 1 "$help" |
||
557 | |||
558 | 1 | Julien Enselme | for dir in `find $d6_dir_sites -maxdepth 1 -mindepth 1 -type d ! -name all ! -name languages ! -name images | sort` ; do |
559 | 21 | Florent Torregrosa | cd $dir |
560 | 45 | Florent Torregrosa | echo $dir |
561 | 21 | Florent Torregrosa | drush $* |
562 | 53 | Julien Enselme | done |
563 | 45 | Florent Torregrosa | </code> |
564 | 37 | Florent Torregrosa | </pre> |
565 | |||
566 | h3. d6-all-dump-full.sh |
||
567 | |||
568 | 84 | Julien Enselme | <pre> |
569 | 37 | Florent Torregrosa | <code class="php"> |
570 | #!/bin/sh |
||
571 | |||
572 | . /users/guest/assos/bin/scripts-config.sh |
||
573 | |||
574 | 41 | Florent Torregrosa | current_date=`date "+%Y-%m-%d-%Hh%Mm%Ss"` |
575 | 1 | Julien Enselme | |
576 | 37 | Florent Torregrosa | # Dump D6 database with webassos user. |
577 | mysqldump --single-transaction webassos -h myweb.serv.int -u webassos --password=password > $d6_dir_full_backup/webassos/$current_date.webassos.sql |
||
578 | 21 | Florent Torregrosa | </code> |
579 | </pre> |
||
580 | |||
581 | h3. d6-all-reset-variables.sh |
||
582 | |||
583 | 84 | Julien Enselme | <pre> |
584 | 21 | Florent Torregrosa | <code class="php"> |
585 | #!/bin/sh |
||
586 | 1 | Julien Enselme | |
587 | 21 | Florent Torregrosa | . /users/guest/assos/bin/scripts-config.sh |
588 | |||
589 | cd $d6_dir_sites |
||
590 | d6-all-drush.sh vset --always-set reverse_proxy TRUE |
||
591 | d6-all-drush.sh vset --always-set --format=json reverse_proxy_addresses '["147.94.19.16","147.94.19.17"]' |
||
592 | 53 | Julien Enselme | drush @sites -y ev "variable_set('update_notify_emails', array('@email_multi_assos'));" |
593 | 21 | Florent Torregrosa | </code> |
594 | </pre> |
||
595 | |||
596 | h3. d6-all-update-contrib.sh |
||
597 | |||
598 | 84 | Julien Enselme | <pre> |
599 | 21 | Florent Torregrosa | <code class="php"> |
600 | #!/bin/sh |
||
601 | 1 | Julien Enselme | |
602 | 21 | Florent Torregrosa | . /users/guest/assos/bin/scripts-config.sh |
603 | |||
604 | d6-all-drush.sh -y en update |
||
605 | # Launch cron to check for updates. |
||
606 | d6-all-drush.sh -q cron |
||
607 | |||
608 | 1 | Julien Enselme | d6-all-drush.sh cc all |
609 | d6-all-dump-full.sh |
||
610 | |||
611 | d6-all-drush.sh -y upc --no-core |
||
612 | d6-all-drush.sh -y updb |
||
613 | |||
614 | d6-all-drush.sh -y dis update |
||
615 | 41 | Florent Torregrosa | |
616 | 53 | Julien Enselme | d6-all-drush.sh cron |
617 | 41 | Florent Torregrosa | </code> |
618 | </pre> |
||
619 | |||
620 | h3. d6-dump-individual.sh |
||
621 | |||
622 | 84 | Julien Enselme | <pre> |
623 | 21 | Florent Torregrosa | <code class="php"> |
624 | #!/bin/sh |
||
625 | |||
626 | . /users/guest/assos/bin/scripts-config.sh |
||
627 | |||
628 | 1 | Julien Enselme | # ARGS: auto or manual, site_prefix |
629 | # WARNING : backup are regularly flushed, put your backup in a safe place. |
||
630 | |||
631 | 84 | Julien Enselme | cd $dir_individual_backup |
632 | 21 | Florent Torregrosa | |
633 | 1 | Julien Enselme | #!/bin/sh |
634 | 21 | Florent Torregrosa | |
635 | . /users/guest/assos/bin/scripts-config.sh |
||
636 | |||
637 | # ARGS: auto or manual, site_prefix |
||
638 | 41 | Florent Torregrosa | # WARNING : backup are regularly flushed, put your backup in a safe place. |
639 | |||
640 | cd $dir_individual_backup |
||
641 | |||
642 | 21 | Florent Torregrosa | #récupération des tables du site dans le fichier liste_tables.temp |
643 | tables='_%' |
||
644 | liste="$1$tables" |
||
645 | |||
646 | mysql -h myweb.serv.int -u webassos --password=HBVH2ljgyZCA0AP251DY -BNe "show tables like '"$liste"'" webassos | tr '\r\n' ' ' > liste_tables.temp |
||
647 | 1 | Julien Enselme | |
648 | 21 | Florent Torregrosa | #transformation de cette liste en une variable |
649 | var=$(cat liste_tables.temp) |
||
650 | |||
651 | #sauvegarde de toutes ces tables |
||
652 | 1 | Julien Enselme | current_date=`date "+%Y-%m-%d-%Hh%Mm%Ss"` |
653 | 21 | Florent Torregrosa | suffixe="_dump$current_date.sql" |
654 | fichier="$1$suffixe" |
||
655 | 1 | Julien Enselme | |
656 | 21 | Florent Torregrosa | if [ $1 = 'auto' ] ; then |
657 | 1 | Julien Enselme | mysqldump webassos -h myweb.serv.int -u webassos --password=HBVH2ljgyZCA0AP251DY $var > $d6_dir_individual_auto_backup/$fichier |
658 | else |
||
659 | 21 | Florent Torregrosa | mysqldump webassos -h myweb.serv.int -u webassos --password=HBVH2ljgyZCA0AP251DY $var > $d6_dir_individual_manual_backup/$fichier |
660 | fi |
||
661 | |||
662 | #suppression du fichier temporaire utilisé |
||
663 | 53 | Julien Enselme | rm liste_tables.temp |
664 | 30 | Florent Torregrosa | </code> |
665 | 53 | Julien Enselme | </pre> |
666 | |||
667 | 1 | Julien Enselme | h2. Scripts Drupal 7 |
668 | 30 | Florent Torregrosa | |
669 | h3. d7-all-drush-logged.sh |
||
670 | |||
671 | 84 | Julien Enselme | <pre> |
672 | 30 | Florent Torregrosa | <code class="php"> |
673 | #!/bin/sh |
||
674 | 66 | Julien Enselme | |
675 | 21 | Florent Torregrosa | . /users/guest/assos/bin/scripts-config.sh |
676 | 66 | Julien Enselme | . scripts-utils.sh |
677 | 1 | Julien Enselme | |
678 | 21 | Florent Torregrosa | help="# ARGS: drush_command" |
679 | 1 | Julien Enselme | |
680 | 21 | Florent Torregrosa | check_arguments $# 1 "$help" |
681 | |||
682 | cd $d7_dir_sites |
||
683 | |||
684 | 1 | Julien Enselme | for dir in `find . -maxdepth 1 -mindepth 1 -type d ! -name all | sort` ; do |
685 | 21 | Florent Torregrosa | cd $dir |
686 | current_date=`date "+%Y-%m-%d_%Hh:%Mm"` |
||
687 | echo "======$current_date======" >> $d7_dir_log/$dir.log |
||
688 | echo "Arguments are: $* " >> $d7_dir_log/$dir.log |
||
689 | drush $* >> $d7_dir_log/$dir.log |
||
690 | #To have the same caracters limit we needed 'end' that have 4 caracters, we used the Croate language for this ! LOL |
||
691 | echo -e "=============KRAJ=============\n" >> $d7_dir_log/$dir.log |
||
692 | 41 | Florent Torregrosa | cd - |
693 | 53 | Julien Enselme | done |
694 | 21 | Florent Torregrosa | </code> |
695 | </pre> |
||
696 | |||
697 | h3. d7-all-drush.sh |
||
698 | |||
699 | 84 | Julien Enselme | <pre> |
700 | 1 | Julien Enselme | <code class="php"> |
701 | 21 | Florent Torregrosa | #!/bin/sh |
702 | 66 | Julien Enselme | |
703 | 21 | Florent Torregrosa | . /users/guest/assos/bin/scripts-config.sh |
704 | 66 | Julien Enselme | . scripts-utils.sh |
705 | 21 | Florent Torregrosa | |
706 | help="# ARGS: drush_command" |
||
707 | |||
708 | check_arguments $# 1 "$help" |
||
709 | |||
710 | for dir in `find $d7_dir_sites -maxdepth 1 -mindepth 1 -type d ! -name all | sort` ; do |
||
711 | cd $dir |
||
712 | echo $dir |
||
713 | drush $* |
||
714 | 53 | Julien Enselme | done |
715 | 21 | Florent Torregrosa | </code> |
716 | 45 | Florent Torregrosa | </pre> |
717 | 21 | Florent Torregrosa | |
718 | 1 | Julien Enselme | h3. d7-all-dump-full.sh |
719 | 21 | Florent Torregrosa | |
720 | 84 | Julien Enselme | <pre> |
721 | 21 | Florent Torregrosa | <code class="php"> |
722 | #!/bin/sh |
||
723 | |||
724 | . /users/guest/assos/bin/scripts-config.sh |
||
725 | |||
726 | 41 | Florent Torregrosa | current_date=`date "+%Y-%m-%d-%Hh%Mm%Ss"` |
727 | |||
728 | # Dump D7 databases at once. |
||
729 | 53 | Julien Enselme | mysqldump -h $db_server -u $db_user -ppassword --all-databases > $d7_dir_full_backup/myassos/$current_date.d7_full.sql |
730 | 21 | Florent Torregrosa | </code> |
731 | </pre> |
||
732 | 41 | Florent Torregrosa | |
733 | h3. d7-all-dump-individual.sh |
||
734 | |||
735 | 84 | Julien Enselme | <pre> |
736 | 62 | Julien Enselme | <code class="php"> |
737 | 21 | Florent Torregrosa | #!/bin/sh |
738 | 66 | Julien Enselme | |
739 | 1 | Julien Enselme | . /users/guest/assos/bin/scripts-config.sh |
740 | 66 | Julien Enselme | . scripts-utils.sh |
741 | 21 | Florent Torregrosa | |
742 | help="# ARGS: auto or manual" |
||
743 | |||
744 | check_arguments $# 1 "$help" |
||
745 | |||
746 | current_date=`date "+%Y-%m-%d-%Hh%Mm%Ss"` |
||
747 | 1 | Julien Enselme | |
748 | 21 | Florent Torregrosa | cd $d7_dir_sites |
749 | |||
750 | for dir in `find . -maxdepth 1 -mindepth 1 -type d ! -name all | cut -c3-` ; do |
||
751 | cd $dir |
||
752 | 1 | Julien Enselme | drush cc all |
753 | 21 | Florent Torregrosa | if [ $1 = 'auto' ] ; then |
754 | drush sql-dump --result-file="$d7_dir_individual_auto_backup/$dir/$current_date.$dir.sql" |
||
755 | else |
||
756 | drush sql-dump --result-file="$d7_dir_individual_manual_backup/$dir/$current_date.$dir.sql" |
||
757 | fi |
||
758 | cd - |
||
759 | 53 | Julien Enselme | done |
760 | 21 | Florent Torregrosa | </code> |
761 | </pre> |
||
762 | |||
763 | h3. d7-all-releases-info.sh |
||
764 | 1 | Julien Enselme | |
765 | 84 | Julien Enselme | <pre> |
766 | 1 | Julien Enselme | <code class="php"> |
767 | #!/bin/sh |
||
768 | |||
769 | . /users/guest/assos/bin/scripts-config.sh |
||
770 | |||
771 | # List version of a module or theme that exists in sites/all/* |
||
772 | # and all versions that are available for same project on drupal.org |
||
773 | |||
774 | # modules |
||
775 | cd $d7_dir_sites/all/modules |
||
776 | for dir in `ls -1` ; do |
||
777 | if [ -d $dir ] ; then |
||
778 | drush pm-releases $dir |
||
779 | fi |
||
780 | done |
||
781 | |||
782 | # themes |
||
783 | cd $d7_dir_sites/all/themes |
||
784 | 21 | Florent Torregrosa | for dir in `ls -1` ; do |
785 | if [ -d $dir ] ; then |
||
786 | drush pm-releases $dir |
||
787 | 41 | Florent Torregrosa | fi |
788 | 53 | Julien Enselme | done |
789 | 41 | Florent Torregrosa | </code> |
790 | 1 | Julien Enselme | </pre> |
791 | 41 | Florent Torregrosa | |
792 | h3. d7-all-reset-variables.sh |
||
793 | |||
794 | 84 | Julien Enselme | <pre> |
795 | 41 | Florent Torregrosa | <code class="php"> |
796 | #!/bin/sh |
||
797 | |||
798 | . /users/guest/assos/bin/scripts-config.sh |
||
799 | |||
800 | for dir in `find $d7_dir_sites -maxdepth 1 -mindepth 1 -type d ! -name all | sort` ; do |
||
801 | cd $dir |
||
802 | 1 | Julien Enselme | echo $dir |
803 | 41 | Florent Torregrosa | d7-reset-variables.sh |
804 | 53 | Julien Enselme | done |
805 | 41 | Florent Torregrosa | </code> |
806 | </pre> |
||
807 | |||
808 | 1 | Julien Enselme | h3. d7-all-security-review.sh |
809 | 21 | Florent Torregrosa | |
810 | 84 | Julien Enselme | <pre> |
811 | 21 | Florent Torregrosa | <code class="php"> |
812 | #!/bin/sh |
||
813 | 59 | Florent Torregrosa | |
814 | 21 | Florent Torregrosa | . /users/guest/assos/bin/scripts-config.sh |
815 | |||
816 | # grep -v success to keep site_name and error lines. |
||
817 | 53 | Julien Enselme | bash -c "d7-all-drush.sh security-review --store |& grep -v success | mail -s d7-all-security-review.sh $email_multi_assos" |
818 | 21 | Florent Torregrosa | </code> |
819 | </pre> |
||
820 | |||
821 | h3. d7-all-update-contrib.sh |
||
822 | |||
823 | 84 | Julien Enselme | <pre> |
824 | 1 | Julien Enselme | <code class="php"> |
825 | 21 | Florent Torregrosa | #!/bin/sh |
826 | |||
827 | . /users/guest/assos/bin/scripts-config.sh |
||
828 | |||
829 | d7-all-drush.sh -y en update |
||
830 | # Launch cron to check for updates. |
||
831 | 1 | Julien Enselme | d7-all-drush.sh -q cron |
832 | 21 | Florent Torregrosa | |
833 | d7-all-dump-individual.sh auto |
||
834 | |||
835 | d7-all-drush-logged.sh -y upc --no-core |
||
836 | 90 | Florent Torregrosa | d7-all-drush.sh -y updb |
837 | |||
838 | 21 | Florent Torregrosa | d7-all-drush.sh -y dis update |
839 | |||
840 | 1 | Julien Enselme | d7-all-drush.sh cc all |
841 | 21 | Florent Torregrosa | |
842 | 53 | Julien Enselme | d7-all-drush.sh cron |
843 | 21 | Florent Torregrosa | </code> |
844 | </pre> |
||
845 | |||
846 | 84 | Julien Enselme | h3. d7-all-update-localisation.sh |
847 | 21 | Florent Torregrosa | |
848 | <pre> |
||
849 | <code class="php"> |
||
850 | #!/bin/sh |
||
851 | |||
852 | . /users/guest/assos/bin/scripts-config.sh |
||
853 | |||
854 | 41 | Florent Torregrosa | d7-all-drush.sh -y en l10n_update |
855 | 53 | Julien Enselme | d7-all-drush.sh l10n-update-refresh |
856 | 1 | Julien Enselme | d7-all-drush.sh l10n-update |
857 | 21 | Florent Torregrosa | d7-all-drush.sh -y dis l10n_update |
858 | 1 | Julien Enselme | </code> |
859 | </pre> |
||
860 | 21 | Florent Torregrosa | |
861 | 97 | Florent Torregrosa | |
862 | h3. d7-all-who-is-admin.sh |
||
863 | |||
864 | <pre> |
||
865 | <code class="php"> |
||
866 | #!/bin/sh |
||
867 | |||
868 | . /users/guest/assos/bin/scripts-config.sh |
||
869 | |||
870 | for dir in `find $d7_dir_sites -maxdepth 1 -mindepth 1 -type d ! -name all | sort` ; do |
||
871 | cd $dir |
||
872 | echo $dir |
||
873 | drush sqlq "SELECT name, mail FROM users WHERE uid IN (SELECT uid FROM users_roles WHERE rid=3);" |
||
874 | done |
||
875 | </code> |
||
876 | </pre> |
||
877 | |||
878 | 21 | Florent Torregrosa | h3. d7-create-site.sh |
879 | 1 | Julien Enselme | |
880 | 84 | Julien Enselme | <pre> |
881 | 87 | Julien Enselme | <code class="php"> |
882 | #!/bin/sh |
||
883 | 21 | Florent Torregrosa | |
884 | 66 | Julien Enselme | . /users/guest/assos/bin/scripts-config.sh |
885 | 21 | Florent Torregrosa | . /users/guest/assos/bin/scripts-config-site.sh $1 |
886 | . /users/guest/assos/bin/scripts-utils.sh |
||
887 | 66 | Julien Enselme | |
888 | 21 | Florent Torregrosa | help="# ARGS: site name" |
889 | |||
890 | ######## Exceptions |
||
891 | check_arguments $# 1 "$help" |
||
892 | |||
893 | # "-" is forbidden because it provokes database error. |
||
894 | if [ `echo $1 | grep -` ] ; then |
||
895 | echo '"-" is forbidden in the site name' |
||
896 | exit 1 |
||
897 | 41 | Florent Torregrosa | fi |
898 | 21 | Florent Torregrosa | |
899 | # Site name length must be lower or equal to 16 due to database limitations. |
||
900 | if [`echo $1 | wc -c` -gt 16 ] ; then |
||
901 | 1 | Julien Enselme | echo "site name can't have more than 16 characters" |
902 | 21 | Florent Torregrosa | exit 1 |
903 | fi |
||
904 | |||
905 | ###### Initialisation |
||
906 | cd $d7_dir |
||
907 | db_password=`ask_password_db $db_server $db_user` |
||
908 | site_password=`generate_password` |
||
909 | 98 | Julien Enselme | site_line_sites_php="\$sites['assos.centrale-marseille.fr.$d7_site_name'] = 'assos.centrale-marseille.fr.$d7_site_name';" |
910 | 21 | Florent Torregrosa | |
911 | # Check if site database already exists. |
||
912 | if mysql -h $db_server -u $db_user -e "USE $d7_site_name" -p$db_password 2>/dev/null ; then |
||
913 | echo "Database $d7_site_name already exists" |
||
914 | exit 1 |
||
915 | fi |
||
916 | |||
917 | # Check if site folder already exists. |
||
918 | if [ -d $d7_site_dir ] ; then |
||
919 | echo "Folder $d7_site_dir already exists" |
||
920 | exit 1 |
||
921 | fi |
||
922 | |||
923 | 1 | Julien Enselme | ###### Main |
924 | 21 | Florent Torregrosa | mkdir $d7_site_dir |
925 | dir_site_name="assos.centrale-marseille.fr.$d7_site_name" |
||
926 | 1 | Julien Enselme | |
927 | 21 | Florent Torregrosa | # Backup requirements |
928 | mkdir $d7_dir_individual_auto_backup/$dir_site_name |
||
929 | mkdir $d7_dir_individual_manual_backup/$dir_site_name |
||
930 | current_date=`date "+%Y-%m-%d-%Hh%Mm%Ss"` |
||
931 | |||
932 | 87 | Julien Enselme | # NB : ls sort by considering the 1st characters |
933 | 1 | Julien Enselme | touch $d7_dir_individual_auto_backup/$dir_site_name/$current_date.$dir_site_name.sql |
934 | touch $d7_dir_individual_auto_backup/$dir_site_name/$current_date.$dir_site_name.sql2 |
||
935 | 21 | Florent Torregrosa | touch $d7_dir_individual_auto_backup/$dir_site_name/$current_date.$dir_site_name.sql3 |
936 | touch $d7_dir_individual_auto_backup/$dir_site_name/$current_date.$dir_site_name.sql4 |
||
937 | |||
938 | # Create and grant privileges on database |
||
939 | 87 | Julien Enselme | mysql -h $db_server -u $db_user -e "CREATE DATABASE $d7_site_name" -p$db_password |
940 | 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 |
||
941 | 21 | Florent Torregrosa | |
942 | # Create settings.php |
||
943 | cp $d7_settings $d7_site_settings |
||
944 | generate_settings_local $d7_site_name $site_password $d7_settings_local_template $d7_site_settings_local |
||
945 | |||
946 | # Create symbolic link |
||
947 | cd $d7_dir |
||
948 | ln -s . $d7_site_name |
||
949 | 1 | Julien Enselme | |
950 | 98 | Julien Enselme | # Update sites.php |
951 | echo $site_line_sites_php >> $sites_php |
||
952 | |||
953 | 41 | Florent Torregrosa | # Next Instructions |
954 | 21 | Florent Torregrosa | echo "Go to http://assos.centrale-marseille.fr/$d7_site_name/install.php to continue." |
955 | echo "Press enter when ready to go on." |
||
956 | read key |
||
957 | |||
958 | # Init variables |
||
959 | d7-reset-variables.sh $d7_site_name |
||
960 | |||
961 | # Permissions |
||
962 | chmod -R 755 $d7_site_dir |
||
963 | chmod 400 $d7_site_settings |
||
964 | |||
965 | # Last instructions |
||
966 | echo "Last instructions:" |
||
967 | echo "- Advice the webmaster to close account creation on the website" |
||
968 | echo "- Give the webmaster a link to the club Drupal's tutorials " |
||
969 | echo "- Create a node of type \"Site\" on default" |
||
970 | 53 | Julien Enselme | echo "- Register the webmaster on webmasters@listes.centrale-marseille.fr" |
971 | 98 | Julien Enselme | echo -e "- If line to add to sites.php differs from the line below, please correct it\n\t$site_line_sites_php" |
972 | 21 | Florent Torregrosa | </code> |
973 | </pre> |
||
974 | |||
975 | h3. d7-delete-site.sh |
||
976 | |||
977 | 84 | Julien Enselme | <pre> |
978 | 21 | Florent Torregrosa | <code class="php"> |
979 | #!/bin/sh |
||
980 | |||
981 | 66 | Julien Enselme | . /users/guest/assos/bin/scripts-config.sh |
982 | 21 | Florent Torregrosa | . scripts-config-site.sh $1 |
983 | 66 | Julien Enselme | . scripts-utils.sh |
984 | 21 | Florent Torregrosa | |
985 | help="# ARGS: site name." |
||
986 | |||
987 | check_arguments $# 1 "$help" |
||
988 | |||
989 | db_password=`ask_password_db $db_server $db_user` |
||
990 | |||
991 | 1 | Julien Enselme | # Delete database. |
992 | 21 | Florent Torregrosa | mysql -h $db_server -u $db_user -p$db_password -e "DROP DATABASE $d7_site_name" |
993 | |||
994 | # Delete MYSQL user. |
||
995 | mysql -h $db_server -u $db_user -p$db_password -e "DROP USER '$d7_site_name'@'%'" |
||
996 | |||
997 | 1 | Julien Enselme | # Delete site's folder. |
998 | 21 | Florent Torregrosa | chmod -R 700 $d7_site_dir |
999 | rm -r $d7_site_dir |
||
1000 | |||
1001 | 1 | Julien Enselme | # Delete symbolic link. |
1002 | rm $d7_dir/$d7_site_name |
||
1003 | 21 | Florent Torregrosa | |
1004 | 99 | Julien Enselme | # Remove site line from sites.php |
1005 | echo '<?php' > $d7_dir_sites/sites.tmp.php |
||
1006 | while read line ; do |
||
1007 | if grep -sv "^\$.*$d7_site_name';$" $line ; then |
||
1008 | echo $line >> sites.tmp.php |
||
1009 | fi |
||
1010 | done |
||
1011 | chmod +w $sites_php |
||
1012 | rm $sites_php |
||
1013 | mv $d7_dir_sites/sites.tmp.php $sites_php |
||
1014 | chmod 400 $sites_php |
||
1015 | |||
1016 | 21 | Florent Torregrosa | # Delete database backups. |
1017 | rm -r $d7_dir_individual_auto_backup/assos.centrale-marseille.fr.$d7_site_name |
||
1018 | rm -r $d7_dir_individual_manual_backup/assos.centrale-marseille.fr.$d7_site_name |
||
1019 | |||
1020 | echo "Don't forget to:" |
||
1021 | echo "- Refresh node site on default" |
||
1022 | 53 | Julien Enselme | echo "- Check particular behavior (normally detailed on site node)" |
1023 | 1 | Julien Enselme | </code> |
1024 | 21 | Florent Torregrosa | </pre> |
1025 | |||
1026 | h3. d7-reset-variables.sh |
||
1027 | |||
1028 | 84 | Julien Enselme | <pre> |
1029 | 21 | Florent Torregrosa | <code class="php"> |
1030 | #!/bin/sh |
||
1031 | |||
1032 | . /users/guest/assos/bin/scripts-config.sh |
||
1033 | |||
1034 | # ARGS: [site_name] |
||
1035 | |||
1036 | 1 | Julien Enselme | if [ ! -z $1 ] ; then |
1037 | 41 | Florent Torregrosa | . scripts-config-site.sh $1 |
1038 | 21 | Florent Torregrosa | cd $d7_site_dir |
1039 | 41 | Florent Torregrosa | fi |
1040 | |||
1041 | 21 | Florent Torregrosa | current_timestamp=`date "+%s"` |
1042 | |||
1043 | random_1=`dd if=/dev/urandom count=1 2> /dev/null | cksum | cut -f1 -d" "` |
||
1044 | random_2=`dd if=/dev/urandom count=1 2> /dev/null | cksum | cut -f1 -d" "` |
||
1045 | 86 | Julien Enselme | |
1046 | 21 | Florent Torregrosa | ####### General variables |
1047 | drush -y vset --always-set reverse_proxy TRUE |
||
1048 | drush -y vset --always-set --format=json reverse_proxy_addresses '["147.94.19.16","147.94.19.17"]' |
||
1049 | 1 | Julien Enselme | drush -y ev "variable_set('update_notify_emails', array('$email_multi_assos'));" |
1050 | 41 | Florent Torregrosa | drush -y vset error_level 0 |
1051 | 21 | Florent Torregrosa | drush -y vset dblog_row_limit 1000 |
1052 | 92 | Julien Enselme | drush -y vset cron_safe_threshold 0 |
1053 | 21 | Florent Torregrosa | |
1054 | ###### Hidden captcha |
||
1055 | drush -y en hidden_captcha |
||
1056 | # Log wrong answers. |
||
1057 | drush -y vset captcha_log_wrong_responses 1 |
||
1058 | # Use hidden captcha for all forms. |
||
1059 | drush -y sqlq --db-prefix "UPDATE {captcha_points} SET module = 'hidden_captcha', captcha_type = 'Hidden CAPTCHA' WHERE module is NULL;" |
||
1060 | # Flush captcha cache. |
||
1061 | drush -y vdel captcha_placement_map_cache |
||
1062 | # Randomely generate a math question as the label of the hidden captcha field. |
||
1063 | drush -y vset hidden_captcha_label "$random_1 + $random_2" |
||
1064 | |||
1065 | 41 | Florent Torregrosa | |
1066 | 21 | Florent Torregrosa | ####### Piwik |
1067 | drush -y en piwik |
||
1068 | drush -y vset piwik_site_id "101" |
||
1069 | drush -y vset piwik_url_http "http://piwik.centrale-marseille.fr/" |
||
1070 | drush -y vset piwik_url_https "https://piwik.centrale-marseille.fr/" |
||
1071 | # Piwik cache. |
||
1072 | drush -y vset piwik_cache 1 |
||
1073 | drush -y vset piwik_visibility_roles "1" |
||
1074 | # Piwik is enable for everyone except the administrator |
||
1075 | drush -y vset --format=json piwik_roles '[3]' |
||
1076 | drush -y vset piwik_page_title_hierarchy 1 |
||
1077 | # Activate local search. |
||
1078 | drush -y vset piwik_site_search 1 |
||
1079 | 41 | Florent Torregrosa | |
1080 | 21 | Florent Torregrosa | |
1081 | ###### Security review |
||
1082 | # For untrusted roles: |
||
1083 | 11 | Julien Enselme | # 1: anonymous user |
1084 | 1 | Julien Enselme | # 2: authenticated user |
1085 | # 3: administrator |
||
1086 | drush -y en security_review |
||
1087 | drush -y ev "variable_set('security_review_untrusted_roles', array('1'));" |
||
1088 | 95 | Florent Torregrosa | drush vset security_review_base_url_method include |
1089 | 1 | Julien Enselme | # Used to initialise entries in the database schema. |
1090 | drush security-review --store |
||
1091 | # Security review can't check for files permissions on multi_assos if launched within the web interface. |
||
1092 | 87 | Julien Enselme | drush -y sqlq --db-prefix "UPDATE {security_review} SET skip = '1', skiptime = $current_timestamp, skipuid = '1' WHERE reviewcheck IN ('file_perms');" |
1093 | drush -y sqlq --db-prefix "UPDATE {security_review} SET skip = '0', skiptime = '0', skipuid = NULL WHERE reviewcheck NOT IN ('file_perms');" |
||
1094 | </code> |
||
1095 | </pre> |
||
1096 | |||
1097 | h3. d7-all-update-settings.sh |
||
1098 | |||
1099 | <pre> |
||
1100 | <code> |
||
1101 | #!/bin/sh |
||
1102 | |||
1103 | . /users/guest/assos/bin/script-config.sh |
||
1104 | . /users/guest/assos/bin/scripts-utils.sh |
||
1105 | |||
1106 | # This script updates all drupal 7 settings.php according to a new template. Site informations located in settings.local.php are left intact. |
||
1107 | |||
1108 | for settings in $(find $d7_dir_sites -mindepth 2 -maxdepth 2 -name settings.php) ; do |
||
1109 | |||
1110 | # We go into the settings.php directory. |
||
1111 | settings_dir=`give_dir $settings` |
||
1112 | cd $settings_dir |
||
1113 | |||
1114 | chmod 700 $settings |
||
1115 | rm $settings |
||
1116 | 1 | Julien Enselme | |
1117 | cp $d7_settings settings.php |
||
1118 | chmod 400 settings.php |
||
1119 | done |