3636require 'optparse'
3737require 'ostruct'
3838
39- PREREQS = %w{ openssl facter cgi }
40- MIN_FACTER_VERSION = 1.5
39+ IS_WINDOWS = RUBY_PLATFORM . match? ( /(mswin|mingw)/ )
4140
4241InstallOptions = OpenStruct . new
4342
@@ -82,13 +81,7 @@ def do_man(man, strip = 'man/')
8281 FileUtils . makedirs ( om , mode : 0755 , verbose : true )
8382 FileUtils . chmod ( 0755 , om )
8483 FileUtils . install ( mf , omf , mode : 0644 , preserve : true , verbose : true )
85- # Solaris does not support gzipped man pages. When called with
86- # --no-check-prereqs/without facter the default gzip behavior still applies
87- unless $osname == "Solaris"
88- gzip = %x{which gzip}
89- gzip . chomp!
90- %x{#{ gzip } --force --no-name #{ omf } }
91- end
84+ %x{gzip --force --no-name #{ omf } }
9285 end
9386end
9487
@@ -103,33 +96,11 @@ def do_locales(locale, strip = 'locales/')
10396 end
10497end
10598
106- # Verify that all of the prereqs are installed
107- def check_prereqs
108- PREREQS . each { |pre |
109- begin
110- require pre
111- if pre == "facter"
112- # to_f isn't quite exact for strings like "1.5.1" but is good
113- # enough for this purpose.
114- facter_version = Facter . version . to_f
115- if facter_version < MIN_FACTER_VERSION
116- puts "Facter version: #{ facter_version } ; minimum required: #{ MIN_FACTER_VERSION } ; cannot install"
117- exit ( -1 )
118- end
119- end
120- rescue LoadError
121- puts "Could not load #{ pre } ; cannot install"
122- exit ( -1 )
123- end
124- }
125- end
126-
12799##
128100# Prepare the file installation.
129101#
130102def prepare_installation
131103 InstallOptions . configs = true
132- InstallOptions . check_prereqs = true
133104 InstallOptions . batch_files = true
134105
135106 ARGV . options do |opts |
@@ -174,9 +145,6 @@ def prepare_installation
174145 opts . on ( '--mandir[=OPTIONAL]' , 'Installation directory for man pages' , 'overrides RbConfig::CONFIG["mandir"]' ) do |mandir |
175146 InstallOptions . mandir = mandir
176147 end
177- opts . on ( '--[no-]check-prereqs' , 'Prevents validation of prerequisite libraries' , 'Default on' ) do |prereq |
178- InstallOptions . check_prereqs = prereq
179- end
180148 opts . on ( '--no-batch-files' , 'Prevents installation of batch files for windows' , 'Default off' ) do |batch_files |
181149 InstallOptions . batch_files = false
182150 end
@@ -201,56 +169,49 @@ def prepare_installation
201169 RbConfig ::CONFIG [ 'bindir' ] = "/usr/bin"
202170 end
203171
204- # Here we only set $osname if we have opted to check for prereqs.
205- # Otherwise facter won't be guaranteed to be present.
206- if InstallOptions . check_prereqs
207- check_prereqs
208- $osname = Facter . value ( 'os.name' )
209- end
210-
211172 if not InstallOptions . configdir . nil?
212173 configdir = InstallOptions . configdir
213- elsif $osname == "windows"
174+ elsif IS_WINDOWS
214175 configdir = File . join ( ENV [ 'ALLUSERSPROFILE' ] , "PuppetLabs" , "puppet" , "etc" )
215176 else
216177 configdir = "/etc/puppetlabs/puppet"
217178 end
218179
219180 if not InstallOptions . codedir . nil?
220181 codedir = InstallOptions . codedir
221- elsif $osname == "windows"
182+ elsif IS_WINDOWS
222183 codedir = File . join ( ENV [ 'ALLUSERSPROFILE' ] , "PuppetLabs" , "code" )
223184 else
224185 codedir = "/etc/puppetlabs/code"
225186 end
226187
227188 if not InstallOptions . vardir . nil?
228189 vardir = InstallOptions . vardir
229- elsif $osname == "windows"
190+ elsif IS_WINDOWS
230191 vardir = File . join ( ENV [ 'ALLUSERSPROFILE' ] , "PuppetLabs" , "puppet" , "cache" )
231192 else
232193 vardir = "/opt/puppetlabs/puppet/cache"
233194 end
234195
235196 if not InstallOptions . publicdir . nil?
236197 publicdir = InstallOptions . publicdir
237- elsif $osname == "windows"
198+ elsif IS_WINDOWS
238199 publicdir = File . join ( ENV [ 'ALLUSERSPROFILE' ] , "PuppetLabs" , "puppet" , "public" )
239200 else
240201 publicdir = "/opt/puppetlabs/puppet/public"
241202 end
242203
243204 if not InstallOptions . rundir . nil?
244205 rundir = InstallOptions . rundir
245- elsif $osname == "windows"
206+ elsif IS_WINDOWS
246207 rundir = File . join ( ENV [ 'ALLUSERSPROFILE' ] , "PuppetLabs" , "puppet" , "var" , "run" )
247208 else
248209 rundir = "/var/run/puppetlabs"
249210 end
250211
251212 if not InstallOptions . logdir . nil?
252213 logdir = InstallOptions . logdir
253- elsif $osname == "windows"
214+ elsif IS_WINDOWS
254215 logdir = File . join ( ENV [ 'ALLUSERSPROFILE' ] , "PuppetLabs" , "puppet" , "var" , "log" )
255216 else
256217 logdir = "/var/log/puppetlabs/puppet"
@@ -265,7 +226,7 @@ def prepare_installation
265226 if not InstallOptions . localedir . nil?
266227 localedir = InstallOptions . localedir
267228 else
268- if $osname == "windows"
229+ if IS_WINDOWS
269230 localedir = File . join ( ENV [ 'PROGRAMFILES' ] , "Puppet Labs" , "Puppet" , "puppet" , "share" , "locale" )
270231 else
271232 localedir = "/opt/puppetlabs/puppet/share/locale"
@@ -339,7 +300,7 @@ def prepare_installation
339300# by stripping the drive letter, but only if the basedir is not empty.
340301#
341302def join ( basedir , dir )
342- return "#{ basedir } #{ dir [ 2 ..-1 ] } " if $osname == "windows" and basedir . length > 0 and dir . length > 2
303+ return "#{ basedir } #{ dir [ 2 ..-1 ] } " if IS_WINDOWS and basedir . length > 0 and dir . length > 2
343304
344305 "#{ basedir } #{ dir } "
345306end
@@ -360,14 +321,14 @@ def install_binfile(from, op_file, target)
360321
361322 File . open ( from ) do |ip |
362323 File . open ( tmp_file . path , "w" ) do |op |
363- op . puts "#!#{ ruby } " unless $osname == "windows"
324+ op . puts "#!#{ ruby } " unless IS_WINDOWS
364325 contents = ip . readlines
365326 contents . shift if contents [ 0 ] =~ /^#!/
366327 op . write contents . join
367328 end
368329 end
369330
370- if $osname == "windows" && InstallOptions . batch_files
331+ if IS_WINDOWS && InstallOptions . batch_files
371332 installed_wrapper = false
372333
373334 unless File . extname ( from ) =~ /\. (cmd|bat)/
@@ -415,14 +376,14 @@ def install_binfile(from, op_file, target)
415376
416377 prepare_installation
417378
418- if $osname == "windows"
379+ if IS_WINDOWS
419380 windows_bins = glob ( %w{ ext/windows/*bat } )
420381 end
421382
422383 do_configs ( configs , InstallOptions . config_dir ) if InstallOptions . configs
423384 do_bins ( bins , InstallOptions . bin_dir )
424- do_bins ( windows_bins , InstallOptions . bin_dir , 'ext/windows/' ) if $osname == "windows" && InstallOptions . batch_files
385+ do_bins ( windows_bins , InstallOptions . bin_dir , 'ext/windows/' ) if IS_WINDOWS && InstallOptions . batch_files
425386 do_libs ( libs )
426387 do_locales ( locales )
427- do_man ( man ) unless $osname == "windows"
388+ do_man ( man ) unless IS_WINDOWS
428389end
0 commit comments