Rantfile header info
[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 def rant_system_info
174 puts <<WOK
175 #{@proj[:platform_notice]}
176
177 Host
178 host: #@host
179 arch: #{@dir[:arch]}
180 sitearch: #{@dir[:sitearch]}
181
182 Directories for installation
183 bin: #{@dir[:bin]}
184 lib (site-ruby): #{@dir[:lib]}/#{@dir[:proj]}/#{Version}
185 conf [etc]: #{@dir[:conf]}/#{@dir[:proj]}
186 data (odf, shared images): #{@dir[:share]}
187 vim (vim syntax, highlighting, ftplugin): #{@dir[:data]}/sisu/vim
188 data (README, version_manifest): #{@dir[:data]}/doc/#{@dir[:proj]}
189 man (manual pages): #{@dir[:man]}
190 output: #{@dir[:out]}
191 processing: #{@dir[:out]}/processing
192 www: #{@dir[:out]}/www
193
194 rubylib: #@rubylib
195
196 WOK
197 end
198 def rant_project_help
199 puts <<WOK
200
201 #{@proj[:name]}
202 #{@proj[:rant]}
203 #{@proj[:platform_notice]}
204
205 Commands quick start list
206
207 #{@proj[:name]} Rant Help: (This Rantfile uses the same directory structure as setup.rb)
208 rant -T # a task list, (generated by Rant) for more complete and up to date help
209 rant system # system info used
210
211 Quick start install and remove project #{@proj[:name]}
212 as root:
213 rant # install #{@proj[:name]}
214
215 rant setup # install #{@proj[:name]} (without additonal configuration and generating of test file)
216
217 rant reinstall # reinstall #{@proj[:name]}
218
219 rant remove # clobber/remove #{@proj[:name]}, current version: #{Version}
220 rant remove_package # clobber/remove #{@proj[:name]}, all versions
221
222 For a more detailed and up to date list of command options use
223
224 rant -T
225
226 WOK
227 end
228 def rant_tasks
229 sys('rant -T')
230 end
231 #%% tasks
232 desc "rant (as root type 'rant' for default action)"
233 task :default => [:default_notice,:project]
234 #task :default => [:help,:notice,:project]
235 desc "Setup/Install #{@proj[:name]} and try generate a file"
236 task :project=> [:setup_bin,:setup_lib,:setup_conf,:setup_share,:setup_data,:setup_man,:setup_vim,:post_install_note]
237 desc "Setup/Install #{@proj[:name]}"
238 task :setup=> [:setup_bin, :setup_lib,:setup_conf,:setup_share,:setup_data,:post_install] #, :help]
239 desc "Setup/Install #{@proj[:name]}: bin, lib and conf (no data)"
240 task :setup_base=> [:setup_bin,:setup_lib,:setup_conf,:setup_share,:setup_man,:setup_vim]
241 desc "Setup/Install #{@proj[:name]} bin, lib and conf (no data and no attempt to do postinstall setup)"
242 task :base=> [:setup_base]
243 if File.directory?('bin') #bin
244 desc "Setup #{@proj[:name]} bin only, synonym :bin"
245 task :setup_bin => [:setup_bin]
246 task :bin => [:setup_bin]
247 end
248 if File.directory?('lib') #lib
249 desc "Setup #{@proj[:name]} lib only, synonym :lib"
250 task :setup_lib => [:setup_lib]
251 task :lib => [:setup_lib]
252 end
253 if File.directory?('conf') #conf or etc
254 desc "Setup #{@proj[:name]} conf only, synonyms :conf & :etc"
255 task :setup_conf => [:setup_conf]
256 task :conf => [:setup_conf]
257 task :setup_etc => [:setup_conf]
258 task :etc => [:setup_conf]
259 end
260 if File.directory?('data') #data
261 desc "Setup #{@proj[:name]} data only, synonyms :data & :examples"
262 task :setup_data => [:setup_data]
263 task :data => [:setup_data]
264 task :setup_examples => [:setup_data]
265 task :examples => [:setup_data]
266 end
267 if File.directory?('data/sisu') #share (odf shared-images)
268 desc "Setup #{@proj[:name]} shared data only (odf & shared images)"
269 task :setup_share => [:setup_share]
270 task :share => [:setup_share]
271 end
272 if File.directory?('man') #man pages
273 desc "Setup #{@proj[:name]} man pages only, synonyms :man"
274 task :setup_man => [:setup_man]
275 task :man => [:setup_man]
276 end
277 if File.directory?('data/vim') #man pages
278 desc "Setup #{@proj[:name]} vim config files only, synonyms :vim"
279 task :setup_vim => [:setup_vim]
280 task :vim => [:setup_vim]
281 end
282 desc "Setup/Install #{@proj[:name]}: bin, lib, conf and data (no attempt to do postinstall setup)"
283 task :setup_only=> [:setup_bin,:setup_lib,:setup_conf,:setup_share,:setup_data,:help]
284 #desc "Remove #{@proj[:name]} version: #{Version}"
285 #task :remove => [:remove_version]
286 desc "Remove #{@proj[:name]} (all versions)" #remove project
287 task :remove_package => [:remove_bin, :remove_lib, :remove_conf]
288 if File.directory?('bin') #bin
289 desc "Remove #{@proj[:name]} bin only" #remove bin
290 task :remove_bin => [:remove_bin]
291 end
292 if File.directory?('lib') #lib
293 desc "Remove #{@proj[:name]} lib only" #remove lib
294 task :remove_lib => [:remove_lib]
295 end
296 if File.directory?('conf') #conf
297 desc "Remove #{@proj[:name]} conf only" #remove conf
298 task :remove_conf => [:remove_conf]
299 end
300 #if File.directory?('data') #data
301 # desc "Remove #{@proj[:name]} data only" #remove data
302 # task :remove_data => [:remove_data]
303 #end
304 desc "Re-setup #{@proj[:name]}, synonym :reinstall" #resetup reinstall
305 task :resetup => [:remove, :setup]
306 task :reinstall => [:remove, :setup]
307 desc "Re-setup #{@proj[:name]}: bin, lib, conf (ignore data), synonym :reinstall" #partial reinstall
308 task :resetup_base => [:remove, :setup_base]
309 task :reinstall_base => [:remove, :setup_base]
310 if File.directory?('bin') #bin
311 desc "Re-setup #{@proj[:name]} bin, synonym :reinstall"
312 task :resetup_bin => [:remove_bin, :setup_bin]
313 task :reinstall_bin => [:remove_bin, :setup_bin]
314 end
315 if File.directory?('lib') #lib
316 desc "Re-setup #{@proj[:name]} lib, synonym :reinstall_lib"
317 task :resetup_lib => [:remove_lib, :setup_lib]
318 task :reinstall_lib => [:remove_lib, :setup_lib]
319 end
320 if File.directory?('conf') #conf
321 desc "Re-setup #{@proj[:name]} conf, synonyms :reinstall_conf & :resetup_etc"
322 task :resetup_conf => [:remove_conf, :setup_conf]
323 task :reinstall_conf => [:remove_conf, :setup_conf]
324 task :resetup_etc => [:remove_conf, :setup_conf]
325 task :reinstall_etc => [:remove_conf, :setup_conf]
326 end
327 if File.directory?('data/sisu') #share
328 desc "Re-setup #{@proj[:name]} shared data, (odf & images)"
329 task :resetup_share => [:remove_share, :setup_share]
330 task :reinstall_share => [:remove_share, :setup_share]
331 end
332 if File.directory?('man') #man
333 desc "Re-setup #{@proj[:name]} man, synonym :reinstall_man"
334 task :resetup_man => [:remove_man, :setup_man]
335 task :reinstall_man => [:remove_man, :setup_man]
336 end
337 desc "Setup Note"
338 task :setup_note => [:help]
339 desc "Note on post installation" #remove conf
340 task :post_install_note => [:post_install_note]
341 desc "System information used by #{@proj[:name]}"
342 task :system => [:system_info,:project_help,:post_install_note]
343 desc "show all system info available - parameters found"
344 task :system_param => [:system_param]
345 desc "Help"
346 task :help => [:project_help,:system_info,:rant_tasks,:pi?]
347 #desc "Setup/Install #{@proj[:name]} (uses filelist)"
348 task :install => [:default_notice,:project]
349 task :install_bin => [:setup_bin]
350 desc "[make rant install file]"
351 task :create_rant_independent_task_file => [:rant_independence]
352 #%% setup/install tasks
353 task :rant_independence do #notice
354 resp=''
355 while resp.length < 4
356 resp='install' #default name install
357 print %{#{@proj[:rant]}
358 Create a rant dependency independent file
359 provide filename default name is "install"
360 [Warning, will overwrite file of name provided
361 provide name or "quit" to exit]: }
362 #res=File.new('/dev/tty').gets.strip
363 #resp=res if res =~/\S{4,30}/
364 exit if resp =~/^(?:n|quit|exit)$/
365 end
366 remove='y' #remove='n'
367 #remove=if FileTest.file?(resp)
368 # print "a file of the same name #{resp} exists, [y] to replace: "
369 # File.new('/dev/tty').gets.strip
370 #else 'y'
371 #end
372 if remove =~/y/; system("rant-import --force --auto #{resp}\n")
373 #puts "#{resp} updated"
374 else #puts "#{resp} not replaced"
375 end
376 end
377
378 task :default_notice do #notice
379 default_notice
380 end
381 task :rant_default2 do #secondary
382 setup_find_cp_r('bin',@dir[:bin]) if File.directory?('bin')
383 setup_find_cp_r('lib',@dir[:lib]) if File.directory?('lib')
384 setup_find_cp_r('conf',@dir[:conf]) if File.directory?('conf')
385 setup_find_cp_r('data/sisu',"#{@dir[:share]}") if File.directory?('data/sisu') #
386 setup_find_cp_r('data',@dir[:data]) if File.directory?('data')
387 setup_find_cp_r('data/vim',"#{@dir[:data]}/vim") if File.directory?('data/vim')
388 setup_find_cp_r('man',@dir[:man]) if File.directory?('man')
389 end
390 task :setup_bin do #bin
391 setup_find_create('bin',@dir[:bin]) if File.directory?('bin')
392 end
393 task :setup_lib do #lib
394 setup_find_create('lib',@dir[:lib]) if File.directory?('lib')
395 end
396 task :setup_conf do #conf
397 setup_find_create('conf',@dir[:conf]) if File.directory?('conf')
398 end
399 task :setup_share do #share
400 setup_find_create('data/sisu',@dir[:share]) if File.directory?('data/sisu')
401 end
402 task :setup_data do #data
403 setup_find_create('data',@dir[:data]) if File.directory?('data')
404 end
405 task :setup_man do #man
406 setup_find_create('man',@dir[:man]) if File.directory?('man') #man pages
407 setup_find_create('man.deb/man',@dir[:man]) if File.directory?('man.deb/man') #man pages
408 end
409 task :setup_vim do #man
410 setup_find_create('data/vim',@dir[:vim]) if File.directory?('data/vim') #man pages
411 end
412 #%% post install
413 #%% clobber/remove tasks
414 task :remove_bin do
415 rm_r "#{@dir[:bin]}/#{@dir[:proj]}" if FileTest.file?("#{@dir[:bin]}/#{@dir[:proj]}")
416 end
417 task :remove_lib do
418 rm_r "#{@dir[:lib]}/#{@dir[:proj]}" if FileTest.directory?("#{@dir[:lib]}/#{@dir[:proj]}")
419 end
420 task :remove_conf do
421 rm_r "#{@dir[:conf]}/#{@dir[:proj]}" if FileTest.directory?("#{@dir[:conf]}/#{@dir[:proj]}")
422 end
423 #task :remove_data do
424 # rm_r "#{@dir[:data]}/#{@dir[:proj_eg]}" if FileTest.directory?("#{@dir[:data]}/#{@dir[:proj_eg]}")
425 #end
426 task :remove_man do
427 rm_r "#{@dir[:man]}/**/#{@dir[:proj]}" if FileTest.directory?("#{@dir[:man]}/man1/#{@dir[:proj]}")
428 end
429 task :remove_version do
430 rm_r "#{@dir[:bin]}/#{@dir[:proj]}" if FileTest.file?("#{@dir[:bin]}/#{@dir[:proj]}")
431 rm_r "#{@dir[:lib]}/#{@dir[:proj]}/#{Version}" if FileTest.directory?("#{@dir[:lib]}/#{@dir[:proj]}/#{Version}")
432 rm_r "#{@dir[:conf]}/#{@dir[:proj]} if FileTest.directory?("#{@dir[:conf]}/#{@dir[:proj]}")
433 #rm_r "#@dir_data/#{@dir[:proj]}"
434 end
435 task :remove_package do
436 rm_r "#{@dir[:bin]}/#{@dir[:proj]}" if FileTest.file?("#{@dir[:bin]}/#{@dir[:proj]}")
437 rm_r "#{@dir[:lib]}/#{@dir[:proj]}" if FileTest.directory?("#{@dir[:lib]}/#{@dir[:proj]}")
438 rm_r "#{@dir[:conf]}/#{@dir[:proj]}" if FileTest.directory?("#{@dir[:conf]}/#{@dir[:proj]}")
439 end
440 task :post_install_note do
441 puts <<WOK
442
443 sisu markup samples are now packaged separately in sisu-markup-samples
444 visit:
445 http://www.jus.uio.no/sisu
446 and:
447 http://www.jus.uio.no/sisu/SiSU/download
448
449 WOK
450 end
451 task :system_info do #%% system info
452 rant_system_info
453 end
454 task :system_param do
455 @env.each {|c| puts c.inspect }
456 end
457 task :project_help do #%% help
458 rant_project_help
459 end
460 task :rant_tasks do #%% help
461 rant_tasks
462 end