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