-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinstall.rb
75 lines (56 loc) · 1.47 KB
/
install.rb
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
#!/usr/bin/env ruby
require "json"
require "fileutils"
require "trollop"
opts = Trollop::options do
opt :uninstall, "Uninstall old installation"
end
INSTALLED_FILE = ".installed_files.json"
D_SHARE_DIR = "/usr/local/share/antlr-php"
D_BIN_DIR = "/usr/local/bin"
files_to_be_installed = {
"lib" => [
"antlr-3.4-complete.jar",
"antlr-php.jar"
],
"bin" => [
"gen-antlr-php.rb"
]
}
if File.exists? INSTALLED_FILE
installed_files = JSON.load File.new(INSTALLED_FILE)
end
# uninstall old files
unless installed_files.nil?
installed_files.each do |file|
FileUtils.rm file
end
FileUtils.rmdir D_SHARE_DIR
FileUtils.rmdir D_BIN_DIR
FileUtils.rm INSTALLED_FILE
end
# if uninstall was required, stop here ...
if opts[:uninstall] == true
exit 0
end
installed_files = []
FileUtils.mkdir_p D_SHARE_DIR
lib_files = files_to_be_installed["lib"]
bin_files = files_to_be_installed["bin"]
lib_files.each do |file|
FileUtils.cp "lib/#{file}", D_SHARE_DIR
installed_files << "#{D_SHARE_DIR}/#{file}"
end
bin_files.each do |file|
FileUtils.cp file, D_BIN_DIR
fullfile = "#{D_BIN_DIR}/#{file}"
basename = "#{D_BIN_DIR}/#{File.basename(file, File.extname(file))}"
File.chmod 0755, fullfile
FileUtils.ln_s fullfile, basename
installed_files << fullfile
installed_files << basename
end
content = JSON.pretty_generate installed_files
File.open INSTALLED_FILE, "w" do |file|
file.write content
end