Skip to content

Commit

Permalink
Merge branch 'stable'
Browse files Browse the repository at this point in the history
* stable:
  (chocolateyGH-1193) Allow version check with FIPS
  (chocolateyGH-1155) do not warn nupkg on pack/push
  (chocolateyGH-1187) File64 - Install-ChocolateyInstallPackage
  (maint) Add 64-bit process Information variable
  (chocolateyGH-1155) Warn when .nupkg/.nuspec used in args
  (chocolateyGH-262) BypassProxy on IHttpClient
  (chocolateyGH-1134) use console adapter for width
  (chocolateyGH-1182) trace network traffic
  (chocolateyGH-1181) Configure a source for self-service
  (chocolateyGH-1180) Create .ignore file only in choco path
  (chocolateyGH-1177) Fix: MSU fails when spaces in path
  (maint) formatting
  (chocolateyGH-1178) Fix: OS_NAME not reported as Windows 10
  (chocolateyGH-1134) ensure GetPackageManager w/older licensed
  (chocolateyGH-1165) pass proxy bypass list to debug message
  • Loading branch information
ferventcoder committed Mar 9, 2017
2 parents 0f602f7 + ebfdaa2 commit 81b6797
Show file tree
Hide file tree
Showing 20 changed files with 383 additions and 40 deletions.
Binary file modified lib/NuGet-Chocolatey/NuGet.Core.dll
Binary file not shown.
11 changes: 11 additions & 0 deletions src/chocolatey.console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ private static void Main(string[] args)

trap_exit_scenarios(config);

warn_on_nuspec_or_nupkg_usage(args, config);

if (config.RegularOutput)
{
"LogFileOnly".Log().Info(() => "".PadRight(60, '='));
Expand Down Expand Up @@ -111,6 +113,7 @@ private static void Main(string[] args)

Log4NetAppenderConfiguration.set_logging_level_debug_when_debug(config.Debug, excludeLoggerName: "{0}LoggingColoredConsoleAppender".format_with(ChocolateyLoggers.Verbose.to_string()));
Log4NetAppenderConfiguration.set_verbose_logger_when_verbose(config.Verbose, config.Debug, "{0}LoggingColoredConsoleAppender".format_with(ChocolateyLoggers.Verbose.to_string()));
Log4NetAppenderConfiguration.set_trace_logger_when_trace(config.Trace, "{0}LoggingColoredConsoleAppender".format_with(ChocolateyLoggers.Trace.to_string()));
"chocolatey".Log().Debug(() => "{0} is running on {1} v {2}".format_with(ApplicationParameters.Name, config.Information.PlatformType, config.Information.PlatformVersion.to_string()));
//"chocolatey".Log().Debug(() => "Command Line: {0}".format_with(Environment.CommandLine));

Expand Down Expand Up @@ -157,6 +160,14 @@ private static void Main(string[] args)
}
}

private static void warn_on_nuspec_or_nupkg_usage(string[] args, ChocolateyConfiguration config)
{
if (!args.Any(a => a.contains("pack") || a.contains("push")) && args.Any(a => a.contains(".nupkg") || a.contains(".nuspec")))
{
if (config.RegularOutput) "chocolatey".Log().Warn("The use of .nupkg or .nuspec in for package name or source is known to cause issues. Please use the package id from the nuspec `<id />` with `-s .` (for local folder where nupkg is found).");
}
}

private static ResolveEventHandler _handler = null;

