minor cleaning of rant file
[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 mapping setup.rb directory structure
5
6 SiSU Simple information Structuring Universe, Serialised information, Structured Units
7 * SiSU at present is for the Linux/Unix platform
8 * See homepage at: << http://www.jus.uio.no/sisu/SiSU >>
9 * & << http://www.jus.uio.no/sisu/download >>
10
11 Rant is a Ruby 'ant' by Stefan Lang
12
13 For Setup/Installation SiSU uses either:
14 * Minero Aoki's setup.rb, provided along with SiSU, or
15 * Rant which may be downloaded and installed from:
16 http://make.rubyforge.org/
17
18 * Name: Rant install/setup file for SiSU - Simple information Structuring Universe, Serialised information Structured Units
19 *
20 * Author: Ralph@Amissah.com
21 * Description: Rant install/setup file which maps directory structure used by setup.rb
22 * arch-tag: Rant install/setup file which maps directory structure used by setup.rb
23 * $Id$
24
25 Copyright (C) 2005 Ralph Amissah (first release edition)
26 Copyright (C) 1997 Ralph Amissah (first edition)
27
28 * License: GPL 2 or later
29
30 Summary of GPL 2
31
32 This program is free software; you can redistribute it and/or modify it
33 under the terms of the GNU General Public License as published by the Free
34 Software Foundation; either version 2 of the License, or (at your option)
35 any later version.
36
37 This program is distributed in the hope that it will be useful, but WITHOUT
38 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
39 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
40 more details.
41
42 You should have received a copy of the GNU General Public License along
43 with this program; if not, write to the Free Software Foundation, Inc.,
44 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
45
46 If you have Internet connection, the latest version of the GPL should be
47 available at these locations:
48 http://www.fsf.org/licenses/gpl.html
49 http://www.gnu.org/copyleft/gpl.html
50 http://www.jus.uio.no/sisu/gpl2.fsf
51
52 SiSU was first released to the public on January 4th 2005
53
54 SiSU uses:
55
56 * Standard SiSU markup syntax,
57 * Standard SiSU meta-markup syntax, and the
58 * Standard SiSU object citation numbering and system
59
60 © Ralph Amissah 1997, current 2005.
61 All Rights Reserved.
62
63 * Ralph Amissah mailto:ralph@amissah.com
64 Ralph Amissah mailto:amissah@gmail.com
65
66 * NOTE reminder to create independent setup file called install:
67 rant-import --auto install
68 then you can, as root (for default action):
69 ruby install
70 or for help on alternative actions:
71 ruby install help
72 ruby install -T
73
74 =end
75 #%% produce a makefile suitable for the target platform
76 #require 'mkmf'
77 #create_makefile("sisu")
78 require 'find'
79 require 'fileutils'
80 require 'rbconfig.rb'
81 include FileUtils
82 @dir=Hash.new
83 @proj=Hash.new
84 #%% project specific variables
85 @proj[:name]='SiSU'
86 @proj[:rant]="Rantfile for the installation/setup of #{@proj[:name]}"
87 @proj[:platform_notice]="[#{@proj[:name]} is for the Linux/Unix Platforms]"
88 @dir[:proj]='sisu'
89 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
90 #%% system configuration
91 @env=Config::CONFIG
92 PKG_VERSION=Version
93 @dir[:version]=Version
94 @host=@env['host']
95 @dir[:arch]=@env['archdir']
96 @dir[:sitearch]=@env['sitearchdir']
97 @dir[:bin]=@env['bindir']
98 #@dir_lib=@env['rubylibdir']
99 @dir[:lib]=@env['sitelibdir']
100 #@dir_lib='/usr/local/lib/site_ruby/1.9' #@env['sitelibdir']
101 @dir[:data]=@env['datadir']
102 @dir[:share]="#{@env['datadir']}/sisu"
103 @dir[:conf]=@env['sysconfdir'] #etc
104 @dir[:man]=@env['mandir']
105 @dir[:vim]="#{@env['datadir']}/sisu/vim"
106 @dir[:out]="#{@env['localstatedir']}/#{@dir[:proj]}"
107 @rubylib=@env['LIBRUBYARG_SHARED']
108 @pwd=Dir.pwd
109 def answer?(ask)
110 resp='redo'
111 print ask + " ['yes', 'no' or 'quit']: "
112 resp=File.new('/dev/tty').gets.strip
113 #resp=gets.strip
114 ans=if resp == 'yes'; true
115 elsif resp == 'no'; false
116 elsif resp =~/^quit|exit$/; exit
117 else puts "[please type: 'yes', 'no' or 'quit']"
118 answer?(ask)
119 end
120 end
121 def default_notice
122 ans= %{#{@proj[:rant]}
123 Information on alternative actions is available using:
124 "rant help" or "rant -T"
125 Default action selected - "install and to setup #{@proj[:name]}" proceed? }
126 resp=answer?(ans)
127 exit unless resp
128 end
129 def get_username
130 gets.strip
131 end
132 def chmod_file(place)
133 if place =~/\/bin/; File.chmod(0755,place)
134 else File.chmod(0644,place)
135 end
136 end
137 def chmod_util(place)
138 if place =~/\/bin/; chmod(0755,place)
139 else chmod(0644,place)
140 end
141 end
142 #%% using a directory and its mapping
143 def setup_find_create(dir_get,dir_put) #primary,
144 Find.find("#@pwd/#{dir_get}") do |f|
145 stub=f.scan(/#@pwd\/#{dir_get}\/(\S+)/).join
146 place="#{dir_put}/#{stub}"
147 action=case
148 when File.file?(f)
149 cp(f,place)
150 chmod_file(place)
151 "-> #{dir_put}/"
152 when File.directory?(f)
153 FileUtils.mkpath(place) unless FileTest.directory?(place)
154 "./#{dir_get}/"
155 else '?'
156 end
157 puts "#{action}#{stub}"
158 end
159 end
160 def setup_find_cp_r(dir_get,dir_put) #secondary, using recursive copy
161 Find.find("#@pwd/#{dir_get}") do |f|
162 stub=f.scan(/#@pwd\/#{dir_get}\/(\S+)/).join
163 place="#{dir_put}/#{stub}"
164 case
165 when File.file?(f)
166 cp_r(f,place)
167 chmod_util(place)
168 when File.directory?(f)
169 mkdir(place) unless FileTest.directory?(place)
170 end
171 end
172 end
173 #%% using a single filelist
174 #filelist broken in switch to rant from rake
175 #filelist=Rant::FileList.new('bin/*','lib/**/*','conf/**/*','data/**/*','man/**/*')
176 #filelist=Rant::FileList.new('bin/*','lib/**/*','conf/**/*','data/**/*','data/man/**/*')
177 def dest(f) #filelist mapping - note currently does not get 'data/man'
178 stub=f.scan(/^\S+?\/(\S+)/).join
179 place=case f
180 when /^bin/; "#{@dir[:bin]}/#{stub}"
181 when /^lib/; "#{@dir[:lib]}/#{stub}"
182 when /^conf/; "#{@dir[:conf]}/#{stub}"
183 when /^data/; "#{@dir[:data]}/#{stub}" unless f =~/^data\/sisu/
184 when /^share/; "#{@dir[:share]}"
185 when /^man/; "#{@dir[:man]}/#{stub}"
186 when /^vim/; "#{@dir[:conf]}/#{stub}/vim"
187 else 'ERROR' #change
188 end
189 end
190 def setup_filelist_cp_r(filelist) #secondary, using recursive copy
191 filelist.sort.each do |f|
192 place=dest(f)
193 case
194 when File.file?(f)
195 cp_r(f,place)
196 chmod_util(place)
197 when File.directory?(f)
198 mkdir(place) unless FileTest.directory?(place)
199 end
200 end
201 end
202 def setup_filelist_create(filelist) #secondary
203 filelist.sort.each do |f|
204 place=dest(f)
205 action=case
206 when File.file?(f)
207 cp(f,place)
208 chmod_file(place)
209 "-> #{place}"
210 when File.directory?(f)
211 p place
212 File.mkpath(place) unless FileTest.directory?(place)
213 ".#{place}/"
214 else '?'
215 end
216 puts action
217 end
218 end
219 def rant_system_info
220 puts <<WOK
221 #{@proj[:platform_notice]}
222
223 Host
224 host: #@host
225 arch: #{@dir[:arch]}
226 sitearch: #{@dir[:sitearch]}
227
228 Directories for installation
229 bin: #{@dir[:bin]}
230 lib (site-ruby): #{@dir[:lib]}/#{@dir[:proj]}/#{Version}
231 conf [etc]: #{@dir[:conf]}/#{@dir[:proj]}
232 data (odf, shared images): #{@dir[:share]}
233 vim (vim syntax, highlighting, ftplugin): #{@dir[:data]}/sisu/vim
234 data (README, version_manifest): #{@dir[:data]}/doc/#{@dir[:proj]}
235 man (manual pages): #{@dir[:man]}
236 output: #{@dir[:out]}
237 processing: #{@dir[:out]}/processing
238 www: #{@dir[:out]}/www
239
240 rubylib: #@rubylib
241
242 WOK
243 end
244 def rant_project_help
245 puts <<WOK
246
247 #{@proj[:name]}
248 #{@proj[:rant]}
249 #{@proj[:platform_notice]}
250
251 Commands quick start list
252
253 #{@proj[:name]} Rant Help: (This Rantfile uses the same directory structure as setup.rb)
254 rant -T # a task list, (generated by Rant) for more complete and up to date help
255 rant system # system info used
256
257 Quick start install and remove project #{@proj[:name]}
258 as root:
259 rant # install #{@proj[:name]}
260
261 rant setup # install #{@proj[:name]} (without additonal configuration and generating of test file)
262
263 rant reinstall # reinstall #{@proj[:name]}
264
265 rant remove # clobber/remove #{@proj[:name]}, current version: #{Version}
266 rant remove_package # clobber/remove #{@proj[:name]}, all versions
267
268 For a more detailed and up to date list of command options use
269
270 rant -T
271
272 WOK
273 end
274 def rant_tasks
275 sys('rant -T')
276 end
277 #%% tasks
278 desc "rant (as root type 'rant' for default action)"
279 task :default => [:default_notice,:project]
280 #task :default => [:help,:notice,:project]
281 desc "Setup/Install #{@proj[:name]} and try generate a file"
282 task :project=> [:setup_bin,:setup_lib,:setup_conf,:setup_share,:setup_data,:setup_man,:setup_vim,:post_install_note]
283 desc "Setup/Install #{@proj[:name]}"
284 task :setup=> [:setup_bin, :setup_lib,:setup_conf,:setup_share,:setup_data,:post_install] #, :help]
285 desc "Setup/Install #{@proj[:name]}: bin, lib and conf (no data)"
286 task :setup_base=> [:setup_bin,:setup_lib,:setup_conf,:setup_share,:setup_man,:setup_vim]
287 desc "Setup/Install #{@proj[:name]} bin, lib and conf (no data and no attempt to do postinstall setup)"
288 task :base=> [:setup_base]
289 if File.directory?('bin') #bin
290 desc "Setup #{@proj[:name]} bin only, synonym :bin"
291 task :setup_bin => [:setup_bin]
292 task :bin => [:setup_bin]
293 end
294 if File.directory?('lib') #lib
295 desc "Setup #{@proj[:name]} lib only, synonym :lib"
296 task :setup_lib => [:setup_lib]
297 task :lib => [:setup_lib]
298 end
299 if File.directory?('conf') #conf or etc
300 desc "Setup #{@proj[:name]} conf only, synonyms :conf & :etc"
301 task :setup_conf => [:setup_conf]
302 task :conf => [:setup_conf]
303 task :setup_etc => [:setup_conf]
304 task :etc => [:setup_conf]
305 end
306 if File.directory?('data') #data
307 desc "Setup #{@proj[:name]} data only, synonyms :data & :examples"
308 task :setup_data => [:setup_data]
309 task :data => [:setup_data]
310 task :setup_examples => [:setup_data]
311 task :examples => [:setup_data]
312 end
313 if File.directory?('data/sisu') #share (odf shared-images)
314 desc "Setup #{@proj[:name]} shared data only (odf & shared images)"
315 task :setup_share => [:setup_share]
316 task :share => [:setup_share]
317 end
318 if File.directory?('man') #man pages
319 desc "Setup #{@proj[:name]} man pages only, synonyms :man"
320 task :setup_man => [:setup_man]
321 task :man => [:setup_man]
322 end
323 if File.directory?('data/vim') #man pages
324 desc "Setup #{@proj[:name]} vim config files only, synonyms :vim"
325 task :setup_vim => [:setup_vim]
326 task :vim => [:setup_vim]
327 end
328 desc "Setup/Install #{@proj[:name]}: bin, lib, conf and data (no attempt to do postinstall setup)"
329 task :setup_only=> [:setup_bin,:setup_lib,:setup_conf,:setup_share,:setup_data,:help]
330 #desc "Remove #{@proj[:name]} version: #{Version}"
331 #task :remove => [:remove_version]
332 desc "Remove #{@proj[:name]} (all versions)" #remove project
333 task :remove_package => [:remove_bin, :remove_lib, :remove_conf]
334 if File.directory?('bin') #bin
335 desc "Remove #{@proj[:name]} bin only" #remove bin
336 task :remove_bin => [:remove_bin]
337 end
338 if File.directory?('lib') #lib
339 desc "Remove #{@proj[:name]} lib only" #remove lib
340 task :remove_lib => [:remove_lib]
341 end
342 if File.directory?('conf') #conf
343 desc "Remove #{@proj[:name]} conf only" #remove conf
344 task :remove_conf => [:remove_conf]
345 end
346 #if File.directory?('data') #data
347 # desc "Remove #{@proj[:name]} data only" #remove data
348 # task :remove_data => [:remove_data]
349 #end
350 desc "Re-setup #{@proj[:name]}, synonym :reinstall" #resetup reinstall
351 task :resetup => [:remove, :setup]
352 task :reinstall => [:remove, :setup]
353 desc "Re-setup #{@proj[:name]}: bin, lib, conf (ignore data), synonym :reinstall" #partial reinstall
354 task :resetup_base => [:remove, :setup_base]
355 task :reinstall_base => [:remove, :setup_base]
356 if File.directory?('bin') #bin
357 desc "Re-setup #{@proj[:name]} bin, synonym :reinstall"
358 task :resetup_bin => [:remove_bin, :setup_bin]
359 task :reinstall_bin => [:remove_bin, :setup_bin]
360 end
361 if File.directory?('lib') #lib
362 desc "Re-setup #{@proj[:name]} lib, synonym :reinstall_lib"
363 task :resetup_lib => [:remove_lib, :setup_lib]
364 task :reinstall_lib => [:remove_lib, :setup_lib]
365 end
366 if File.directory?('conf') #conf
367 desc "Re-setup #{@proj[:name]} conf, synonyms :reinstall_conf & :resetup_etc"
368 task :resetup_conf => [:remove_conf, :setup_conf]
369 task :reinstall_conf => [:remove_conf, :setup_conf]
370 task :resetup_etc => [:remove_conf, :setup_conf]
371 task :reinstall_etc => [:remove_conf, :setup_conf]
372 end
373 if File.directory?('data/sisu') #share
374 desc "Re-setup #{@proj[:name]} shared data, (odf & images)"
375 task :resetup_share => [:remove_share, :setup_share]
376 task :reinstall_share => [:remove_share, :setup_share]
377 end
378 if File.directory?('man') #man
379 desc "Re-setup #{@proj[:name]} man, synonym :reinstall_man"
380 task :resetup_man => [:remove_man, :setup_man]
381 task :reinstall_man => [:remove_man, :setup_man]
382 end
383 desc "Setup Note"
384 task :setup_note => [:help]
385 desc "Note on post installation" #remove conf
386 task :post_install_note => [:post_install_note]
387 desc "System information used by #{@proj[:name]}"
388 task :system => [:system_info,:project_help,:post_install_note]
389 desc "show all system info available - parameters found"
390 task :system_param => [:system_param]
391 desc "Help"
392 task :help => [:project_help,:system_info,:rant_tasks,:pi?]
393 #desc "Setup/Install #{@proj[:name]} (uses filelist)"
394 task :install => [:default_notice,:project]
395 #:install uses filelist which was broken in switch to rant from rake, look at later
396 #task :install => [:install]
397 task :install_a => [:rant_default1]
398 task :install_b => [:rant_default2]
399 task :install_bin => [:setup_bin]
400 desc "[make rant install file]"
401 task :create_rant_independent_task_file => [:rant_independence]
402 #%% setup/install tasks
403
404 task :rant_independence do #notice
405 resp=''
406 while resp.length < 4
407 resp='install' #default name install
408 print %{#{@proj[:rant]}
409 Create a rant dependency independent file
410 provide filename default name is "install"
411 [Warning, will overwrite file of name provided
412 provide name or "quit" to exit]: }
413 #res=File.new('/dev/tty').gets.strip
414 #resp=res if res =~/\S{4,30}/
415 exit if resp =~/^(?:n|quit|exit)$/
416 end
417 remove='y' #remove='n'
418 #remove=if FileTest.file?(resp)
419 # print "a file of the same name #{resp} exists, [y] to replace: "
420 # File.new('/dev/tty').gets.strip
421 #else 'y'
422 #end
423 if remove =~/y/; system("rant-import --force --auto #{resp}\n")
424 #puts "#{resp} updated"
425 else #puts "#{resp} not replaced"
426 end
427 end
428
429 task :default_notice do #notice
430 default_notice
431 end
432 task :rant_default1 do #secondary
433 setup_filelist_cp_r(filelist)
434 end
435 task :rant_default2 do #secondary
436 setup_find_cp_r('bin',@dir[:bin]) if File.directory?('bin')
437 setup_find_cp_r('lib',@dir[:lib]) if File.directory?('lib')
438 setup_find_cp_r('conf',@dir[:conf]) if File.directory?('conf')
439 setup_find_cp_r('data/sisu',"#{@dir[:share]}") if File.directory?('data/sisu') #
440 setup_find_cp_r('data',@dir[:data]) if File.directory?('data')
441 setup_find_cp_r('data/vim',"#{@dir[:data]}/vim") if File.directory?('data/vim')
442 setup_find_cp_r('man',@dir[:man]) if File.directory?('man')
443 end
444 task :install do #secondary
445 setup_filelist_create(filelist)
446 end
447 task :setup_bin do #bin
448 setup_find_create('bin',@dir[:bin]) if File.directory?('bin')
449 end
450 task :setup_lib do #lib
451 setup_find_create('lib',@dir[:lib]) if File.directory?('lib')
452 end
453 task :setup_conf do #conf
454 setup_find_create('conf',@dir[:conf]) if File.directory?('conf')
455 end
456 task :setup_share do #share
457 setup_find_create('data/sisu',@dir[:share]) if File.directory?('data/sisu')
458 end
459 task :setup_data do #data
460 setup_find_create('data',@dir[:data]) if File.directory?('data')
461 end
462 task :setup_man do #man
463 setup_find_create('man',@dir[:man]) if File.directory?('man') #man pages
464 setup_find_create('man.deb/man',@dir[:man]) if File.directory?('man.deb/man') #man pages
465 end
466 task :setup_vim do #man
467 setup_find_create('data/vim',@dir[:vim]) if File.directory?('data/vim') #man pages
468 end
469 #%% post install
470 #%% clobber/remove tasks
471 task :remove_bin do
472 rm_r "#{@dir[:bin]}/#{@dir[:proj]}" if FileTest.file?("#{@dir[:bin]}/#{@dir[:proj]}")
473 end
474 task :remove_lib do
475 rm_r "#{@dir[:lib]}/#{@dir[:proj]}" if FileTest.directory?("#{@dir[:lib]}/#{@dir[:proj]}")
476 end
477 task :remove_conf do
478 rm_r "#{@dir[:conf]}/#{@dir[:proj]}" if FileTest.directory?("#{@dir[:conf]}/#{@dir[:proj]}")
479 end
480 #task :remove_data do
481 # rm_r "#{@dir[:data]}/#{@dir[:proj_eg]}" if FileTest.directory?("#{@dir[:data]}/#{@dir[:proj_eg]}")
482 #end
483 task :remove_man do
484 rm_r "#{@dir[:man]}/**/#{@dir[:proj]}" if FileTest.directory?("#{@dir[:man]}/man1/#{@dir[:proj]}")
485 end
486 task :remove_version do
487 rm_r "#{@dir[:bin]}/#{@dir[:proj]}" if FileTest.file?("#{@dir[:bin]}/#{@dir[:proj]}")
488 rm_r "#{@dir[:lib]}/#{@dir[:proj]}/#{Version}" if FileTest.directory?("#{@dir[:lib]}/#{@dir[:proj]}/#{Version}")
489 rm_r "#{@dir[:conf]}/#{@dir[:proj]} if FileTest.directory?("#{@dir[:conf]}/#{@dir[:proj]}")
490 #rm_r "#@dir_data/#{@dir[:proj]}"
491 end
492 task :remove_package do
493 rm_r "#{@dir[:bin]}/#{@dir[:proj]}" if FileTest.file?("#{@dir[:bin]}/#{@dir[:proj]}")
494 rm_r "#{@dir[:lib]}/#{@dir[:proj]}" if FileTest.directory?("#{@dir[:lib]}/#{@dir[:proj]}")
495 rm_r "#{@dir[:conf]}/#{@dir[:proj]}" if FileTest.directory?("#{@dir[:conf]}/#{@dir[:proj]}")
496 end
497 task :post_install_note do
498 puts <<WOK
499
500 sisu markup samples are now packaged separately in sisu-markup-samples
501 visit:
502 http://www.jus.uio.no/sisu
503 and:
504 http://www.jus.uio.no/sisu/SiSU/download
505
506 WOK
507 end
508 task :system_info do #%% system info
509 rant_system_info
510 end
511 task :system_param do
512 @env.each {|c| puts c.inspect }
513 end
514 task :project_help do #%% help
515 rant_project_help
516 end
517 task :rant_tasks do #%% help
518 rant_tasks
519 end