-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathRakefile
88 lines (73 loc) · 2.11 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
require 'fileutils'
task :readme => ["doc/README.md"] do
`pandoc doc/README.md -t gfm -o README.md`
end
task :test do
puts `./test/test-minstructor.rb`
puts `./test/test-mcollector.rb`
end
directory "build"
targets = ["minstructor", "mcollector"]
targets.each do |t|
file "build/#{t}.1.gz" => ["build", "doc/#{t}.md"] do
`pandoc -t man -s doc/#{t}.md -o build/#{t}.1.gz`
end
end
task :man => targets.map { |t| "build/#{t}.1.gz"}
task :default => [:man]
task :install, [:install_d,:man_d] => [:default] do |task,args|
args.with_defaults(:install_d => "/usr/local/bin",
:man_d => `man -w`.chomp.split(':')[-1]
)
install_d = File.expand_path(args.install_d)
mandir = File.expand_path(args.man_d)
puts "Installing ruby scripts to #{install_d}"
puts "Installing man files to #{mandir}"
# Ensure the required folders are available
FileUtils.mkdir_p install_d
FileUtils.mkdir_p mandir
[install_d, mandir].each do |d|
if !File.directory?(d)
puts "ERROR: directory #{d} does not exist"
exit 1
end
if !File.writable?(d)
puts "ERROR: you have no permissions to write at #{d}"
exit 1
end
end
# INSTALL MAN PAGES
targets.map do |t|
manf = File.expand_path("build/#{t}.1.gz")
man1dir = "#{mandir}/man1/"
FileUtils.mkdir_p man1dir
install_path = man1dir + File.basename(manf)
`cp -f #{manf} #{install_path}`
end
# INSTALL SCRIPTS
install_files = [
"math.rb",
"regular-expressions.rb",
"minstructor.rb",
"version.rb",
"mcollector.rb",
"mcollector-modules/akav.rb",
"mcollector-modules/csv.rb",
"mcollector-modules/kav.rb",
"mcollector-modules/base.rb",
"mcollector-modules/available-modules.rb",
]
libpath = install_d + "/minstructor-lib/"
install_files.each do |f|
install_path = libpath + f
puts "install _path = #{install_path}"
if !File.directory?(File.dirname(install_path))
FileUtils.mkdir_p(File.dirname(install_path))
end
FileUtils.copy(f, install_path)
end
# INSTALL SOFTLINKS FOR EXECUTION
targets.each do |t|
FileUtils.ln_s(libpath + t + ".rb", install_d + "/#{t}", force: true)
end
end