diff --git a/src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs b/src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs index b6ca2bdd39..af1b7934c9 100644 --- a/src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs +++ b/src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs @@ -28,6 +28,7 @@ namespace chocolatey.infrastructure.app.builders using information; using infrastructure.services; using logging; + using nuget; using platforms; using tolerance; using Environment = adapters.Environment; @@ -64,6 +65,7 @@ public static void set_up_configuration(IList args, ChocolateyConfigurat ConfigurationOptions.reset_options(); set_global_options(args, config); set_environment_options(config); + set_environment_variables(config); } private static void set_file_configuration(ChocolateyConfiguration config, IFileSystem fileSystem, IXmlService xmlService, Action notifyWarnLoggingAction) @@ -324,5 +326,50 @@ private static void set_environment_options(ChocolateyConfiguration config) config.Information.IsUserAdministrator = ProcessInformation.user_is_administrator(); config.Information.IsProcessElevated = ProcessInformation.process_is_elevated(); } + + public static void set_environment_variables(ChocolateyConfiguration config) + { + Environment.SetEnvironmentVariable(ApplicationParameters.ChocolateyInstallEnvironmentVariableName, ApplicationParameters.InstallLocation); + Environment.SetEnvironmentVariable("CHOCOLATEY_VERSION", config.Information.ChocolateyVersion); + Environment.SetEnvironmentVariable("CHOCOLATEY_VERSION_PRODUCT", config.Information.ChocolateyProductVersion); + Environment.SetEnvironmentVariable("OS_PLATFORM", config.Information.PlatformType.get_description_or_value()); + Environment.SetEnvironmentVariable("OS_VERSION", config.Information.PlatformVersion.to_string()); + Environment.SetEnvironmentVariable("OS_NAME", config.Information.PlatformName.to_string()); + // experimental until we know if this value returns correctly based on the OS and not the current process. + Environment.SetEnvironmentVariable("OS_IS64BIT", config.Information.Is64Bit ? "true" : "false"); + Environment.SetEnvironmentVariable("IS_ADMIN", config.Information.IsUserAdministrator ? "true" : "false"); + Environment.SetEnvironmentVariable("IS_PROCESSELEVATED", config.Information.IsProcessElevated ? "true" : "false"); + + Environment.SetEnvironmentVariable("TEMP", config.CacheLocation); + if (config.Debug) + { + Environment.SetEnvironmentVariable("ChocolateyEnvironmentDebug", "true"); + } + if (config.Verbose) + { + Environment.SetEnvironmentVariable("ChocolateyEnvironmentVerbose", "true"); + } + if (!config.Features.CheckSumFiles) + { + Environment.SetEnvironmentVariable("ChocolateyIgnoreChecksums", "true"); + } + if (!string.IsNullOrWhiteSpace(config.Proxy.Location)) + { + var proxyCreds = string.Empty; + if (!string.IsNullOrWhiteSpace(config.Proxy.User) && + !string.IsNullOrWhiteSpace(config.Proxy.EncryptedPassword) + ) + { + proxyCreds = "{0}:{1}@".format_with(config.Proxy.User, NugetEncryptionUtility.DecryptString(config.Proxy.EncryptedPassword)); + + Environment.SetEnvironmentVariable("chocolateyProxyUser", config.Proxy.User); + Environment.SetEnvironmentVariable("chocolateyProxyPassword", NugetEncryptionUtility.DecryptString(config.Proxy.EncryptedPassword)); + } + + Environment.SetEnvironmentVariable("http_proxy", "{0}{1}".format_with(proxyCreds, config.Proxy.Location)); + Environment.SetEnvironmentVariable("https_proxy", "{0}{1}".format_with(proxyCreds, config.Proxy.Location)); + Environment.SetEnvironmentVariable("chocolateyProxyLocation", config.Proxy.Location); + } + } } } \ No newline at end of file diff --git a/src/chocolatey/infrastructure.app/services/PowershellService.cs b/src/chocolatey/infrastructure.app/services/PowershellService.cs index 7bf14e29c1..cd5f7853b5 100644 --- a/src/chocolatey/infrastructure.app/services/PowershellService.cs +++ b/src/chocolatey/infrastructure.app/services/PowershellService.cs @@ -18,6 +18,7 @@ namespace chocolatey.infrastructure.app.services using System.IO; using System.Linq; using adapters; + using builders; using commandline; using configuration; using domain; @@ -165,17 +166,10 @@ public bool run_action(ChocolateyConfiguration configuration, PackageResult pack var failure = false; + //todo: this is here for any possible compatibility issues. Should be reviewed and removed. + ConfigurationBuilder.set_environment_variables(configuration); + var package = packageResult.Package; - Environment.SetEnvironmentVariable(ApplicationParameters.ChocolateyInstallEnvironmentVariableName, ApplicationParameters.InstallLocation); - Environment.SetEnvironmentVariable("CHOCOLATEY_VERSION", configuration.Information.ChocolateyVersion); - Environment.SetEnvironmentVariable("CHOCOLATEY_VERSION_PRODUCT", configuration.Information.ChocolateyProductVersion); - Environment.SetEnvironmentVariable("OS_PLATFORM", configuration.Information.PlatformType.get_description_or_value()); - Environment.SetEnvironmentVariable("OS_VERSION", configuration.Information.PlatformVersion.to_string()); - Environment.SetEnvironmentVariable("OS_NAME", configuration.Information.PlatformName.to_string()); - // experimental until we know if this value returns correctly based on the OS and not the current process. - Environment.SetEnvironmentVariable("OS_IS64BIT", configuration.Information.Is64Bit ? "true" : "false"); - Environment.SetEnvironmentVariable("IS_ADMIN", configuration.Information.IsUserAdministrator ? "true" : "false"); - Environment.SetEnvironmentVariable("IS_PROCESSELEVATED", configuration.Information.IsProcessElevated ? "true" : "false"); Environment.SetEnvironmentVariable("chocolateyPackageName", package.Id); Environment.SetEnvironmentVariable("packageName", package.Id); Environment.SetEnvironmentVariable("chocolateyPackageVersion", package.Version.to_string()); @@ -195,42 +189,12 @@ public bool run_action(ChocolateyConfiguration configuration, PackageResult pack { Environment.SetEnvironmentVariable("chocolateyInstallOverride", "true"); } - - Environment.SetEnvironmentVariable("TEMP", configuration.CacheLocation); - + if (configuration.NotSilent) { Environment.SetEnvironmentVariable("chocolateyInstallOverride", "true"); } - if (configuration.Debug) - { - Environment.SetEnvironmentVariable("ChocolateyEnvironmentDebug", "true"); - } - if (configuration.Verbose) - { - Environment.SetEnvironmentVariable("ChocolateyEnvironmentVerbose", "true"); - } - if (!configuration.Features.CheckSumFiles) - { - Environment.SetEnvironmentVariable("ChocolateyIgnoreChecksums", "true"); - } - if (!string.IsNullOrWhiteSpace(configuration.Proxy.Location)) - { - var proxy_creds = string.Empty; - if (!string.IsNullOrWhiteSpace(configuration.Proxy.User) && - !string.IsNullOrWhiteSpace(configuration.Proxy.EncryptedPassword) - ) - { - proxy_creds = "{0}:{1}@".format_with(configuration.Proxy.User, NugetEncryptionUtility.DecryptString(configuration.Proxy.EncryptedPassword)); - - Environment.SetEnvironmentVariable("chocolateyProxyUser", configuration.Proxy.User); - Environment.SetEnvironmentVariable("chocolateyProxyPassword", NugetEncryptionUtility.DecryptString(configuration.Proxy.EncryptedPassword)); - } - - Environment.SetEnvironmentVariable("http_proxy", "{0}{1}".format_with(proxy_creds, configuration.Proxy.Location)); - Environment.SetEnvironmentVariable("https_proxy", "{0}{1}".format_with(proxy_creds, configuration.Proxy.Location)); - Environment.SetEnvironmentVariable("chocolateyProxyLocation", configuration.Proxy.Location); - } + //todo:if (configuration.NoOutput) //{ // Environment.SetEnvironmentVariable("ChocolateyEnvironmentQuiet","true");