DEL suppression de la decription du protocole (passé dans le wiki)
[euphorik.git] / tools / tools.rb
1 #!/usr/bin/ruby
2 =begin
3 Copyright 2008 Grégory Burri
4
5 This file is part of Euphorik.
6
7 Euphorik is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 Euphorik is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Euphorik. If not, see <http://www.gnu.org/licenses/>.
19 =end
20
21 #TODO :
22 # - mettre à jour les numéros de versions (créer une classe)
23 # - création de unit tests (voir eunit) et validation avant la mise en prod
24 # - faire une classe qui vérifie tous les js avec jslint
25
26 class MiseEnProd
27 @@rep_remote = '/var/www/euphorik'
28 @@host = 'euphorik.ch'
29 @@opt_rsync = ''
30
31 def initialize
32 end
33
34 def creer_remote_rep(rep)
35 begin
36 `ssh #{@@host} "mkdir #{@@rep_remote}/#{rep}"`
37 rescue
38 end
39 end
40
41 def compiler_partie_serveuse
42 Dir.chdir(@@rep_remote + '/modules')
43 puts `make`
44 if $?.exitstatus != 0
45 puts "Echec de compilation de la partie serveuse"
46 exit 1
47 end
48 Dir.chdir('..')
49 end
50
51 def creer_repertoire_bd
52 # création du repertoire BD
53 creer_remote_rep('BD')
54 creer_remote_rep('BD/backup')
55 `ssh #{@@host} "chmod g+w #{@@rep_remote}/BD"`
56 end
57
58 # css, images, html, etc..
59 def copier_partie_statique
60 print `rsync #{$opt_rsync} index.yaws #{$host}:#{$rep_remote}`
61 print `rsync #{$opt_rsync} favicon.ico #{$host}:#{$rep_remote}`
62 print `rsync #{$opt_rsync} -r css #{$host}:#{$rep_remote}`
63 print `rsync #{$opt_rsync} -r pages #{$host}:#{$rep_remote}`
64 print `rsync #{$opt_rsync} -r --exclude 'autres' img #{$host}:#{$rep_remote}`
65 end
66
67 # contrôle des fichiers js à l'aide de jslint
68 # @return false si une erreur est survenue durant la vérification
69 def check_js
70
71 end
72
73 # minification et package des fichiers js dans euphorik.js
74 def pack_js
75 # copie des js avec minification
76 rep_js = 'js'
77 creer_remote_rep(rep_js)
78 Dir.entries(rep_js).each{|fichier|
79 if fichier[0..0] != '.' and fichier != 'debug.js'
80 puts "Minimisation et copie de #{fichier}"
81 print `tools/jsmin.rb < #{rep_js}/#{fichier} | ssh #{@@host} "cat > #{@@rep_remote}/#{rep_js}/#{fichier}"`
82 end
83 }
84 end
85
86 def copie_modules_serveurs
87 # copie des modules erlang
88 creer_remote_rep('modules')
89 `rsync #{@@opt_rsync} -r --exclude 'euphorik_test.beam' modules/ebin #{@@host}:#{@@rep_remote}/modules`
90 `rsync #{@@opt_rsync} -r modules/include #{@@host}:#{@@rep_remote}/modules`
91 end
92
93 def set_droits_fichiers
94 # attribution des droits
95 `ssh #{$host} "chmod -R g+rx #{$rep_remote}"`
96 end
97
98 def maj
99 # execution du script de mise à jour
100 print `cat tools/mise_en_prod.erl | ssh #{$host} "cat > /tmp/mise_en_prod.erl"`
101 print `ssh #{$host} "chmod u+x /tmp/mise_en_prod.erl; /tmp/mise_en_prod.erl; rm /tmp/mise_en_prod.erl"`
102 end
103 end