install.rb

Path: install.rb
Last Update: Fri Nov 08 12:57:19 +0000 2013

Required files

rbconfig   find   fileutils   tempfile   optparse   ostruct   rdoc/rdoc  

Methods

Included Modules

FileUtils

Constants

PREREQS = %w{rubygems stomp}
InstallOptions = OpenStruct.new

Public Instance methods

Build the rdoc documentation.

[Source]

     # File install.rb, line 246
246: def build_rdoc(files)
247:   return unless $haverdoc
248:   begin
249:     r = RDoc::RDoc.new
250:     r.document(["--main", "MCollective", "--line-numbers"] + files)
251:   rescue RDoc::RDocError => e
252:     $stderr.puts e.message
253:   rescue Exception => e
254:     $stderr.puts "Couldn't build RDoc documentation\n#{e.message}"
255:   end
256: end

[Source]

    # File install.rb, line 65
65: def check_prereqs
66:   PREREQS.each do |pre|
67:     begin
68:       require pre
69:     rescue LoadError
70:       puts "Could not load #{pre} Ruby library; cannot install"
71:       exit(-1)
72:     end
73:   end
74: end

[Source]

    # File install.rb, line 86
86: def do_bins(bins, target, strip = 's?bin/')
87:   Dir.mkdir(target) unless File.directory? target
88:   bins.each do |bf|
89:     obf = bf.gsub(/#{strip}/, '')
90:     install_binfile(bf, obf, target)
91:   end
92: end

[Source]

    # File install.rb, line 76
76: def do_configs(configs, target, strip = 'etc/')
77:   Dir.mkdir(target) unless File.directory? target
78:   configs.each do |cf|
79:     ocf = File.join(target, cf.gsub(Regexp.new(strip), ''))
80:     oc = File.dirname(ocf)
81:     makedirs(oc, {:mode => 0755, :verbose => true})
82:     install(cf, ocf, {:mode => 0644, :preserve => true, :verbose => true})
83:   end
84: end

[Source]

     # File install.rb, line 94
 94: def do_libs(libs, target, strip = 'lib/')
 95:   libs.each do |lf|
 96:     olf = File.join(target, lf.sub(/^#{strip}/, ''))
 97:     op = File.dirname(olf)
 98:     if File.directory?(lf)
 99:       makedirs(olf, {:mode => 0755, :verbose => true})
100:     else
101:       makedirs(op, {:mode => 0755, :verbose => true})
102:       install(lf, olf, {:mode => 0644, :preserve => true, :verbose => true})
103:     end
104:   end
105: end

[Source]

    # File install.rb, line 57
57: def glob(list)
58:   g = list.map { |i| Dir.glob(i) }
59:   g.flatten!
60:   g.compact!
61:   g.uniq!
62:   g
63: end

Install file(s) from ./bin to RbConfig::CONFIG[‘bindir’]. Patch it on the way to insert a #! line; on a Unix install, the command is named as expected

[Source]

     # File install.rb, line 261
261: def install_binfile(from, op_file, target)
262:   tmp_file = Tempfile.new('mcollective-binfile')
263: 
264:   if InstallOptions.ruby
265:     ruby = InstallOptions.ruby
266:   else
267:     ruby = File.join(RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name'])
268:   end
269: 
270:   File.open(from) do |ip|
271:     File.open(tmp_file.path, "w") do |op|
272:       op.puts "#!#{ruby}"
273:       contents = ip.readlines
274:       contents.shift if contents[0] =~ /^#!/
275:       op.write contents.join
276:     end
277:   end
278: 
279:   install(tmp_file.path, File.join(target, op_file), :mode => 0755, :preserve => true, :verbose => true)
280:   tmp_file.unlink
281: end

Prepare the file installation.

[Source]

     # File install.rb, line 110
110: def prepare_installation
111:   InstallOptions.configs = true
112: 
113:   # Only try to do docs if we're sure they have rdoc
114:   if $haverdoc
115:     InstallOptions.rdoc = true
116:   else
117:     InstallOptions.rdoc = false
118:   end
119: 
120: 
121:   ARGV.options do |opts|
122:     opts.banner = "Usage: #{File.basename($0)} [options]"
123:     opts.separator ""
124:     opts.on('--[no-]rdoc', 'Creation of RDoc output.', 'Default is create rdoc.') do |onrdoc|
125:       InstallOptions.rdoc = onrdoc
126:     end
127:     opts.on('--[no-]configs', 'Installation of config files', 'Default is install configs.') do |onconfigs|
128:       InstallOptions.configs = onconfigs
129:     end
130:     opts.on('--destdir[=OPTIONAL]', 'Installation prefix for all targets', 'Default essentially /') do |destdir|
131:       InstallOptions.destdir = destdir
132:     end
133:     opts.on('--configdir[=OPTIONAL]', 'Installation directory for config files', 'Default /etc/mcollective') do |configdir|
134:       InstallOptions.configdir = configdir
135:     end
136:     opts.on('--bindir[=OPTIONAL]', 'Installation directory for binaries', 'overrides RbConfig::CONFIG["bindir"]') do |bindir|
137:       InstallOptions.bindir = bindir
138:     end
139:     opts.on('--sbindir[=OPTIONAL]', 'Installation directory for system binaries', 'overrides RbConfig::CONFIG["sbindir"]') do |sbindir|
140:       InstallOptions.sbindir = sbindir
141:     end
142:     opts.on('--ruby[=OPTIONAL]', 'Ruby interpreter to use with installation', 'overrides ruby used to call install.rb') do |ruby|
143:       InstallOptions.ruby = ruby
144:     end
145:     opts.on('--sitelibdir[=OPTIONAL]', 'Installation directory for libraries', 'overrides RbConfig::CONFIG["sitelibdir"]') do |sitelibdir|
146:       InstallOptions.sitelibdir = sitelibdir
147:     end
148:     opts.on('--plugindir[=OPTIONAL]', 'Installation directory for plugins', 'Default /usr/libexec/mcollective') do |plugindir|
149:       InstallOptions.plugindir = plugindir
150:     end
151:     opts.on('--quick', 'Performs a quick installation. Only the', 'installation is done.') do |quick|
152:       InstallOptions.rdoc    = false
153:       InstallOptions.ri      = false
154:       InstallOptions.configs = true
155:     end
156:     opts.on('--full', 'Performs a full installation. All', 'optional installation steps are run.') do |full|
157:       InstallOptions.rdoc    = true
158:       InstallOptions.ri      = true
159:       InstallOptions.configs = true
160:     end
161:     opts.separator("")
162:     opts.on_tail('--help', "Shows this help text.") do
163:       $stderr.puts opts
164:       exit
165:     end
166: 
167:     opts.parse!
168:   end
169: 
170:   version = [RbConfig::CONFIG["MAJOR"], RbConfig::CONFIG["MINOR"]].join(".")
171:   libdir = File.join(RbConfig::CONFIG["libdir"], "ruby", version)
172: 
173:   # Mac OS X 10.5 and higher declare bindir
174:   # /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin
175:   # which is not generally where people expect executables to be installed
176:   # These settings are appropriate defaults for all OS X versions.
177:   if RUBY_PLATFORM =~ /^universal-darwin[\d\.]+$/
178:     RbConfig::CONFIG['bindir'] = "/usr/bin"
179:     RbConfig::CONFIG['sbindir'] = "/usr/sbin"
180:   end
181: 
182:   if InstallOptions.configdir
183:     configdir = InstallOptions.configdir
184:   else
185:     configdir = "/etc/mcollective"
186:   end
187: 
188:   if InstallOptions.bindir
189:     bindir = InstallOptions.bindir
190:   else
191:     bindir = RbConfig::CONFIG['bindir']
192:   end
193: 
194:   if InstallOptions.sbindir
195:     sbindir = InstallOptions.sbindir
196:   else
197:     sbindir = RbConfig::CONFIG['sbindir']
198:   end
199: 
200:   if InstallOptions.sitelibdir
201:     sitelibdir = InstallOptions.sitelibdir
202:   else
203:     sitelibdir = RbConfig::CONFIG["sitelibdir"]
204:     if sitelibdir.nil?
205:       sitelibdir = $LOAD_PATH.find { |x| x =~ /site_ruby/ }
206:       if sitelibdir.nil?
207:         sitelibdir = File.join(libdir, "site_ruby")
208:       elsif sitelibdir !~ Regexp.quote(version)
209:         sitelibdir = File.join(sitelibdir, version)
210:       end
211:     end
212:   end
213: 
214:   if InstallOptions.plugindir
215:     plugindir = InstallOptions.plugindir
216:   else
217:     plugindir = "/usr/libexec/mcollective"
218:   end
219: 
220:   if InstallOptions.destdir
221:     destdir = InstallOptions.destdir
222:   else
223:     destdir = ''
224:   end
225: 
226:   configdir = File.join(destdir, configdir)
227:   bindir = File.join(destdir, bindir)
228:   sitelibdir = File.join(destdir, sitelibdir)
229: 
230:   makedirs(configdir) if InstallOptions.configs
231:   makedirs(bindir)
232:   makedirs(sbindir)
233:   makedirs(sitelibdir)
234:   makedirs(plugindir)
235: 
236:   InstallOptions.sitelibdir = sitelibdir
237:   InstallOptions.configdir = configdir
238:   InstallOptions.bindir  = bindir
239:   InstallOptions.sbindir  = sbindir
240:   InstallOptions.plugindir  = plugindir
241: end

[Validate]