primarily gpl3 changes, license changed, license included, images added
[software/sisu] / Rantfile
1 #!/usr/bin/env ruby
2 raise 'Please, use ruby1.8.4 or later.' if RUBY_VERSION < '1.8.4'
3 =begin
4 Rantfile installer for SiSU
5 * Homepage: <http://www.jus.uio.no/sisu/SiSU> <http://www.sisudoc.org>
6 * Download: <http://www.jus.uio.no/sisu/download>
7
8
9 Copyright (C) 2007 Ralph Amissah
10
11 * License: LGPL - GNU Lesser General Public License
12 [same license as Rant provided within the Rant package]
13
14 * Ralph Amissah <ralph@amissah.com>
15 Ralph Amissah <ralph.amissah@gmail.com>
16
17 Rant is a Ruby 'ant' by Stefan Lang
18 * Rant may be downloaded and installed from:
19 http://make.rubyforge.org/
20
21 Notes on use:
22
23 rant -T
24
25 SiSU can also be Setup/Installation using:
26 * Minero Aoki's setup.rb, provided along with SiSU, or
27
28 =end
29 #%% produce a makefile suitable for the target platform
30 #require 'mkmf'
31 #create_makefile("sisu")
32 require 'find'
33 require 'fileutils'
34 require 'rbconfig.rb'
35 include FileUtils
36 @dir=Hash.new
37 @proj=Hash.new
38 #%% project specific variables
39 @proj[:name]='SiSU'
40 @proj[:rant]="Rantfile for the installation/setup of #{@proj[:name]}"
41 @proj[:platform_notice]="[#{@proj[:name]} is for the Linux/Unix Platforms]"
42 @dir[:proj]='sisu'
43 Version=` pwd | grep -o "[0-9]+\.[0-9]+\.[0-9]+$" | grep -o "^[0-9]+\.[0-9]+"` #%% NOTE placing version number permits fine grained removal of version directories if used in lib and conf / etc
44 #%% system configuration
45 @env=Config::CONFIG
46 PKG_VERSION=Version
47 @dir[:version]=Version
48 @host=@env['host']
49 @dir[:arch]=@env['archdir']
50 @dir[:sitearch]=@env['sitearchdir']
51 @dir[:bin]=@env['bindir']
52 #@dir_lib=@env['rubylibdir']
53 @dir[:lib]=@env['sitelibdir']
54 #@dir_lib='/usr/local/lib/site_ruby/1.9' #@env['sitelibdir']
55 @dir[:data]=@env['datadir']
56 @dir[:share]="#{@env['datadir']}/sisu"
57 @dir[:conf]=@env['sysconfdir'] #etc
58 @dir[:man]=@env['mandir']
59 @dir[:vim]="#{@env['datadir']}/sisu/vim"
60 @dir[:out]="#{@env['localstatedir']}/#{@dir[:proj]}"
61 @rubylib=@env['LIBRUBYARG_SHARED']
62 @pwd=Dir.pwd
63 def answer?(ask)
64 resp='redo'
65 print ask + " ['yes', 'no' or 'quit']: "
66 resp=File.new('/dev/tty').gets.strip
67 #resp=gets.strip
68 ans=if resp == 'yes'; true
69 elsif resp == 'no'; false
70 elsif resp =~/^quit|exit$/; exit
71 else puts "[please type: 'yes', 'no' or 'quit']"
72 answer?(ask)
73 end
74 end
75 def default_notice
76 ans= %{#{@proj[:rant]}
77 Information on alternative actions is available using:
78 "rant help" or "rant -T"
79 Default action selected - "install and to setup #{@proj[:name]}" proceed? }
80 resp=answer?(ans)
81 exit unless resp
82 end
83 def get_username
84 gets.strip
85 end
86 def chmod_file(place)
87 if place =~/\/bin/; File.chmod(0755,place)
88 else File.chmod(0644,place)
89 end
90 end
91 def chmod_util(place)
92 if place =~/\/bin/; chmod(0755,place)
93 else chmod(0644,place)
94 end
95 end
96 #%% using a directory and its mapping
97 def setup_find_create(dir_get,dir_put) #primary,
98 Find.find("#@pwd/#{dir_get}") do |f|
99 stub=f.scan(/#@pwd\/#{dir_get}\/(\S+)/).join
100 place="#{dir_put}/#{stub}"
101 action=case
102 when File.file?(f)
103 cp(f,place)
104 chmod_file(place)
105 "-> #{dir_put}/"
106 when File.directory?(f)
107 FileUtils.mkpath(place) unless FileTest.directory?(place)
108 "./#{dir_get}/"
109 else '?'
110 end
111 puts "#{action}#{stub}"
112 end
113 end
114 def setup_find_cp_r(dir_get,dir_put) #secondary, using recursive copy
115 Find.find("#@pwd/#{dir_get}") do |f|
116 stub=f.scan(/#@pwd\/#{dir_get}\/(\S+)/).join
117 place="#{dir_put}/#{stub}"
118 case
119 when File.file?(f)
120 cp_r(f,place)
121 chmod_util(place)
122 when File.directory?(f)
123 mkdir(place) unless FileTest.directory?(place)
124 end
125 end
126 end
127 def rant_system_info
128 puts <<WOK
129 #{@proj[:platform_notice]}
130
131 Host
132 host: #@host
133 arch: #{@dir[:arch]}
134 sitearch: #{@dir[:sitearch]}
135
136 Directories for installation
137 bin: #{@dir[:bin]}
138 lib (site-ruby): #{@dir[:lib]}/#{@dir[:proj]}/#{Version}
139 conf [etc]: #{@dir[:conf]}/#{@dir[:proj]}
140 data (odf, shared images): #{@dir[:share]}
141 vim (vim syntax, highlighting, ftplugin): #{@dir[:data]}/sisu/vim
142 data (README, version_manifest): #{@dir[:data]}/doc/#{@dir[:proj]}
143 man (manual pages): #{@dir[:man]}
144 output: #{@dir[:out]}
145 processing: #{@dir[:out]}/processing
146 www: #{@dir[:out]}/www
147
148 rubylib: #@rubylib
149
150 WOK
151 end
152 def rant_project_help
153 puts <<WOK
154
155 #{@proj[:name]}
156 #{@proj[:rant]}
157 #{@proj[:platform_notice]}
158
159 Commands quick start list
160
161 #{@proj[:name]} Rant Help: (This Rantfile uses the same directory structure as setup.rb)
162 rant -T # a task list, (generated by Rant) for more complete and up to date help
163 rant system # system info used
164
165 Quick start install and remove project #{@proj[:name]}
166 as root:
167 rant # install #{@proj[:name]}
168
169 rant setup # install #{@proj[:name]} (without additonal configuration and generating of test file)
170
171 rant reinstall # reinstall #{@proj[:name]}
172
173 rant remove # clobber/remove #{@proj[:name]}, current version: #{Version}
174 rant remove_package # clobber/remove #{@proj[:name]}, all versions
175
176 For a more detailed and up to date list of command options use
177
178 rant -T
179
180 WOK
181 end
182 def rant_tasks
183 sys('rant -T')
184 end
185 #%% tasks
186 desc "rant (as root type 'rant' for default action)"
187 task :default => [:default_notice,:project]
188 #task :default => [:help,:notice,:project]
189 desc "Setup/Install #{@proj[:name]} and try generate a file"
190 task :project=> [:setup_bin,:setup_lib,:setup_conf,:setup_share,:setup_data,:setup_man,:setup_vim,:post_install_note]
191 desc "Setup/Install #{@proj[:name]}"
192 task :setup=> [:setup_bin, :setup_lib,:setup_conf,:setup_share,:setup_data,:post_install] #, :help]
193 desc "Setup/Install #{@proj[:name]}: bin, lib and conf (no data)"
194 task :setup_base=> [:setup_bin,:setup_lib,:setup_conf,:setup_share,:setup_man,:setup_vim]
195 desc "Setup/Install #{@proj[:name]} bin, lib and conf (no data and no attempt to do postinstall setup)"
196 task :base=> [:setup_base]
197 if File.directory?('bin') #bin
198 desc "Setup #{@proj[:name]} bin only, synonym :bin"
199 task :setup_bin => [:setup_bin]
200 task :bin => [:setup_bin]
201 end
202 if File.directory?('lib') #lib
203 desc "Setup #{@proj[:name]} lib only, synonym :lib"
204 task :setup_lib => [:setup_lib]
205 task :lib => [:setup_lib]
206 end
207 if File.directory?('conf') #conf or etc
208 desc "Setup #{@proj[:name]} conf only, synonyms :conf & :etc"
209 task :setup_conf => [:setup_conf]
210 task :conf => [:setup_conf]
211 task :setup_etc => [:setup_conf]
212 task :etc => [:setup_conf]
213 end
214 if File.directory?('data') #data
215 desc "Setup #{@proj[:name]} data only, synonyms :data & :examples"
216 task :setup_data => [:setup_data]
217 task :data => [:setup_data]
218 task :setup_examples => [:setup_data]
219 task :examples => [:setup_data]
220 end
221 if File.directory?('data/sisu') #share (odf shared-images)
222 desc "Setup #{@proj[:name]} shared data only (odf & shared images)"
223 task :setup_share => [:setup_share]
224 task :share => [:setup_share]
225 end
226 if File.directory?('man') #man pages
227 desc "Setup #{@proj[:name]} man pages only, synonyms :man"
228 task :setup_man => [:setup_man]
229 task :man => [:setup_man]
230 end
231 if File.directory?('data/vim') #man pages
232 desc "Setup #{@proj[:name]} vim config files only, synonyms :vim"
233 task :setup_vim => [:setup_vim]
234 task :vim => [:setup_vim]
235 end
236 desc "Setup/Install #{@proj[:name]}: bin, lib, conf and data (no attempt to do postinstall setup)"
237 task :setup_only=> [:setup_bin,:setup_lib,:setup_conf,:setup_share,:setup_data,:help]
238 #desc "Remove #{@proj[:name]} version: #{Version}"
239 #task :remove => [:remove_version]
240 desc "Remove #{@proj[:name]} (all versions)" #remove project
241 task :remove_package => [:remove_bin, :remove_lib, :remove_conf]
242 if File.directory?('bin') #bin
243 desc "Remove #{@proj[:name]} bin only" #remove bin
244 task :remove_bin => [:remove_bin]
245 end
246 if File.directory?('lib') #lib
247 desc "Remove #{@proj[:name]} lib only" #remove lib
248 task :remove_lib => [:remove_lib]
249 end
250 if File.directory?('conf') #conf
251 desc "Remove #{@proj[:name]} conf only" #remove conf
252 task :remove_conf => [:remove_conf]
253 end
254 #if File.directory?('data') #data
255 # desc "Remove #{@proj[:name]} data only" #remove data
256 # task :remove_data => [:remove_data]
257 #end
258 desc "Re-setup #{@proj[:name]}, synonym :reinstall" #resetup reinstall
259 task :resetup => [:remove, :setup]
260 task :reinstall => [:remove, :setup]
261 desc "Re-setup #{@proj[:name]}: bin, lib, conf (ignore data), synonym :reinstall" #partial reinstall
262 task :resetup_base => [:remove, :setup_base]
263 task :reinstall_base => [:remove, :setup_base]
264 if File.directory?('bin') #bin
265 desc "Re-setup #{@proj[:name]} bin, synonym :reinstall"
266 task :resetup_bin => [:remove_bin, :setup_bin]
267 task :reinstall_bin => [:remove_bin, :setup_bin]
268 end
269 if File.directory?('lib') #lib
270 desc "Re-setup #{@proj[:name]} lib, synonym :reinstall_lib"
271 task :resetup_lib => [:remove_lib, :setup_lib]
272 task :reinstall_lib => [:remove_lib, :setup_lib]
273 end
274 if File.directory?('conf') #conf
275 desc "Re-setup #{@proj[:name]} conf, synonyms :reinstall_conf & :resetup_etc"
276 task :resetup_conf => [:remove_conf, :setup_conf]
277 task :reinstall_conf => [:remove_conf, :setup_conf]
278 task :resetup_etc => [:remove_conf, :setup_conf]
279 task :reinstall_etc => [:remove_conf, :setup_conf]
280 end
281 if File.directory?('data/sisu') #share
282 desc "Re-setup #{@proj[:name]} shared data, (odf & images)"
283 task :resetup_share => [:remove_share, :setup_share]
284 task :reinstall_share => [:remove_share, :setup_share]
285 end
286 if File.directory?('man') #man
287 desc "Re-setup #{@proj[:name]} man, synonym :reinstall_man"
288 task :resetup_man => [:remove_man, :setup_man]
289 task :reinstall_man => [:remove_man, :setup_man]
290 end
291 desc "Setup Note"
292 task :setup_note => [:help]
293 desc "Note on post installation" #remove conf
294 task :post_install_note => [:post_install_note]
295 desc "System information used by #{@proj[:name]}"
296 task :system => [:system_info,:project_help,:post_install_note]
297 desc "show all system info available - parameters found"
298 task :system_param => [:system_param]
299 desc "Help"
300 task :help => [:project_help,:system_info,:rant_tasks,:pi?]
301 #desc "Setup/Install #{@proj[:name]} (uses filelist)"
302 task :install => [:default_notice,:project]
303 task :install_bin => [:setup_bin]
304 desc "[make rant install file]"
305 task :create_rant_independent_task_file => [:rant_independence]
306 #%% setup/install tasks
307 task :rant_independence do #notice
308 resp=''
309 while resp.length < 4
310 resp='install' #default name install
311 print %{#{@proj[:rant]}
312 Create a rant dependency independent file
313 provide filename default name is "install"
314 [Warning, will overwrite file of name provided
315 provide name or "quit" to exit]: }
316 #res=File.new('/dev/tty').gets.strip
317 #resp=res if res =~/\S{4,30}/
318 exit if resp =~/^(?:n|quit|exit)$/
319 end
320 remove='y' #remove='n'
321 #remove=if FileTest.file?(resp)
322 # print "a file of the same name #{resp} exists, [y] to replace: "
323 # File.new('/dev/tty').gets.strip
324 #else 'y'
325 #end
326 if remove =~/y/; system("rant-import --force --auto #{resp}\n")
327 #puts "#{resp} updated"
328 else #puts "#{resp} not replaced"
329 end
330 end
331
332 task :default_notice do #notice
333 default_notice
334 end
335 task :rant_default2 do #secondary
336 setup_find_cp_r('bin',@dir[:bin]) if File.directory?('bin')
337 setup_find_cp_r('lib',@dir[:lib]) if File.directory?('lib')
338 setup_find_cp_r('conf',@dir[:conf]) if File.directory?('conf')
339 setup_find_cp_r('data/sisu',"#{@dir[:share]}") if File.directory?('data/sisu') #
340 setup_find_cp_r('data',@dir[:data]) if File.directory?('data')
341 setup_find_cp_r('data/vim',"#{@dir[:data]}/vim") if File.directory?('data/vim')
342 setup_find_cp_r('man',@dir[:man]) if File.directory?('man')
343 end
344 task :setup_bin do #bin
345 setup_find_create('bin',@dir[:bin]) if File.directory?('bin')
346 end
347 task :setup_lib do #lib
348 setup_find_create('lib',@dir[:lib]) if File.directory?('lib')
349 end
350 task :setup_conf do #conf
351 setup_find_create('conf',@dir[:conf]) if File.directory?('conf')
352 end
353 task :setup_share do #share
354 setup_find_create('data/sisu',@dir[:share]) if File.directory?('data/sisu')
355 end
356 task :setup_data do #data
357 setup_find_create('data',@dir[:data]) if File.directory?('data')
358 end
359 task :setup_man do #man
360 setup_find_create('man',@dir[:man]) if File.directory?('man') #man pages
361 setup_find_create('man.deb/man',@dir[:man]) if File.directory?('man.deb/man') #man pages
362 end
363 task :setup_vim do #man
364 setup_find_create('data/vim',@dir[:vim]) if File.directory?('data/vim') #man pages
365 end
366 #%% post install
367 #%% clobber/remove tasks
368 task :remove_bin do
369 rm_r "#{@dir[:bin]}/#{@dir[:proj]}" if FileTest.file?("#{@dir[:bin]}/#{@dir[:proj]}")
370 end
371 task :remove_lib do
372 rm_r "#{@dir[:lib]}/#{@dir[:proj]}" if FileTest.directory?("#{@dir[:lib]}/#{@dir[:proj]}")
373 end
374 task :remove_conf do
375 rm_r "#{@dir[:conf]}/#{@dir[:proj]}" if FileTest.directory?("#{@dir[:conf]}/#{@dir[:proj]}")
376 end
377 #task :remove_data do
378 # rm_r "#{@dir[:data]}/#{@dir[:proj_eg]}" if FileTest.directory?("#{@dir[:data]}/#{@dir[:proj_eg]}")
379 #end
380 task :remove_man do
381 rm_r "#{@dir[:man]}/**/#{@dir[:proj]}" if FileTest.directory?("#{@dir[:man]}/man1/#{@dir[:proj]}")
382 end
383 task :remove_version do
384 rm_r "#{@dir[:bin]}/#{@dir[:proj]}" if FileTest.file?("#{@dir[:bin]}/#{@dir[:proj]}")
385 rm_r "#{@dir[:lib]}/#{@dir[:proj]}/#{Version}" if FileTest.directory?("#{@dir[:lib]}/#{@dir[:proj]}/#{Version}")
386 rm_r "#{@dir[:conf]}/#{@dir[:proj]} if FileTest.directory?("#{@dir[:conf]}/#{@dir[:proj]}")
387 #rm_r "#@dir_data/#{@dir[:proj]}"
388 end
389 task :remove_package do
390 rm_r "#{@dir[:bin]}/#{@dir[:proj]}" if FileTest.file?("#{@dir[:bin]}/#{@dir[:proj]}")
391 rm_r "#{@dir[:lib]}/#{@dir[:proj]}" if FileTest.directory?("#{@dir[:lib]}/#{@dir[:proj]}")
392 rm_r "#{@dir[:conf]}/#{@dir[:proj]}" if FileTest.directory?("#{@dir[:conf]}/#{@dir[:proj]}")
393 end
394 task :post_install_note do
395 puts <<WOK
396
397 sisu markup samples are now packaged separately in sisu-markup-samples
398 visit:
399 http://www.jus.uio.no/sisu
400 and:
401 http://www.jus.uio.no/sisu/SiSU/download
402
403 WOK
404 end
405 task :system_info do #%% system info
406 rant_system_info
407 end
408 task :system_param do
409 @env.each {|c| puts c.inspect }
410 end
411 task :project_help do #%% help
412 rant_project_help
413 end
414 task :rant_tasks do #%% help
415 rant_tasks
416 end