private static void add_assembly_resolver()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,18 @@ you can get it to the path with
In 0.10.1+, `FileFullPath` is an alias for File.
This can be a 32-bit or 64-bit file. This is mandatory in earlier versions
of Chocolatey, but optional if File64 has been provided.
.PARAMETER File64
Full file path to a 64-bit native installer to run. Available in 0.10.4+.
If embedding in the package, you can get it to the path with
`"$(Split-Path -parent $MyInvocation.MyCommand.Definition)\\INSTALLER_FILE"`
Provide this when you want to provide both 32-bit and 64-bit
installers or explicitly only a 64-bit installer (which will cause a package
install failure on 32-bit systems).
.PARAMETER ValidExitCodes
Array of exit codes indicating success. Defaults to `@(0)`.
Expand Down Expand Up @@ -146,7 +158,8 @@ param(
[parameter(Mandatory=$false, Position=1)]
[alias("installerType","installType")][string] $fileType = 'exe',
[parameter(Mandatory=$false, Position=2)][string[]] $silentArgs = '',
[alias("fileFullPath")][parameter(Mandatory=$true, Position=3)][string] $file,
[alias("fileFullPath")][parameter(Mandatory=$false, Position=3)][string] $file,
[alias("fileFullPath64")][parameter(Mandatory=$false)][string] $file64,
[parameter(Mandatory=$false)] $validExitCodes = @(0),
[parameter(Mandatory=$false)]
[alias("useOnlyPackageSilentArgs")][switch] $useOnlyPackageSilentArguments = $false,
Expand All @@ -156,16 +169,25 @@ param(

Write-FunctionCallLogMessage -Invocation $MyInvocation -Parameters $PSBoundParameters

$installMessage = "Installing $packageName..."
Write-Host $installMessage

if ($file -eq '' -or $file -eq $null) {
throw 'Package parameters incorrect, File cannot be empty.'
$bitnessMessage = ''
$fileFullPath = $file
if ((Get-ProcessorBits 32) -or $env:ChocolateyForceX86 -eq 'true') {
if (!$file) { throw "32-bit installation is not supported for $packageName"; }
if ($file64) { $bitnessMessage = '32-bit '; }
} elseif ($file64) {
$fileFullPath = $file64
$bitnessMessage = '64-bit '
}


if ($fileFullPath -eq '' -or $fileFullPath -eq $null) {
throw 'Package parameters incorrect, either File or File64 must be specified.'
}

Write-Host "Installing $bitnessMessage$packageName..."

if ($fileType -eq '' -or $fileType -eq $null) {
Write-Debug 'No FileType supplied. Using the file extension to determine FileType'
$fileType = [System.IO.Path]::GetExtension("$file").Replace(".", "")
$fileType = [System.IO.Path]::GetExtension("$fileFullPath").Replace(".", "")
}

$installerTypeLower = $fileType.ToLower()
Expand Down Expand Up @@ -199,23 +221,25 @@ Pro / Business supports a single, ubiquitous install directory option.
# might be a slight issue here if the download path is the older
$silentArgs = $silentArgs -replace '\\chocolatey\\chocolatey\\', '\chocolatey\'
$additionalInstallArgs = $additionalInstallArgs -replace '\\chocolatey\\chocolatey\\', '\chocolatey\'
$updatedFilePath = $file -replace '\\chocolatey\\chocolatey\\', '\chocolatey\'
$updatedFilePath = $fileFullPath -replace '\\chocolatey\\chocolatey\\', '\chocolatey\'
if ([System.IO.File]::Exists($updatedFilePath)) {
$file = $updatedFilePath
$fileFullPath = $updatedFilePath
}

$ignoreFile = $file + '.ignore'
try {
'' | out-file $ignoreFile
} catch {
Write-Warning "Unable to generate `'$ignoreFile`'"
$ignoreFile = $fileFullPath + '.ignore'
if ($env:ChocolateyInstall -and $ignoreFile -match "$env:ChocolateyInstall") {
try {
'' | out-file $ignoreFile
} catch {
Write-Warning "Unable to generate `'$ignoreFile`'"
}
}

$workingDirectory = Get-Location
try {
$workingDirectory = [System.IO.Path]::GetDirectoryName($file)
$workingDirectory = [System.IO.Path]::GetDirectoryName($fileFullPath)
} catch {
Write-Warning "Unable to set the working directory for installer to location of '$file'"
Write-Warning "Unable to set the working directory for installer to location of '$fileFullPath'"
}

try {
Expand All @@ -234,7 +258,7 @@ Pro / Business supports a single, ubiquitous install directory option.
}

if ($fileType -like 'msi') {
$msiArgs = "/i `"$file`""
$msiArgs = "/i `"$fileFullPath`""
if ($overrideArguments) {
Write-Host "Overriding package arguments with '$additionalInstallArgs' (replacing '$silentArgs')";
$msiArgs = "$msiArgs $additionalInstallArgs";
Expand All @@ -248,18 +272,18 @@ Pro / Business supports a single, ubiquitous install directory option.
if ($fileType -like 'exe') {
if ($overrideArguments) {
Write-Host "Overriding package arguments with '$additionalInstallArgs' (replacing '$silentArgs')";
$env:ChocolateyExitCode = Start-ChocolateyProcessAsAdmin "$additionalInstallArgs" $file -validExitCodes $validExitCodes -workingDirectory $workingDirectory
$env:ChocolateyExitCode = Start-ChocolateyProcessAsAdmin "$additionalInstallArgs" $fileFullPath -validExitCodes $validExitCodes -workingDirectory $workingDirectory
} else {
$env:ChocolateyExitCode = Start-ChocolateyProcessAsAdmin "$silentArgs $additionalInstallArgs" $file -validExitCodes $validExitCodes -workingDirectory $workingDirectory
$env:ChocolateyExitCode = Start-ChocolateyProcessAsAdmin "$silentArgs $additionalInstallArgs" $fileFullPath -validExitCodes $validExitCodes -workingDirectory $workingDirectory
}
}

if($fileType -like 'msu') {
if ($overrideArguments) {
Write-Host "Overriding package arguments with '$additionalInstallArgs' (replacing '$silentArgs')";
$msuArgs = "$file $additionalInstallArgs"
$msuArgs = "`"$fileFullPath`" $additionalInstallArgs"
} else {
$msuArgs = "$file $silentArgs $additionalInstallArgs"
$msuArgs = "`"$fileFullPath`" $silentArgs $additionalInstallArgs"
}
$env:ChocolateyExitCode = Start-ChocolateyProcessAsAdmin "$msuArgs" "$($env:SystemRoot)\System32\wusa.exe" -validExitCodes $validExitCodes -workingDirectory $workingDirectory
}
Expand Down
2 changes: 1 addition & 1 deletion src/chocolatey.tests.integration/Scenario.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ private static ChocolateyConfiguration baseline_configuration()
config.Information.ChocolateyVersion = "1.2.3";
config.Information.ChocolateyProductVersion = "1.2.3";
config.Information.FullName = "choco something something";
config.Information.Is64Bit = true;
config.Information.Is64BitOperatingSystem = true;
config.Information.IsInteractive = false;
config.Information.IsUserAdministrator = true;
config.Information.IsProcessElevated = true;
Expand Down
1 change: 1 addition & 0 deletions src/chocolatey/chocolatey.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
<Compile Include="infrastructure.app\events\HandlePackageResultCompletedMessage.cs" />
<Compile Include="infrastructure.app\services\FileTypeDetectorService.cs" />
<Compile Include="infrastructure.app\services\IFileTypeDetectorService.cs" />
<Compile Include="infrastructure\logging\TraceLog.cs" />
<Compile Include="infrastructure\registration\SecurityProtocol.cs" />
<Compile Include="infrastructure\results\PowerShellExecutionResults.cs" />
<Compile Include="infrastructure.app\tasks\RemovePendingPackagesTask.cs" />
Expand Down
20 changes: 17 additions & 3 deletions src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ private static void add_or_remove_licensed_source(ChocolateyLicense license, Con
Password = NugetEncryptionUtility.EncryptString(license.Id),
Priority = 10,
BypassProxy = false,
AllowSelfService = false,
};

if (addOrUpdate && !sources.Any(s =>
Expand Down Expand Up @@ -186,6 +187,7 @@ private static void set_machine_sources(ChocolateyConfiguration config, ConfigFi
EncryptedCertificatePassword = source.CertificatePassword,
Priority = source.Priority,
BypassProxy = source.BypassProxy,
AllowSelfService = source.AllowSelfService,
});
}
}
Expand Down Expand Up @@ -325,8 +327,11 @@ private static void set_global_options(IList<string> args, ChocolateyConfigurati
"Debug - Show debug messaging.",
option => config.Debug = option != null)
.Add("v|verbose",
"Verbose - Show verbose messaging.",
"Verbose - Show verbose messaging. Very verbose messaging, avoid using under normal circumstances.",
option => config.Verbose = option != null)
.Add("trace",
"Trace - Show trace messaging. Very, very verbose trace messaging. Avoid except when needing super low-level .NET Framework debugging. Available in 0.10.4+.",
option => config.Trace = option != null)
.Add("acceptlicense|accept-license",
"AcceptLicense - Accept license dialogs automatically. Reserved for future use.",
option => config.AcceptLicense = option != null)
Expand Down Expand Up @@ -470,7 +475,8 @@ private static void set_environment_options(ChocolateyConfiguration config)
config.Information.ChocolateyVersion = VersionInformation.get_current_assembly_version();
config.Information.ChocolateyProductVersion = VersionInformation.get_current_informational_version();
config.Information.FullName = Assembly.GetExecutingAssembly().FullName;
config.Information.Is64Bit = Environment.Is64BitOperatingSystem;
config.Information.Is64BitOperatingSystem = Environment.Is64BitOperatingSystem;
config.Information.Is64BitProcess = (IntPtr.Size == 8);
config.Information.IsInteractive = Environment.UserInteractive;
config.Information.IsUserAdministrator = ProcessInformation.user_is_administrator();
config.Information.IsProcessElevated = ProcessInformation.process_is_elevated();
Expand Down Expand Up @@ -559,7 +565,15 @@ private static void set_hash_provider(ChocolateyConfiguration config, Container
"chocolatey".Log().Warn(ChocolateyLoggers.Important, @"
FIPS Mode detected - run 'choco feature enable -n {0}'
to use Chocolatey.".format_with(ApplicationParameters.Features.UseFipsCompliantChecksums));
throw new ApplicationException("When FIPS Mode is enabled, Chocolatey requires {0} feature also be enabled.".format_with(ApplicationParameters.Features.UseFipsCompliantChecksums));

var errorMessage = "When FIPS Mode is enabled, Chocolatey requires {0} feature also be enabled.".format_with(ApplicationParameters.Features.UseFipsCompliantChecksums);
if (string.IsNullOrWhiteSpace(config.CommandName))
{
"chocolatey".Log().Error(errorMessage);
return;
}

throw new ApplicationException(errorMessage);
}

throw;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,12 @@ public virtual void configure_argument_parser(OptionSet optionSet, ChocolateyCon
.Add("priority=",
"Priority - The priority order of this source as compared to other sources, lower is better. Defaults to 0 (no priority). All priorities above 0 will be evaluated first, then zero-based values will be evaluated in config file order. Available in 0.9.9.9+.",
option => configuration.SourceCommand.Priority = int.Parse(option.remove_surrounding_quotes()))
.Add("bypassProxy",
"BypassProxy - Should this source explicitly bypass any explicitly or system configured proxies? Defaults to false. Available in 0.10.4+.",
.Add("bypassproxy|bypass-proxy",
"Bypass Proxy - Should this source explicitly bypass any explicitly or system configured proxies? Defaults to false. Available in 0.10.4+.",
option => configuration.SourceCommand.BypassProxy = option != null)
.Add("allowselfservice|allow-self-service",
"Allow Self-Service - Should this source be allowed to be used with self-service? Requires business edition. Defaults to false. Available in 0.10.4+.",
option => configuration.SourceCommand.AllowSelfService = option != null)
;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ private void append_output(StringBuilder propertyValues, string append)

public bool Debug { get; set; }
public bool Verbose { get; set; }
public bool Trace { get; set; }
public bool Force { get; set; }
public bool Noop { get; set; }
public bool HelpRequested { get; set; }
Expand Down Expand Up @@ -328,7 +329,8 @@ public sealed class InformationCommandConfiguration
public string ChocolateyVersion { get; set; }
public string ChocolateyProductVersion { get; set; }
public string FullName { get; set; }
public bool Is64Bit { get; set; }
public bool Is64BitOperatingSystem { get; set; }
public bool Is64BitProcess { get; set; }
public bool IsInteractive { get; set; }
public bool IsUserAdministrator { get; set; }
public bool IsProcessElevated { get; set; }
Expand Down Expand Up @@ -417,6 +419,7 @@ public sealed class SourcesCommandConfiguration
public string Certificate { get; set; }
public string CertificatePassword { get; set; }
public bool BypassProxy { get; set; }
public bool AllowSelfService { get; set; }
}

[Serializable]
Expand All @@ -430,6 +433,7 @@ public sealed class MachineSourceConfiguration
public string Certificate { get; set; }
public string EncryptedCertificatePassword { get; set; }
public bool BypassProxy { get; set; }
public bool AllowSelfService { get; set; }
}

[Serializable]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ public class ChocolateySource

public bool Authenticated { get; set; }

public bool BypassProxy { get; set; }
public bool BypassProxy { get; set; }

public bool AllowSelfService { get; set; }

public int Priority { get; set; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ public sealed class ConfigFileSourceSetting
[XmlAttribute(AttributeName = "bypassProxy")]
public bool BypassProxy { get; set; }

[XmlAttribute(AttributeName = "selfService")]
public bool AllowSelfService { get; set; }

[XmlAttribute(AttributeName = "user")]
public string UserName { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ public static void set_environment_variables(ChocolateyConfiguration config)
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("OS_IS64BIT", config.Information.Is64BitOperatingSystem ? "true" : "false");
Environment.SetEnvironmentVariable("PROCESS_IS64BIT", config.Information.Is64BitProcess ? "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);
Expand Down
Loading

0 comments on commit 81b6797

Please sign in to comment.