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