cgi search script fix, related to highlighting matches, changelog update, rest remova...
[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 PKG_VERSION=Version
92 @dir[:version]=Version
93 @host=Config::CONFIG['host']
94 @dir[:arch]=Config::CONFIG['archdir']
95 @dir[:sitearch]=Config::CONFIG['sitearchdir']
96 @dir[:bin]=Config::CONFIG['bindir']
97 #@dir_lib=Config::CONFIG['rubylibdir']
98 @dir[:lib]=Config::CONFIG['sitelibdir']
99 #@dir_lib='/usr/local/lib/site_ruby/1.9' #Config::CONFIG['sitelibdir']
100 @dir[:data]=Config::CONFIG['datadir']
101 @dir[:share]="#{Config::CONFIG['datadir']}/sisu"
102 @dir[:conf]=Config::CONFIG['sysconfdir'] #etc
103 @dir[:man]=Config::CONFIG['mandir']
104 @dir[:vim]="#{Config::CONFIG['datadir']}/sisu/vim"
105 @dir[:out]="#{Config::CONFIG['localstatedir']}/#{@dir[:proj]}"
106 @rubylib=Config::CONFIG['LIBRUBYARG_SHARED']
107 @pwd=Dir.pwd
108 def answer?(ask)
109 resp='redo'
110 print ask + " ['yes', 'no' or 'quit']: "
111 resp=File.new('/dev/tty').gets.strip
112 #resp=gets.strip
113 ans=if resp == 'yes'; true
114 elsif resp == 'no'; false
115 elsif resp =~/^quit|exit$/; exit
116 else puts "[please type: 'yes', 'no' or 'quit']"
117 answer?(ask)
118 end
119 end
120 def default_notice
121 ans= %{#{@proj[:rant]}
122 Information on alternative actions is available using:
123 "rant help" or "rant -T"
124 Default action selected - "install and to setup #{@proj[:name]}" proceed? }
125 resp=answer?(ans)
126 exit unless resp
127 end
128 def get_username
129 gets.strip
130 end
131 def chmod_file(place)
132 if place =~/\/bin/; File.chmod(0755,place)
133 else File.chmod(0644,place)
134 end
135 end
136 def chmod_util(place)
137 if place =~/\/bin/; chmod(0755,place)
138 else chmod(0644,place)
139 end
140 end
141 #%% using a directory and its mapping
142 def setup_find_create(dir_get,dir_put) #primary,
143 Find.find("#@pwd/#{dir_get}") do |f|
144 stub=f.scan(/#@pwd\/#{dir_get}\/(\S+)/).join
145 place="#{dir_put}/#{stub}"
146 action=case
147 when File.file?(f)
148 cp(f,place)
149 chmod_file(place)
150 "-> #{dir_put}/"
151 when File.directory?(f)
152 FileUtils.mkpath(place) unless FileTest.directory?(place)
153 "./#{dir_get}/"
154 else '?'
155 end
156 puts "#{action}#{stub}"
157 end
158 end
159 def setup_find_cp_r(dir_get,dir_put) #secondary, using recursive copy
160 Find.find("#@pwd/#{dir_get}") do |f|
161 stub=f.scan(/#@pwd\/#{dir_get}\/(\S+)/).join
162 place="#{dir_put}/#{stub}"
163 case
164 when File.file?(f)
165 cp_r(f,place)
166 chmod_util(place)
167 when File.directory?(f)
168 mkdir(place) unless FileTest.directory?(place)
169 end
170 end
171 end
172 #%% using a single filelist
173 #filelist broken in switch to rant from rake
174 #filelist=Rant::FileList.new('bin/*','lib/**/*','conf/**/*','data/**/*','man/**/*')
175 #filelist=Rant::FileList.new('bin/*','lib/**/*','conf/**/*','data/**/*','data/man/**/*')
176 def dest(f) #filelist mapping - note currently does not get 'data/man'
177 stub=f.scan(/^\S+?\/(\S+)/).join
178 place=case f
179 when /^bin/; "#{@dir[:bin]}/#{stub}"
180 when /^lib/; "#{@dir[:lib]}/#{stub}"
181 when /^conf/; "#{@dir[:conf]}/#{stub}"
182 when /^data/; "#{@dir[:data]}/#{stub}" unless f =~/^data\/sisu/
183 when /^share/; "#{@dir[:share]}"
184 when /^man/; "#{@dir[:man]}/#{stub}"
185 when /^vim/; "#{@dir[:conf]}/#{stub}/vim"
186 else 'ERROR' #change
187 end
188 end
189 def setup_filelist_cp_r(filelist) #secondary, using recursive copy
190 filelist.sort.each do |f|
191 place=dest(f)
192 case
193 when File.file?(f)
194 cp_r(f,place)
195 chmod_util(place)
196 when File.directory?(f)
197 mkdir(place) unless FileTest.directory?(place)
198 end
199 end
200 end
201 def setup_filelist_create(filelist) #secondary
202 filelist.sort.each do |f|
203 place=dest(f)
204 action=case
205 when File.file?(f)
206 cp(f,place)
207 chmod_file(place)
208 "-> #{place}"
209 when File.directory?(f)
210 p place
211 File.mkpath(place) unless FileTest.directory?(place)
212 ".#{place}/"
213 else '?'
214 end
215 puts action
216 end
217 end
218 def rant_system_info
219 puts <<WOK
220 #{@proj[:platform_notice]}
221
222 Host
223 host: #@host
224 arch: #{@dir[:arch]}
225 sitearch: #{@dir[:sitearch]}
226
227 Directories for installation
228 bin: #{@dir[:bin]}
229 lib (site-ruby): #{@dir[:lib]}/#{@dir[:proj]}/#{Version}
230 conf [etc]: #{@dir[:conf]}/#{@dir[:proj]}
231 data (odf, shared images): #{@dir[:share]}
232 vim (vim syntax, highlighting, ftplugin): #{@dir[:data]}/sisu/vim
233 data (README, version_manifest): #{@dir[:data]}/doc/#{@dir[:proj]}
234 man (manual pages): #{@dir[:man]}
235 output: #{@dir[:out]}
236 processing: #{@dir[:out]}/processing
237 www: #{@dir[:out]}/www
238
239 rubylib: #@rubylib
240
241 WOK
242 end
243 def rant_project_help
244 puts <<WOK
245
246 #{@proj[:name]}
247 #{@proj[:rant]}
248 #{@proj[:platform_notice]}
249
250 Commands quick start list
251
252 #{@proj[:name]} Rant Help: (This Rantfile uses the same directory structure as setup.rb)
253 rant -T # a task list, (generated by Rant) for more complete and up to date help
254 rant system # system info used
255
256 Quick start install and remove project #{@proj[:name]}
257 as root:
258 rant # install #{@proj[:name]}
259
260 rant setup # install #{@proj[:name]} (without additonal configuration and generating of test file)
261
262 rant reinstall # reinstall #{@proj[:name]}
263
264 rant remove # clobber/remove #{@proj[:name]}, current version: #{Version}
265 rant remove_package # clobber/remove #{@proj[:name]}, all versions
266
267 For a more detailed and up to date list of command options use
268
269 rant -T
270
271 WOK
272 end
273 def rant_tasks
274 sys('rant -T')
275 end
276 #%% tasks
277 desc "rant (as root type 'rant' for default action)"
278 task :default => [:default_notice,:project]
279 #task :default => [:help,:notice,:project]
280 desc "Setup/Install #{@proj[:name]} and try generate a file"
281 task :project=> [:setup_bin,:setup_lib,:setup_conf,:setup_share,:setup_data,:setup_man,:setup_vim,:post_install_note]
282 desc "Setup/Install #{@proj[:name]}"
283 task :setup=> [:setup_bin, :setup_lib,:setup_conf,:setup_share,:setup_data,:post_install] #, :help]
284 desc "Setup/Install #{@proj[:name]}: bin, lib and conf (no data)"
285 task :setup_base=> [:setup_bin,:setup_lib,:setup_conf,:setup_share,:setup_man,:setup_vim]
286 desc "Setup/Install #{@proj[:name]} bin, lib and conf (no data and no attempt to do postinstall setup)"
287 task :base=> [:setup_base]
288 if File.directory?('bin') #bin
289 desc "Setup #{@proj[:name]} bin only, synonym :bin"
290 task :setup_bin => [:setup_bin]
291 task :bin => [:setup_bin]
292 end
293 if File.directory?('lib') #lib
294 desc "Setup #{@proj[:name]} lib only, synonym :lib"
295 task :setup_lib => [:setup_lib]
296 task :lib => [:setup_lib]
297 end
298 if File.directory?('conf') #conf or etc
299 desc "Setup #{@proj[:name]} conf only, synonyms :conf & :etc"
300 task :setup_conf => [:setup_conf]
301 task :conf => [:setup_conf]
302 task :setup_etc => [:setup_conf]
303 task :etc => [:setup_conf]
304 end
305 if File.directory?('data') #data
306 desc "Setup #{@proj[:name]} data only, synonyms :data & :examples"
307 task :setup_data => [:setup_data]
308 task :data => [:setup_data]
309 task :setup_examples => [:setup_data]
310 task :examples => [:setup_data]
311 end
312 if File.directory?('data/sisu') #share (odf shared-images)
313 desc "Setup #{@proj[:name]} shared data only (odf & shared images)"
314 task :setup_share => [:setup_share]
315 task :share => [:setup_share]
316 end
317 if File.directory?('man') #man pages
318 desc "Setup #{@proj[:name]} man pages only, synonyms :man"
319 task :setup_man => [:setup_man]
320 task :man => [:setup_man]
321 end
322 if File.directory?('data/vim') #man pages
323 desc "Setup #{@proj[:name]} vim config files only, synonyms :vim"
324 task :setup_vim => [:setup_vim]
325 task :vim => [:setup_vim]
326 end
327 desc "Setup/Install #{@proj[:name]}: bin, lib, conf and data (no attempt to do postinstall setup)"
328 task :setup_only=> [:setup_bin,:setup_lib,:setup_conf,:setup_share,:setup_data,:help]
329 #desc "Remove #{@proj[:name]} version: #{Version}"
330 #task :remove => [:remove_version]
331 desc "Remove #{@proj[:name]} (all versions)" #remove project
332 task :remove_package => [:remove_bin, :remove_lib, :remove_conf]
333 if File.directory?('bin') #bin
334 desc "Remove #{@proj[:name]} bin only" #remove bin
335 task :remove_bin => [:remove_bin]
336 end
337 if File.directory?('lib') #lib
338 desc "Remove #{@proj[:name]} lib only" #remove lib
339 task :remove_lib => [:remove_lib]
340 end
341 if File.directory?('conf') #conf
342 desc "Remove #{@proj[:name]} conf only" #remove conf
343 task :remove_conf => [:remove_conf]
344 end
345 #if File.directory?('data') #data
346 # desc "Remove #{@proj[:name]} data only" #remove data
347 # task :remove_data => [:remove_data]
348 #end
349 desc "Re-setup #{@proj[:name]}, synonym :reinstall" #resetup reinstall
350 task :resetup => [:remove, :setup]
351 task :reinstall => [:remove, :setup]
352 desc "Re-setup #{@proj[:name]}: bin, lib, conf (ignore data), synonym :reinstall" #partial reinstall
353 task :resetup_base => [:remove, :setup_base]
354 task :reinstall_base => [:remove, :setup_base]
355 if File.directory?('bin') #bin
356 desc "Re-setup #{@proj[:name]} bin, synonym :reinstall"
357 task :resetup_bin => [:remove_bin, :setup_bin]
358 task :reinstall_bin => [:remove_bin, :setup_bin]
359 end
360 if File.directory?('lib') #lib
361 desc "Re-setup #{@proj[:name]} lib, synonym :reinstall_lib"
362 task :resetup_lib => [:remove_lib, :setup_lib]
363 task :reinstall_lib => [:remove_lib, :setup_lib]
364 end
365 if File.directory?('conf') #conf
366 desc "Re-setup #{@proj[:name]} conf, synonyms :reinstall_conf & :resetup_etc"
367 task :resetup_conf => [:remove_conf, :setup_conf]
368 task :reinstall_conf => [:remove_conf, :setup_conf]
369 task :resetup_etc => [:remove_conf, :setup_conf]
370 task :reinstall_etc => [:remove_conf, :setup_conf]
371 end
372 if File.directory?('data/sisu') #share
373 desc "Re-setup #{@proj[:name]} shared data, (odf & images)"
374 task :resetup_share => [:remove_share, :setup_share]
375 task :reinstall_share => [:remove_share, :setup_share]
376 end
377 if File.directory?('man') #man
378 desc "Re-setup #{@proj[:name]} man, synonym :reinstall_man"
379 task :resetup_man => [:remove_man, :setup_man]
380 task :reinstall_man => [:remove_man, :setup_man]
381 end
382 desc "Setup Note"
383 task :setup_note => [:help]
384 desc "Note on post installation" #remove conf
385 task :post_install_note => [:post_install_note]
386 desc "System information used by #{@proj[:name]}"
387 task :system => [:system_info,:project_help,:post_install_note]
388 desc "show all system info available - parameters found"
389 task :system_param => [:system_param]
390 desc "Help"
391 task :help => [:project_help,:system_info,:rant_tasks,:pi?]
392 #desc "Setup/Install #{@proj[:name]} (uses filelist)"
393 task :install => [:default_notice,:project]
394 #:install uses filelist which was broken in switch to rant from rake, look at later
395 #task :install => [:install]
396 task :install_a => [:rant_default1]
397 task :install_b => [:rant_default2]
398 task :install_bin => [:setup_bin]
399 desc "[make rant install file]"
400 task :create_rant_independent_task_file => [:rant_independence]
401 #%% setup/install tasks
402
403 task :rant_independence do #notice
404 resp=''
405 while resp.length < 4
406 resp='install' #default name install
407 print %{#{@proj[:rant]}
408 Create a rant dependency independent file
409 provide filename default name is "install"
410 [Warning, will overwrite file of name provided
411 provide name or "quit" to exit]: }
412 #res=File.new('/dev/tty').gets.strip
413 #resp=res if res =~/\S{4,30}/
414 exit if resp =~/^(?:n|quit|exit)$/
415 end
416 remove='y' #remove='n'
417 #remove=if FileTest.file?(resp)
418 # print "a file of the same name #{resp} exists, [y] to replace: "
419 # File.new('/dev/tty').gets.strip
420 #else 'y'
421 #end
422 if remove =~/y/; system("rant-import --force --auto #{resp}\n")
423 #puts "#{resp} updated"
424 else #puts "#{resp} not replaced"
425 end
426 end
427
428 task :default_notice do #notice
429 default_notice
430 end
431 task :rant_default1 do #secondary
432 setup_filelist_cp_r(filelist)
433 end
434 task :rant_default2 do #secondary
435 setup_find_cp_r('bin',@dir[:bin]) if File.directory?('bin')
436 setup_find_cp_r('lib',@dir[:lib]) if File.directory?('lib')
437 setup_find_cp_r('conf',@dir[:conf]) if File.directory?('conf')
438 setup_find_cp_r('data/sisu',"#{@dir[:share]}") if File.directory?('data/sisu') #
439 setup_find_cp_r('data',@dir[:data]) if File.directory?('data')
440 setup_find_cp_r('data/vim',"#{@dir[:data]}/vim") if File.directory?('data/vim')
441 setup_find_cp_r('man',@dir[:man]) if File.directory?('man')
442 end
443 task :install do #secondary
444 setup_filelist_create(filelist)
445 end
446 task :setup_bin do #bin
447 setup_find_create('bin',@dir[:bin]) if File.directory?('bin')
448 end
449 task :setup_lib do #lib
450 setup_find_create('lib',@dir[:lib]) if File.directory?('lib')
451 end
452 task :setup_conf do #conf
453 setup_find_create('conf',@dir[:conf]) if File.directory?('conf')
454 end
455 task :setup_share do #share
456 setup_find_create('data/sisu',@dir[:share]) if File.directory?('data/sisu')
457 end
458 task :setup_data do #data
459 setup_find_create('data',@dir[:data]) if File.directory?('data')
460 end
461 task :setup_man do #man
462 setup_find_create('man',@dir[:man]) if File.directory?('man') #man pages
463 setup_find_create('man.deb/man',@dir[:man]) if File.directory?('man.deb/man') #man pages
464 end
465 task :setup_vim do #man
466 setup_find_create('data/vim',@dir[:vim]) if File.directory?('data/vim') #man pages
467 end
468 #%% post install
469 #%% clobber/remove tasks
470 task :remove_bin do
471 rm_r "#{@dir[:bin]}/#{@dir[:proj]}" if FileTest.file?("#{@dir[:bin]}/#{@dir[:proj]}")
472 end
473 task :remove_lib do
474 rm_r "#{@dir[:lib]}/#{@dir[:proj]}" if FileTest.directory?("#{@dir[:lib]}/#{@dir[:proj]}")
475 end
476 task :remove_conf do
477 rm_r "#{@dir[:conf]}/#{@dir[:proj]}" if FileTest.directory?("#{@dir[:conf]}/#{@dir[:proj]}")
478 end
479 #task :remove_data do
480 # rm_r "#{@dir[:data]}/#{@dir[:proj_eg]}" if FileTest.directory?("#{@dir[:data]}/#{@dir[:proj_eg]}")
481 #end
482 task :remove_man do
483 rm_r "#{@dir[:man]}/**/#{@dir[:proj]}" if FileTest.directory?("#{@dir[:man]}/man1/#{@dir[:proj]}")
484 end
485 task :remove_version do
486 rm_r "#{@dir[:bin]}/#{@dir[:proj]}" if FileTest.file?("#{@dir[:bin]}/#{@dir[:proj]}")
487 rm_r "#{@dir[:lib]}/#{@dir[:proj]}/#{Version}" if FileTest.directory?("#{@dir[:lib]}/#{@dir[:proj]}/#{Version}")
488 rm_r "#{@dir[:conf]}/#{@dir[:proj]} if FileTest.directory?("#{@dir[:conf]}/#{@dir[:proj]}")
489 #rm_r "#@dir_data/#{@dir[:proj]}"
490 end
491 task :remove_package do
492 rm_r "#{@dir[:bin]}/#{@dir[:proj]}" if FileTest.file?("#{@dir[:bin]}/#{@dir[:proj]}")
493 rm_r "#{@dir[:lib]}/#{@dir[:proj]}" if FileTest.directory?("#{@dir[:lib]}/#{@dir[:proj]}")
494 rm_r "#{@dir[:conf]}/#{@dir[:proj]}" if FileTest.directory?("#{@dir[:conf]}/#{@dir[:proj]}")
495 end
496 task :post_install_note do
497 puts <<WOK
498
499 sisu markup samples are now packaged separately in sisu-markup-samples
500 visit:
501 http://www.jus.uio.no/sisu
502 and:
503 http://www.jus.uio.no/sisu/SiSU/download
504
505 WOK
506 end
507 task :system_info do #%% system info
508 rant_system_info
509 end
510 task :system_param do
511 Config::CONFIG.each {|c| p c }
512 end
513 task :project_help do #%% help
514 rant_project_help
515 end
516 task :rant_tasks do #%% help
517 rant_tasks
518 end