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