644c82564f9ad5f826b29d8c074c6f997424ba45
[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 en appelant le script "cope_num_version.rb"
23 # - création de unit tests (voir eunit) et validation avant la mise en prod
24
25 # Utilisation :
26 # tools.rb <commande> <args>
27 # commandes :
28 #
29
30 class MiseEnProd
31 @@rep_remote = '/var/www/euphorik'
32 @@host = 'euphorik.ch'
33 @@opt_rsync = ''
34
35 def initialize
36 end
37
38 def creer_remote_rep(rep)
39 begin
40 `ssh #{@@host} "mkdir #{@@rep_remote}/#{rep}"`
41 rescue
42 end
43 end
44
45 def compiler_partie_serveuse
46 Dir.chdir(@@rep_remote + '/modules')
47 puts `make`
48 if $?.exitstatus != 0
49 puts "Echec de compilation de la partie serveuse"
50 exit 1
51 end
52 Dir.chdir('..')
53 end
54
55 def creer_repertoire_bd
56 # création du repertoire BD
57 creer_remote_rep('BD')
58 creer_remote_rep('BD/backup')
59 `ssh #{@@host} "chmod g+w #{@@rep_remote}/BD"`
60 end
61
62 # css, images, html, etc..
63 def copier_partie_statique
64 copier_fichier_html("index.yaws")
65
66 ####print `rsync #{$opt_rsync} index.yaws #{$host}:#{$rep_remote}`
67 #print `rsync #{$opt_rsync} favicon.ico #{$host}:#{$rep_remote}`
68 #print `rsync #{$opt_rsync} -r css #{$host}:#{$rep_remote}`
69 #print `rsync #{$opt_rsync} -r pages #{$host}:#{$rep_remote}`
70 #print `rsync #{$opt_rsync} -r --exclude 'autres' img #{$host}:#{$rep_remote}`
71 end
72
73 # Copie un fichier html, enlève les balises qui ont comme attribut : prod="delete"
74 def copier_fichier_htm(fichier)
75
76 end
77
78 # contrôle des fichiers js à l'aide de jslint
79 # @return false si une erreur est survenue durant la vérification
80 def check_js
81
82 end
83
84 # minification et package des fichiers js dans euphorik.js
85 def pack_js
86 # copie des js avec minification
87 rep_js = 'js'
88 creer_remote_rep(rep_js)
89 Dir.entries(rep_js).each{|fichier|
90 if fichier[0..0] != '.' and fichier != 'debug.js'
91 puts "Minimisation et copie de #{fichier}"
92 print `tools/jsmin.rb < #{rep_js}/#{fichier} | ssh #{@@host} "cat > #{@@rep_remote}/#{rep_js}/#{fichier}"`
93 end
94 }
95 end
96
97 def copie_modules_serveurs
98 # copie des modules erlang
99 creer_remote_rep('modules')
100 `rsync #{@@opt_rsync} -r --exclude 'euphorik_test.beam' modules/ebin #{@@host}:#{@@rep_remote}/modules`
101 `rsync #{@@opt_rsync} -r modules/include #{@@host}:#{@@rep_remote}/modules`
102 end
103
104 def set_droits_fichiers
105 # attribution des droits
106 `ssh #{$host} "chmod -R g+rx #{$rep_remote}"`
107 end
108
109 def maj
110 # execution du script de mise à jour
111 print `cat tools/mise_en_prod.erl | ssh #{$host} "cat > /tmp/mise_en_prod.erl"`
112 print `ssh #{$host} "chmod u+x /tmp/mise_en_prod.erl; /tmp/mise_en_prod.erl; rm /tmp/mise_en_prod.erl"`
113 end
114 end