Skip to content

Commit 34cc30f

Browse files
committed
Detect Windows in install.rb without Facter
1 parent 29db049 commit 34cc30f

File tree

1 file changed

+16
-31
lines changed

1 file changed

+16
-31
lines changed

install.rb

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@
3636
require 'optparse'
3737
require 'ostruct'
3838

39-
PREREQS = %w{openssl facter cgi}
40-
MIN_FACTER_VERSION = 1.5
39+
IS_WINDOWS = RUBY_PLATFORM.match?(/(mswin|mingw)/)
40+
41+
PREREQS = %w{openssl cgi}
4142

4243
InstallOptions = OpenStruct.new
4344

@@ -102,15 +103,6 @@ def check_prereqs
102103
PREREQS.each { |pre|
103104
begin
104105
require pre
105-
if pre == "facter"
106-
# to_f isn't quite exact for strings like "1.5.1" but is good
107-
# enough for this purpose.
108-
facter_version = Facter.version.to_f
109-
if facter_version < MIN_FACTER_VERSION
110-
puts "Facter version: #{facter_version}; minimum required: #{MIN_FACTER_VERSION}; cannot install"
111-
exit(-1)
112-
end
113-
end
114106
rescue LoadError
115107
puts "Could not load #{pre}; cannot install"
116108
exit(-1)
@@ -195,56 +187,49 @@ def prepare_installation
195187
RbConfig::CONFIG['bindir'] = "/usr/bin"
196188
end
197189

198-
# Here we only set $osname if we have opted to check for prereqs.
199-
# Otherwise facter won't be guaranteed to be present.
200-
if InstallOptions.check_prereqs
201-
check_prereqs
202-
$osname = Facter.value('os.name')
203-
end
204-
205190
if not InstallOptions.configdir.nil?
206191
configdir = InstallOptions.configdir
207-
elsif $osname == "windows"
192+
elsif IS_WINDOWS
208193
configdir = File.join(ENV['ALLUSERSPROFILE'], "PuppetLabs", "puppet", "etc")
209194
else
210195
configdir = "/etc/puppetlabs/puppet"
211196
end
212197

213198
if not InstallOptions.codedir.nil?
214199
codedir = InstallOptions.codedir
215-
elsif $osname == "windows"
200+
elsif IS_WINDOWS
216201
codedir = File.join(ENV['ALLUSERSPROFILE'], "PuppetLabs", "code")
217202
else
218203
codedir = "/etc/puppetlabs/code"
219204
end
220205

221206
if not InstallOptions.vardir.nil?
222207
vardir = InstallOptions.vardir
223-
elsif $osname == "windows"
208+
elsif IS_WINDOWS
224209
vardir = File.join(ENV['ALLUSERSPROFILE'], "PuppetLabs", "puppet", "cache")
225210
else
226211
vardir = "/opt/puppetlabs/puppet/cache"
227212
end
228213

229214
if not InstallOptions.publicdir.nil?
230215
publicdir = InstallOptions.publicdir
231-
elsif $osname == "windows"
216+
elsif IS_WINDOWS
232217
publicdir = File.join(ENV['ALLUSERSPROFILE'], "PuppetLabs", "puppet", "public")
233218
else
234219
publicdir = "/opt/puppetlabs/puppet/public"
235220
end
236221

237222
if not InstallOptions.rundir.nil?
238223
rundir = InstallOptions.rundir
239-
elsif $osname == "windows"
224+
elsif IS_WINDOWS
240225
rundir = File.join(ENV['ALLUSERSPROFILE'], "PuppetLabs", "puppet", "var", "run")
241226
else
242227
rundir = "/var/run/puppetlabs"
243228
end
244229

245230
if not InstallOptions.logdir.nil?
246231
logdir = InstallOptions.logdir
247-
elsif $osname == "windows"
232+
elsif IS_WINDOWS
248233
logdir = File.join(ENV['ALLUSERSPROFILE'], "PuppetLabs", "puppet", "var", "log")
249234
else
250235
logdir = "/var/log/puppetlabs/puppet"
@@ -259,7 +244,7 @@ def prepare_installation
259244
if not InstallOptions.localedir.nil?
260245
localedir = InstallOptions.localedir
261246
else
262-
if $osname == "windows"
247+
if IS_WINDOWS
263248
localedir = File.join(ENV['PROGRAMFILES'], "Puppet Labs", "Puppet", "puppet", "share", "locale")
264249
else
265250
localedir = "/opt/puppetlabs/puppet/share/locale"
@@ -333,7 +318,7 @@ def prepare_installation
333318
# by stripping the drive letter, but only if the basedir is not empty.
334319
#
335320
def join(basedir, dir)
336-
return "#{basedir}#{dir[2..-1]}" if $osname == "windows" and basedir.length > 0 and dir.length > 2
321+
return "#{basedir}#{dir[2..-1]}" if IS_WINDOWS and basedir.length > 0 and dir.length > 2
337322

338323
"#{basedir}#{dir}"
339324
end
@@ -354,14 +339,14 @@ def install_binfile(from, op_file, target)
354339

355340
File.open(from) do |ip|
356341
File.open(tmp_file.path, "w") do |op|
357-
op.puts "#!#{ruby}" unless $osname == "windows"
342+
op.puts "#!#{ruby}" unless IS_WINDOWS
358343
contents = ip.readlines
359344
contents.shift if contents[0] =~ /^#!/
360345
op.write contents.join
361346
end
362347
end
363348

364-
if $osname == "windows" && InstallOptions.batch_files
349+
if IS_WINDOWS && InstallOptions.batch_files
365350
installed_wrapper = false
366351

367352
unless File.extname(from) =~ /\.(cmd|bat)/
@@ -409,14 +394,14 @@ def install_binfile(from, op_file, target)
409394

410395
prepare_installation
411396

412-
if $osname == "windows"
397+
if IS_WINDOWS
413398
windows_bins = glob(%w{ext/windows/*bat})
414399
end
415400

416401
do_configs(configs, InstallOptions.config_dir) if InstallOptions.configs
417402
do_bins(bins, InstallOptions.bin_dir)
418-
do_bins(windows_bins, InstallOptions.bin_dir, 'ext/windows/') if $osname == "windows" && InstallOptions.batch_files
403+
do_bins(windows_bins, InstallOptions.bin_dir, 'ext/windows/') if IS_WINDOWS && InstallOptions.batch_files
419404
do_libs(libs)
420405
do_locales(locales)
421-
do_man(man) unless $osname == "windows"
406+
do_man(man) unless IS_WINDOWS
422407
end

0 commit comments

Comments
 (0)