From a9abc245e4655cccc9e124bdb87df703a10b2c21 Mon Sep 17 00:00:00 2001 From: Ewoud Kohl van Wijngaarden Date: Fri, 27 Sep 2024 16:53:13 +0200 Subject: [PATCH 1/5] Remove unused find import --- install.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/install.rb b/install.rb index a3c9314f114..85aa06b4bb3 100755 --- a/install.rb +++ b/install.rb @@ -30,7 +30,6 @@ #++ require 'rbconfig' -require 'find' require 'fileutils' require 'tempfile' require 'optparse' From dca0d97f5e9abe70162a8e59f64425ff4a8c7627 Mon Sep 17 00:00:00 2001 From: Ewoud Kohl van Wijngaarden Date: Fri, 27 Sep 2024 16:55:36 +0200 Subject: [PATCH 2/5] Replace $osname in install.rb with Puppet::Util::Platform --- install.rb | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/install.rb b/install.rb index 85aa06b4bb3..3ff25f4f3ec 100755 --- a/install.rb +++ b/install.rb @@ -35,6 +35,8 @@ require 'optparse' require 'ostruct' +require_relative 'lib/puppet/util/platform' + PREREQS = %w{openssl facter cgi} MIN_FACTER_VERSION = 1.5 @@ -83,7 +85,7 @@ def do_man(man, strip = 'man/') FileUtils.install(mf, omf, mode: 0644, preserve: true, verbose: true) # Solaris does not support gzipped man pages. When called with # --no-check-prereqs/without facter the default gzip behavior still applies - unless $osname == "Solaris" + unless Puppet::Util::Platform.solaris? gzip = %x{which gzip} gzip.chomp! %x{#{gzip} -f #{omf}} @@ -200,16 +202,13 @@ def prepare_installation RbConfig::CONFIG['bindir'] = "/usr/bin" end - # Here we only set $osname if we have opted to check for prereqs. - # Otherwise facter won't be guaranteed to be present. if InstallOptions.check_prereqs check_prereqs - $osname = Facter.value('os.name') end if not InstallOptions.configdir.nil? configdir = InstallOptions.configdir - elsif $osname == "windows" + elsif Puppet::Util::Platform.windows? configdir = File.join(ENV['ALLUSERSPROFILE'], "PuppetLabs", "puppet", "etc") else configdir = "/etc/puppetlabs/puppet" @@ -217,7 +216,7 @@ def prepare_installation if not InstallOptions.codedir.nil? codedir = InstallOptions.codedir - elsif $osname == "windows" + elsif Puppet::Util::Platform.windows? codedir = File.join(ENV['ALLUSERSPROFILE'], "PuppetLabs", "code") else codedir = "/etc/puppetlabs/code" @@ -225,7 +224,7 @@ def prepare_installation if not InstallOptions.vardir.nil? vardir = InstallOptions.vardir - elsif $osname == "windows" + elsif Puppet::Util::Platform.windows? vardir = File.join(ENV['ALLUSERSPROFILE'], "PuppetLabs", "puppet", "cache") else vardir = "/opt/puppetlabs/puppet/cache" @@ -233,7 +232,7 @@ def prepare_installation if not InstallOptions.publicdir.nil? publicdir = InstallOptions.publicdir - elsif $osname == "windows" + elsif Puppet::Util::Platform.windows? publicdir = File.join(ENV['ALLUSERSPROFILE'], "PuppetLabs", "puppet", "public") else publicdir = "/opt/puppetlabs/puppet/public" @@ -241,7 +240,7 @@ def prepare_installation if not InstallOptions.rundir.nil? rundir = InstallOptions.rundir - elsif $osname == "windows" + elsif Puppet::Util::Platform.windows? rundir = File.join(ENV['ALLUSERSPROFILE'], "PuppetLabs", "puppet", "var", "run") else rundir = "/var/run/puppetlabs" @@ -249,7 +248,7 @@ def prepare_installation if not InstallOptions.logdir.nil? logdir = InstallOptions.logdir - elsif $osname == "windows" + elsif Puppet::Util::Platform.windows? logdir = File.join(ENV['ALLUSERSPROFILE'], "PuppetLabs", "puppet", "var", "log") else logdir = "/var/log/puppetlabs/puppet" @@ -264,7 +263,7 @@ def prepare_installation if not InstallOptions.localedir.nil? localedir = InstallOptions.localedir else - if $osname == "windows" + if Puppet::Util::Platform.windows? localedir = File.join(ENV['PROGRAMFILES'], "Puppet Labs", "Puppet", "puppet", "share", "locale") else localedir = "/opt/puppetlabs/puppet/share/locale" @@ -338,7 +337,7 @@ def prepare_installation # by stripping the drive letter, but only if the basedir is not empty. # def join(basedir, dir) - return "#{basedir}#{dir[2..-1]}" if $osname == "windows" and basedir.length > 0 and dir.length > 2 + return "#{basedir}#{dir[2..-1]}" if Puppet::Util::Platform.windows? and basedir.length > 0 and dir.length > 2 "#{basedir}#{dir}" end @@ -359,14 +358,14 @@ def install_binfile(from, op_file, target) File.open(from) do |ip| File.open(tmp_file.path, "w") do |op| - op.puts "#!#{ruby}" unless $osname == "windows" + op.puts "#!#{ruby}" unless Puppet::Util::Platform.windows? contents = ip.readlines contents.shift if contents[0] =~ /^#!/ op.write contents.join end end - if $osname == "windows" && InstallOptions.batch_files + if Puppet::Util::Platform.windows? && InstallOptions.batch_files installed_wrapper = false unless File.extname(from) =~ /\.(cmd|bat)/ @@ -414,14 +413,14 @@ def install_binfile(from, op_file, target) prepare_installation - if $osname == "windows" + if Puppet::Util::Platform.windows? windows_bins = glob(%w{ext/windows/*bat}) end do_configs(configs, InstallOptions.config_dir) if InstallOptions.configs do_bins(bins, InstallOptions.bin_dir) - do_bins(windows_bins, InstallOptions.bin_dir, 'ext/windows/') if $osname == "windows" && InstallOptions.batch_files + do_bins(windows_bins, InstallOptions.bin_dir, 'ext/windows/') if Puppet::Util::Platform.windows? && InstallOptions.batch_files do_libs(libs) do_locales(locales) - do_man(man) unless $osname == "windows" + do_man(man) unless Puppet::Util::Platform.windows? end From 1d41ce73731fbda4adee4ecb9ea5fac9228255fd Mon Sep 17 00:00:00 2001 From: Ewoud Kohl van Wijngaarden Date: Fri, 27 Sep 2024 16:57:24 +0200 Subject: [PATCH 3/5] Remove prerequisite checking in install.rb Facter is no longer needed in this script and the actual prerequisite checking was unmaintained anyway. --- install.rb | 36 +++--------------------------------- 1 file changed, 3 insertions(+), 33 deletions(-) diff --git a/install.rb b/install.rb index 3ff25f4f3ec..6ef2f9fccd6 100755 --- a/install.rb +++ b/install.rb @@ -37,9 +37,6 @@ require_relative 'lib/puppet/util/platform' -PREREQS = %w{openssl facter cgi} -MIN_FACTER_VERSION = 1.5 - InstallOptions = OpenStruct.new def glob(list) @@ -83,8 +80,7 @@ def do_man(man, strip = 'man/') FileUtils.makedirs(om, mode: 0755, verbose: true) FileUtils.chmod(0755, om) FileUtils.install(mf, omf, mode: 0644, preserve: true, verbose: true) - # Solaris does not support gzipped man pages. When called with - # --no-check-prereqs/without facter the default gzip behavior still applies + # Solaris does not support gzipped man pages unless Puppet::Util::Platform.solaris? gzip = %x{which gzip} gzip.chomp! @@ -104,33 +100,11 @@ def do_locales(locale, strip = 'locales/') end end -# Verify that all of the prereqs are installed -def check_prereqs - PREREQS.each { |pre| - begin - require pre - if pre == "facter" - # to_f isn't quite exact for strings like "1.5.1" but is good - # enough for this purpose. - facter_version = Facter.version.to_f - if facter_version < MIN_FACTER_VERSION - puts "Facter version: #{facter_version}; minimum required: #{MIN_FACTER_VERSION}; cannot install" - exit(-1) - end - end - rescue LoadError - puts "Could not load #{pre}; cannot install" - exit(-1) - end - } -end - ## # Prepare the file installation. # def prepare_installation InstallOptions.configs = true - InstallOptions.check_prereqs = true InstallOptions.batch_files = true ARGV.options do |opts| @@ -175,8 +149,8 @@ def prepare_installation opts.on('--mandir[=OPTIONAL]', 'Installation directory for man pages', 'overrides RbConfig::CONFIG["mandir"]') do |mandir| InstallOptions.mandir = mandir end - opts.on('--[no-]check-prereqs', 'Prevents validation of prerequisite libraries', 'Default on') do |prereq| - InstallOptions.check_prereqs = prereq + opts.on('--[no-]check-prereqs', 'Removed option. Remains for compatibility') do + warn "--check-prereqs has been removed" end opts.on('--no-batch-files', 'Prevents installation of batch files for windows', 'Default off') do |batch_files| InstallOptions.batch_files = false @@ -202,10 +176,6 @@ def prepare_installation RbConfig::CONFIG['bindir'] = "/usr/bin" end - if InstallOptions.check_prereqs - check_prereqs - end - if not InstallOptions.configdir.nil? configdir = InstallOptions.configdir elsif Puppet::Util::Platform.windows? From 7302700b5c5882b67295b300af0b090ff68d4882 Mon Sep 17 00:00:00 2001 From: Ewoud Kohl van Wijngaarden Date: Thu, 26 Sep 2024 15:31:41 +0200 Subject: [PATCH 4/5] Set install options defaults before setting up the parser This has the benefit that the help texts reflect the actual defaults. --- install.rb | 223 ++++++++++++++++++++++------------------------------- 1 file changed, 91 insertions(+), 132 deletions(-) diff --git a/install.rb b/install.rb index 6ef2f9fccd6..b5a4b3f9526 100755 --- a/install.rb +++ b/install.rb @@ -104,56 +104,117 @@ def do_locales(locale, strip = 'locales/') # Prepare the file installation. # def prepare_installation + # Mac OS X 10.5 and higher declare bindir + # /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin + # which is not generally where people expect executables to be installed + # These settings are appropriate defaults for all OS X versions. + if RUBY_PLATFORM =~ /^universal-darwin[\d\.]+$/ + RbConfig::CONFIG['bindir'] = "/usr/bin" + end + InstallOptions.configs = true - InstallOptions.batch_files = true + InstallOptions.destdir = '' + InstallOptions.configdir = if Puppet::Util::Platform.windows? + File.join(ENV['ALLUSERSPROFILE'], "PuppetLabs", "puppet", "etc") + else + "/etc/puppetlabs/puppet" + end + InstallOptions.codedir = if Puppet::Util::Platform.windows? + File.join(ENV['ALLUSERSPROFILE'], "PuppetLabs", "code") + else + "/etc/puppetlabs/code" + end + InstallOptions.vardir = if Puppet::Util::Platform.windows? + File.join(ENV['ALLUSERSPROFILE'], "PuppetLabs", "puppet", "cache") + else + "/opt/puppetlabs/puppet/cache" + end + InstallOptions.publicdir = if Puppet::Util::Platform.windows? + File.join(ENV['ALLUSERSPROFILE'], "PuppetLabs", "puppet", "public") + else + "/opt/puppetlabs/puppet/public" + end + InstallOptions.rundir = if Puppet::Util::Platform.windows? + File.join(ENV['ALLUSERSPROFILE'], "PuppetLabs", "puppet", "var", "run") + else + "/var/run/puppetlabs" + end + InstallOptions.logdir = if Puppet::Util::Platform.windows? + File.join(ENV['ALLUSERSPROFILE'], "PuppetLabs", "puppet", "var", "log") + else + "/var/log/puppetlabs/puppet" + end + InstallOptions.bindir = RbConfig::CONFIG['bindir'] + + InstallOptions.localedir = if Puppet::Util::Platform.windows? + File.join(ENV['PROGRAMFILES'], "Puppet Labs", "Puppet", "puppet", "share", "locale") + else + "/opt/puppetlabs/puppet/share/locale" + end + + InstallOptions.ruby = File.join(RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name']) + + InstallOptions.sitelibdir = RbConfig::CONFIG.fetch("sitelibdir") do + sitelibdir = $LOAD_PATH.find { |x| x.include?('site_ruby') } + if sitelibdir.nil? + version = [RbConfig::CONFIG["MAJOR"], RbConfig::CONFIG["MINOR"]].join(".") + sitelibdir = File.join(RbConfig::CONFIG["libdir"], "ruby", version, "site_ruby") + elsif !sitelibdir.include?(version) + sitelibdir = File.join(sitelibdir, version) + end + sitelibdir + end + + InstallOptions.mandir = RbConfig::CONFIG['mandir'] + InstallOptions.batch_files = Puppet::Util::Platform.windows? ARGV.options do |opts| opts.banner = "Usage: #{File.basename($0)} [options]" opts.separator "" - opts.on('--[no-]configs', 'Prevents the installation of config files', 'Default off.') do |ontest| + opts.on('--[no-]configs', 'Whether to install config files or not', "Default '#{InstallOptions.configs}'") do |ontest| InstallOptions.configs = ontest end - opts.on('--destdir[=OPTIONAL]', 'Installation prefix for all targets', 'Default essentially /') do |destdir| + opts.on('--destdir[=OPTIONAL]', 'Installation prefix for all targets', "Default '#{InstallOptions.destdir}'") do |destdir| InstallOptions.destdir = destdir end - opts.on('--configdir[=OPTIONAL]', 'Installation directory for config files', 'Default /etc/puppetlabs/puppet') do |configdir| + opts.on('--configdir[=OPTIONAL]', 'Installation directory for config files', "Default '#{InstallOptions.configdir}'") do |configdir| InstallOptions.configdir = configdir end - opts.on('--codedir[=OPTIONAL]', 'Installation directory for code files', 'Default /etc/puppetlabs/code') do |codedir| + opts.on('--codedir[=OPTIONAL]', 'Installation directory for code files', "Default '#{InstallOptions.codedir}'") do |codedir| InstallOptions.codedir = codedir end - opts.on('--vardir[=OPTIONAL]', 'Installation directory for var files', 'Default /opt/puppetlabs/puppet/cache') do |vardir| + opts.on('--vardir[=OPTIONAL]', 'Installation directory for var files', "Default '#{InstallOptions.vardir}'") do |vardir| InstallOptions.vardir = vardir end - opts.on('--publicdir[=OPTIONAL]', 'Installation directory for public files such as the `last_run_summary.yaml` report', 'Default /opt/puppetlabs/puppet/public') do |publicdir| + opts.on('--publicdir[=OPTIONAL]', 'Installation directory for public files such as the `last_run_summary.yaml` report', "Default '#{InstallOptions.vardir}'") do |publicdir| InstallOptions.publicdir = publicdir end - opts.on('--rundir[=OPTIONAL]', 'Installation directory for state files', 'Default /var/run/puppetlabs') do |rundir| + opts.on('--rundir[=OPTIONAL]', 'Installation directory for state files', "Default '#{InstallOptions.rundir}'") do |rundir| InstallOptions.rundir = rundir end - opts.on('--logdir[=OPTIONAL]', 'Installation directory for log files', 'Default /var/log/puppetlabs/puppet') do |logdir| + opts.on('--logdir[=OPTIONAL]', 'Installation directory for log files', "Default '#{InstallOptions.logdir}'") do |logdir| InstallOptions.logdir = logdir end - opts.on('--bindir[=OPTIONAL]', 'Installation directory for binaries', 'overrides RbConfig::CONFIG["bindir"]') do |bindir| + opts.on('--bindir[=OPTIONAL]', 'Installation directory for binaries', "Default '#{InstallOptions.bindir}'") do |bindir| InstallOptions.bindir = bindir end - opts.on('--localedir[=OPTIONAL]', 'Installation directory for locale information', 'Default /opt/puppetlabs/puppet/share/locale') do |localedir| + opts.on('--localedir[=OPTIONAL]', 'Installation directory for locale information', "Default '#{InstallOptions.localedir}'") do |localedir| InstallOptions.localedir = localedir end - opts.on('--ruby[=OPTIONAL]', 'Ruby interpreter to use with installation', 'overrides ruby used to call install.rb') do |ruby| + opts.on('--ruby[=OPTIONAL]', 'Ruby interpreter to use with installation', "Default '#{InstallOptions.ruby}'") do |ruby| InstallOptions.ruby = ruby end - opts.on('--sitelibdir[=OPTIONAL]', 'Installation directory for libraries', 'overrides RbConfig::CONFIG["sitelibdir"]') do |sitelibdir| + opts.on('--sitelibdir[=OPTIONAL]', 'Installation directory for libraries', "Default '#{InstallOptions.sitelibdir}'") do |sitelibdir| InstallOptions.sitelibdir = sitelibdir end - opts.on('--mandir[=OPTIONAL]', 'Installation directory for man pages', 'overrides RbConfig::CONFIG["mandir"]') do |mandir| + opts.on('--mandir[=OPTIONAL]', 'Installation directory for man pages', "Default '#{InstallOptions.mandir}'") do |mandir| InstallOptions.mandir = mandir end opts.on('--[no-]check-prereqs', 'Removed option. Remains for compatibility') do warn "--check-prereqs has been removed" end - opts.on('--no-batch-files', 'Prevents installation of batch files for windows', 'Default off') do |batch_files| - InstallOptions.batch_files = false + opts.on('--[no-]batch-files', 'Install batch files for windows', "Default '#{InstallOptions.batch_files}'") do |batch_files| + InstallOptions.batch_files = batch_files end opts.on('--quick', 'Performs a quick installation. Only the', 'installation is done.') do |quick| InstallOptions.configs = true @@ -168,116 +229,18 @@ def prepare_installation opts.parse! end - # Mac OS X 10.5 and higher declare bindir - # /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin - # which is not generally where people expect executables to be installed - # These settings are appropriate defaults for all OS X versions. - if RUBY_PLATFORM =~ /^universal-darwin[\d\.]+$/ - RbConfig::CONFIG['bindir'] = "/usr/bin" - end - - if not InstallOptions.configdir.nil? - configdir = InstallOptions.configdir - elsif Puppet::Util::Platform.windows? - configdir = File.join(ENV['ALLUSERSPROFILE'], "PuppetLabs", "puppet", "etc") - else - configdir = "/etc/puppetlabs/puppet" - end - - if not InstallOptions.codedir.nil? - codedir = InstallOptions.codedir - elsif Puppet::Util::Platform.windows? - codedir = File.join(ENV['ALLUSERSPROFILE'], "PuppetLabs", "code") - else - codedir = "/etc/puppetlabs/code" - end - - if not InstallOptions.vardir.nil? - vardir = InstallOptions.vardir - elsif Puppet::Util::Platform.windows? - vardir = File.join(ENV['ALLUSERSPROFILE'], "PuppetLabs", "puppet", "cache") - else - vardir = "/opt/puppetlabs/puppet/cache" - end - - if not InstallOptions.publicdir.nil? - publicdir = InstallOptions.publicdir - elsif Puppet::Util::Platform.windows? - publicdir = File.join(ENV['ALLUSERSPROFILE'], "PuppetLabs", "puppet", "public") - else - publicdir = "/opt/puppetlabs/puppet/public" - end - - if not InstallOptions.rundir.nil? - rundir = InstallOptions.rundir - elsif Puppet::Util::Platform.windows? - rundir = File.join(ENV['ALLUSERSPROFILE'], "PuppetLabs", "puppet", "var", "run") - else - rundir = "/var/run/puppetlabs" - end - - if not InstallOptions.logdir.nil? - logdir = InstallOptions.logdir - elsif Puppet::Util::Platform.windows? - logdir = File.join(ENV['ALLUSERSPROFILE'], "PuppetLabs", "puppet", "var", "log") - else - logdir = "/var/log/puppetlabs/puppet" - end - - if not InstallOptions.bindir.nil? - bindir = InstallOptions.bindir - else - bindir = RbConfig::CONFIG['bindir'] - end + destdir = InstallOptions.destdir - if not InstallOptions.localedir.nil? - localedir = InstallOptions.localedir - else - if Puppet::Util::Platform.windows? - localedir = File.join(ENV['PROGRAMFILES'], "Puppet Labs", "Puppet", "puppet", "share", "locale") - else - localedir = "/opt/puppetlabs/puppet/share/locale" - end - end - - if not InstallOptions.sitelibdir.nil? - sitelibdir = InstallOptions.sitelibdir - else - sitelibdir = RbConfig::CONFIG["sitelibdir"] - if sitelibdir.nil? - sitelibdir = $LOAD_PATH.find { |x| x =~ /site_ruby/ } - if sitelibdir.nil? - version = [RbConfig::CONFIG["MAJOR"], RbConfig::CONFIG["MINOR"]].join(".") - sitelibdir = File.join(RbConfig::CONFIG["libdir"], "ruby", version, "site_ruby") - elsif sitelibdir !~ Regexp.quote(version) - sitelibdir = File.join(sitelibdir, version) - end - end - end - - if not InstallOptions.mandir.nil? - mandir = InstallOptions.mandir - else - mandir = RbConfig::CONFIG['mandir'] - end - - # This is the new way forward - if not InstallOptions.destdir.nil? - destdir = InstallOptions.destdir - else - destdir = '' - end - - configdir = join(destdir, configdir) - codedir = join(destdir, codedir) - vardir = join(destdir, vardir) - publicdir = join(destdir, publicdir) - rundir = join(destdir, rundir) - logdir = join(destdir, logdir) - bindir = join(destdir, bindir) - localedir = join(destdir, localedir) - mandir = join(destdir, mandir) - sitelibdir = join(destdir, sitelibdir) + configdir = join(destdir, InstallOptions.configdir) + codedir = join(destdir, InstallOptions.codedir) + vardir = join(destdir, InstallOptions.vardir) + publicdir = join(destdir, InstallOptions.publicdir) + rundir = join(destdir, InstallOptions.rundir) + logdir = join(destdir, InstallOptions.logdir) + bindir = join(destdir, InstallOptions.bindir) + localedir = join(destdir, InstallOptions.localedir) + mandir = join(destdir, InstallOptions.mandir) + sitelibdir = join(destdir, InstallOptions.sitelibdir) FileUtils.makedirs(configdir) if InstallOptions.configs FileUtils.makedirs(codedir) @@ -320,11 +283,7 @@ def join(basedir, dir) def install_binfile(from, op_file, target) tmp_file = Tempfile.new('puppet-binfile') - if not InstallOptions.ruby.nil? - ruby = InstallOptions.ruby - else - ruby = File.join(RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name']) - end + ruby = InstallOptions.ruby File.open(from) do |ip| File.open(tmp_file.path, "w") do |op| @@ -335,7 +294,7 @@ def install_binfile(from, op_file, target) end end - if Puppet::Util::Platform.windows? && InstallOptions.batch_files + if InstallOptions.batch_files installed_wrapper = false unless File.extname(from) =~ /\.(cmd|bat)/ @@ -389,7 +348,7 @@ def install_binfile(from, op_file, target) do_configs(configs, InstallOptions.config_dir) if InstallOptions.configs do_bins(bins, InstallOptions.bin_dir) - do_bins(windows_bins, InstallOptions.bin_dir, 'ext/windows/') if Puppet::Util::Platform.windows? && InstallOptions.batch_files + do_bins(windows_bins, InstallOptions.bin_dir, 'ext/windows/') if InstallOptions.batch_files do_libs(libs) do_locales(locales) do_man(man) unless Puppet::Util::Platform.windows? From 3df67bbee15b3dbacc52f245dfdebf0f952e5774 Mon Sep 17 00:00:00 2001 From: Ewoud Kohl van Wijngaarden Date: Thu, 26 Sep 2024 15:31:41 +0200 Subject: [PATCH 5/5] Load install paths from RunMode This avoids duplicating the defaults that already exist within the run mode. It also opens up the path to more run modes where the paths could be different. --- install.rb | 49 +++++++++++++++++++------------------------------ 1 file changed, 19 insertions(+), 30 deletions(-) diff --git a/install.rb b/install.rb index b5a4b3f9526..41b9d6bcda1 100755 --- a/install.rb +++ b/install.rb @@ -36,6 +36,18 @@ require 'ostruct' require_relative 'lib/puppet/util/platform' +require_relative 'lib/puppet/util/run_mode' + +module ForcedRoot + private + + # Override the installation to always assume system installations + # This also removes the dependency on Puppet.features.root? + def which_dir(system, user) + system + end +end +Puppet::Util::RunMode.prepend(ForcedRoot) InstallOptions = OpenStruct.new @@ -112,38 +124,15 @@ def prepare_installation RbConfig::CONFIG['bindir'] = "/usr/bin" end + run_mode = Puppet::Util::RunMode[:agent] InstallOptions.configs = true InstallOptions.destdir = '' - InstallOptions.configdir = if Puppet::Util::Platform.windows? - File.join(ENV['ALLUSERSPROFILE'], "PuppetLabs", "puppet", "etc") - else - "/etc/puppetlabs/puppet" - end - InstallOptions.codedir = if Puppet::Util::Platform.windows? - File.join(ENV['ALLUSERSPROFILE'], "PuppetLabs", "code") - else - "/etc/puppetlabs/code" - end - InstallOptions.vardir = if Puppet::Util::Platform.windows? - File.join(ENV['ALLUSERSPROFILE'], "PuppetLabs", "puppet", "cache") - else - "/opt/puppetlabs/puppet/cache" - end - InstallOptions.publicdir = if Puppet::Util::Platform.windows? - File.join(ENV['ALLUSERSPROFILE'], "PuppetLabs", "puppet", "public") - else - "/opt/puppetlabs/puppet/public" - end - InstallOptions.rundir = if Puppet::Util::Platform.windows? - File.join(ENV['ALLUSERSPROFILE'], "PuppetLabs", "puppet", "var", "run") - else - "/var/run/puppetlabs" - end - InstallOptions.logdir = if Puppet::Util::Platform.windows? - File.join(ENV['ALLUSERSPROFILE'], "PuppetLabs", "puppet", "var", "log") - else - "/var/log/puppetlabs/puppet" - end + InstallOptions.configdir = run_mode.conf_dir + InstallOptions.codedir = run_mode.code_dir + InstallOptions.vardir = run_mode.var_dir + InstallOptions.publicdir = run_mode.public_dir + InstallOptions.rundir = run_mode.run_dir + InstallOptions.logdir = run_mode.log_dir InstallOptions.bindir = RbConfig::CONFIG['bindir'] InstallOptions.localedir = if Puppet::Util::Platform.windows?