-
Notifications
You must be signed in to change notification settings - Fork 8
/
hda-install-gem
executable file
·71 lines (62 loc) · 1.57 KB
/
hda-install-gem
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
#! /usr/bin/env ruby
def do_system_multiple(args)
res = false
(1..4).each {
res = system("#{args} 2>&1")
break if res
}
res
end
def run_gem_install(gem, version = nil)
ver = version ? " --version #{version} " : ""
#puts "system(\"gem install #{gem} #{ver} --no-rdoc --no-ri\")"
do_system_multiple "gem install #{gem} #{ver} --no-rdoc --no-ri"
end
def gem_list
res = {}
raw_list = open("|gem list") { |f| f.readlines }.map do |g|
if g =~ /\s*([^\s]+)\s*\(([^\)]+)\)/
gem = $1
versions = $2.split /[, ]+/
res[gem] = versions
# puts "DEBUG gem: \"#{gem}\" -> #{versions.inspect}"
end
end
res
end
# return true if there are no errors - pass thru false for errors
def install_gem(gem, version = nil)
# puts gem.inspect
# puts version.inspect
usage if version && ! (version =~ /[0-9.]+/)
gems = gem_list
if gems[gem]
# puts "installed"
if version && ! gems[gem].include?(version)
# puts "DEBUG: gem versions available: #{gems[gem].inspect}"
puts "gem \"#{gem}\" is already installed, but not the version requested. installing #{version} ..."
run_gem_install(gem, version)
puts "done."
else
puts "gem \"#{gem}\" is already installed. skipped."
end
else
# puts "NOT installed at all - installing ..."
puts "gem \"#{gem}\" is not installed. installing ..."
run_gem_install(gem, version)
puts "done."
end
# return true for no errors
true
end
def usage
puts "usage: hda-install-gem gem [version]"
exit -1
end
unless ARGV.size > 0
usage
end
unless install_gem(ARGV[0], ARGV[1])
# could not install - exit with an error
exit -1
end