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