Skip to content

Commit

Permalink
Merge branch 'stable'
Browse files Browse the repository at this point in the history
* stable:
  (version) 0.9.9.3
  (doc) update nuspec / changelog for release
  (chocolateyGH-211) Use full path to msiexec
  (chocolateyGH-197) Uninstaller check for registry existence
  (chocolateyGH-167) Get-ChocolateyWebFile create directory
  (chocolateyGH-207) Set up variables for powershell scripts
  (chocolateyGH-202)(log) Enhance formatting escaping
  (chocolateyGH-202) Fix formatting on Noop logging
  (chocolateyGH-208) Do not escape curly braces in scripts
  (chocolateyGH-168) Retry .NET Fx if first install fails
  (chocolateyGH-168) .NET Framework 4.0 install egg/chicken
  (chocolateyGH-207) Some pkgs incorrectly use arguments
  • Loading branch information
ferventcoder committed Mar 29, 2015
2 parents 31e3a62 + 2a86103 commit ce90c21
Show file tree
Hide file tree
Showing 13 changed files with 177 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .uppercut
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<property name="version.major" value="0" overwrite="false" />
<property name="version.minor" value="9" overwrite="false" />
<property name="version.patch" value="9" overwrite="false" />
<property name="version.fix" value="2" overwrite="false" />
<property name="version.fix" value="3" overwrite="false" />
<property name="version.nuget.prerelease" value="" overwrite="false" />
<property name="version.use.build_date" value="false" overwrite="false" />
<property name="assembly.description" value="${project.name} is a product of ${company.name} - All Rights Reserved." overwrite="false" />
Expand Down
22 changes: 20 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
## [0.9.9.2](https://github.com/chocolatey/choco/issues?q=milestone%3A0.9.9.2+is%3Aclosed) (March 6, 2015)
## [0.9.9.3](https://github.com/chocolatey/choco/issues?q=milestone%3A0.9.9.3+is%3Aclosed) (March 29, 2015)

### BUG FIXES

* Fix - Install .NET Framework immediately during install - see [#168](https://github.com/chocolatey/choco/issues/168)
* Fix - Do not error on Set-Acl during install/upgrade - see [#163](https://github.com/chocolatey/choco/issues/163)
* Fix - Do not escape curly braces in powershell script - see [#208](https://github.com/chocolatey/choco/issues/208)
* Fix - Formatting issues on --noop command logging - see [#202](https://github.com/chocolatey/choco/issues/202)
* Fix - Uninstaller check doesn't find 32-bit registry keys - see [#197](https://github.com/chocolatey/choco/issues/197)
* Fix - Uninstaller errors on short path to msiexec - see [#211](https://github.com/chocolatey/choco/issues/211)

### IMPROVEMENTS

* Some packages use non-API variables like $installArguments - see [#207](https://github.com/chocolatey/choco/issues/207)
* Add Generate-BinFile to Helpers (widely used but never part of API) - see [#145](https://github.com/chocolatey/choco/issues/145)
* Add Remove-BinFile to Helpers - see [#195](https://github.com/chocolatey/choco/issues/195)
* Get-ChocolateyWebFile should create path if it doesn't exist - see [#167](https://github.com/chocolatey/choco/issues/167)

## [0.9.9.2](https://github.com/chocolatey/choco/issues?q=milestone%3A0.9.9.2+is%3Aclosed) (March 6, 2015)

### BUG FIXES

Expand All @@ -10,7 +28,7 @@

* Upgrade `-r` should always return a value - see [#153](https://github.com/chocolatey/choco/issues/153)

## [0.9.9.1](https://github.com/chocolatey/choco/issues?q=milestone%3A0.9.9.1+is%3Aclosed) (March 3, 2015)
## [0.9.9.1](https://github.com/chocolatey/choco/issues?q=milestone%3A0.9.9.1+is%3Aclosed) (March 3, 2015)

### BUG FIXES

Expand Down
18 changes: 18 additions & 0 deletions nuget/chocolatey/chocolatey.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,24 @@ In that mess there is a link to the [Helper Reference](https://github.com/chocol
<releaseNotes>
See all - https://github.com/chocolatey/choco/blob/master/CHANGELOG.md

## 0.9.9.3

### BUG FIXES

* Fix - Install .NET Framework immediately during install - see [#168](https://github.com/chocolatey/choco/issues/168)
* Fix - Do not error on Set-Acl during install/upgrade - see [#163](https://github.com/chocolatey/choco/issues/163)
* Fix - Do not escape curly braces in powershell script - see [#208](https://github.com/chocolatey/choco/issues/208)
* Fix - Formatting issues on --noop command logging - see [#202](https://github.com/chocolatey/choco/issues/202)
* Fix - Uninstaller check doesn't find 32-bit registry keys - see [#197](https://github.com/chocolatey/choco/issues/197)
* Fix - Uninstaller errors on short path to msiexec - see [#211](https://github.com/chocolatey/choco/issues/211)

### IMPROVEMENTS

* Some packages use non-API variables like $installArguments - see [#207](https://github.com/chocolatey/choco/issues/207)
* Add Generate-BinFile to Helpers (widely used but never part of API) - see [#145](https://github.com/chocolatey/choco/issues/145)
* Add Remove-BinFile to Helpers - see [#195](https://github.com/chocolatey/choco/issues/195)
* Get-ChocolateyWebFile should create path if it doesn't exist - see [#167](https://github.com/chocolatey/choco/issues/167)

## 0.9.9.2

### BUG FIXES
Expand Down
54 changes: 48 additions & 6 deletions nuget/chocolatey/tools/chocolateysetup.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -445,16 +445,58 @@ param(
}
}

$netFx4InstallTries = 0

function Install-DotNet4IfMissing {
param(
$forceFxInstall = $false
)
# we can't take advantage of any chocolatey module functions, because they
# haven't been unpacked because they require .NET Framework 4.0

Write-Debug "Install-DotNet4IfMissing"
if ([IntPtr]::Size -eq 8) {$fx="framework64"} else {$fx="framework"}

Write-Debug "Installing .NET Framework 4.0 if it is missing"
if (!(test-path "$env:windir\Microsoft.Net\$fx\v4.0.30319")) {
Write-Host "Downloading and installing .NET Framework 4.0"
$NetFx4ClientUrl = 'http://download.microsoft.com/download/5/6/2/562A10F9-C9F4-4313-A044-9C94E0A8FAC8/dotNetFx40_Client_x86_x64.exe'
$NetFx4FullUrl = 'http://download.microsoft.com/download/9/5/A/95A9616B-7A37-4AF6-BC36-D6EA96C8DAAE/dotNetFx40_Full_x86_x64.exe'
Install-ChocolateyPackage "NetFx4.0" 'exe' -silentArgs "/q /norestart /repair /log `'$tempDir\NetFx4Install.log`'" -url "$NetFx4FullUrl" -url64bit "$NetFx4FullUrl" -validExitCodes @(0, 3010)
$NetFx4ClientUrl = 'http://download.microsoft.com/download/5/6/2/562A10F9-C9F4-4313-A044-9C94E0A8FAC8/dotNetFx40_Client_x86_x64.exe'
$NetFx4FullUrl = 'http://download.microsoft.com/download/9/5/A/95A9616B-7A37-4AF6-BC36-D6EA96C8DAAE/dotNetFx40_Full_x86_x64.exe'
$NetFx4Url = $NetFx4FullUrl
$NetFx4Path = "$tempDir"
$NetFx4InstallerFile = 'dotNetFx40_Full_x86_x64.exe'
$NetFx4Installer = Join-Path $NetFx4Path $NetFx4InstallerFile

if(!(test-path "$env:windir\Microsoft.Net\$fx\v4.0.30319") -or $forceFxInstall) {
if (!(Test-Path $NetFx4Path)) {
Write-Host "Creating folder `'$NetFx4Path`'"
$null = New-Item -Path "$NetFx4Path" -ItemType Directory
}

$netFx4InstallTries += 1

if (!(Test-Path $NetFx4Installer)) {
Write-Host "Downloading `'$NetFx4Url`' to `'$NetFx4Installer`' - the installer is 40+ MBs, so this could take awhile on a slow connection."
(New-Object Net.WebClient).DownloadFile("$NetFx4Url","$NetFx4Installer")
}

$psi = New-Object System.Diagnostics.ProcessStartInfo
$psi.WorkingDirectory = "$NetFx4Path"
$psi.FileName = "$NetFx4InstallerFile"
# https://msdn.microsoft.com/library/ee942965(v=VS.100).aspx#command_line_options
# http://blogs.msdn.com/b/astebner/archive/2010/05/12/10011664.aspx
# For the actual setup.exe (if you want to unpack first) - /repair /x86 /x64 /ia64 /parameterfolder Client /q /norestart
$psi.Arguments = "/q /norestart /repair"

Write-Host "Installing `'$NetFx4Installer`' - this may take awhile with no output."
$s = [System.Diagnostics.Process]::Start($psi);
$s.WaitForExit();
if ($s.ExitCode -ne 0 -and $s.ExitCode -ne 3010) {
if ($netFx4InstallTries -eq 2) {
Write-Error ".NET Framework install failed with exit code `'$($s.ExitCode)`'. `n This will cause the rest of the install to fail."
throw "Error installing .NET Framework 4.0 (exit code $($s.ExitCode)). `n Please install the .NET Framework 4.0 manually and then try to install Chocolatey again. `n Download at `'$NetFx4Url`'"
} else {
Write-Warning "First try of .NET framework install failed with exit code `'$($s.ExitCode)`'. Trying again."
Install-DotNet4IfMissing $true
}
}
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/chocolatey.resources/chocolatey.resources.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@
<EmbeddedResource Include="helpers\functions\Generate-BinFile.ps1" />
<EmbeddedResource Include="helpers\functions\Remove-BinFile.ps1" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="helpers\chocolateyScriptRunner.ps1" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand All @@ -127,4 +130,4 @@
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>
10 changes: 10 additions & 0 deletions src/chocolatey.resources/helpers/chocolateyInstaller.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ if ($env:ChocolateyEnvironmentDebug -eq 'true') { $DebugPreference = "Continue";
$VerbosePreference = "SilentlyContinue"
if ($env:ChocolateyEnvironmentVerbose -eq 'true') { $VerbosePreference = "Continue"; $verbosity = $true }

$installArguments = $env:chocolateyInstallArguments

$overrideArgs = false
if ($env:chocolateyInstallOverride -eq 'true') { $overrideArgs = true }

$forceX86 = false
if ($env:chocolateyForceX86 -eq 'true') { $forceX86 = true }

$packageParameters = $env:chocolateyPackageParameters

# ensure module loading preference is on
$PSModuleAutoLoadingPreference = "All";

Expand Down
28 changes: 28 additions & 0 deletions src/chocolatey.resources/helpers/chocolateyScriptRunner.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
param(
[alias("ia","installArgs")][string] $installArguments = '',
[alias("o","override","overrideArguments","notSilent")]
[switch] $overrideArgs = $false,
[alias("x86")][switch] $forceX86 = $false,
[alias("params")][alias("parameters")][alias("pkgParams")][string]$packageParameters = '',
[string]$packageScript
)

Write-Debug "Running 'ChocolateyScriptRunner' for $($env:packageName) v$($env:packageVersion) with packageScript `'$packageScript`', packageFolder:`'$($env:packageFolder)`', installArguments: `'$installArguments`', packageParameters: `'$packageParameters`',"

## Set the culture to invariant
$currentThread = [System.Threading.Thread]::CurrentThread;
$culture = [System.Globalization.CultureInfo]::InvariantCulture;
$currentThread.CurrentCulture = $culture;
$currentThread.CurrentUICulture = $culture;

$RunNote = "DarkCyan"
$Warning = "Magenta"
$ErrorColor = "Red"
$Note = "Green"

$version = $env:packageVersion
$packageName = $env:packageName
$packageFolder = $env:packageFolder

Write-Debug "Running `'$packageScript`'";
& "$packageScript"
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@ param(
$checksumType = $checksumType64
}

try {
$fileDirectory = $([System.IO.Path]::GetDirectoryName($fileFullPath))
if (!(Test-Path($fileDirectory))) {
[System.IO.Directory]::CreateDirectory($fileDirectory) | Out-Null
}
} catch {
Write-Host "Attempt to create directory failed for '$fileFullPath'."
}

$forceX86 = $env:chocolateyForceX86;
if ($forceX86) {
Write-Debug "User specified -x86 so forcing 32 bit"
Expand Down
5 changes: 4 additions & 1 deletion src/chocolatey/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,14 @@ public static string remove_surrounding_quotes(this string input)
return input;
}

private static Regex open_brace_regex = new Regex("(?<!{){(?!{)", RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.Compiled);
private static Regex close_brace_regex = new Regex("(?<!})}(?!})", RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.Compiled);

public static string escape_curly_braces(this string input)
{
if (string.IsNullOrWhiteSpace(input)) return string.Empty;

return input.Replace("{", "{{").Replace("}", "}}");
return open_brace_regex.Replace(close_brace_regex.Replace(input,"}}"),"{{");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public void run(PackageResult packageResult, ChocolateyConfiguration config)
var uninstallExe = uninstallArgs.DefaultIfEmpty(string.Empty).FirstOrDefault();
uninstallArgs.Remove(uninstallExe);
uninstallExe = uninstallExe.remove_surrounding_quotes();
if (uninstallExe.is_equal_to("msiexec.exe")) uninstallExe = _fileSystem.combine_paths(Environment.SystemDirectory, uninstallExe);
this.Log().Debug(() => " Uninstaller path is '{0}'".format_with(uninstallExe));

//todo: ultimately we should merge keys with logging
Expand Down
34 changes: 25 additions & 9 deletions src/chocolatey/infrastructure.app/services/PowershellService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void noop_action(PackageResult packageResult, CommandNameType command)
var chocoInstall = installScript.FirstOrDefault();

this.Log().Info("Would have run '{0}':".format_with(chocoInstall));
this.Log().Warn(_fileSystem.read_file(chocoInstall));
this.Log().Warn(_fileSystem.read_file(chocoInstall).escape_curly_braces());
}
}

Expand All @@ -89,22 +89,36 @@ public bool uninstall(ChocolateyConfiguration configuration, PackageResult packa
return run_action(configuration, packageResult, CommandNameType.uninstall);
}

public string wrap_script_with_module(string script)
public string wrap_script_with_module(string script, ChocolateyConfiguration config)
{
var installerModules = _fileSystem.get_files(ApplicationParameters.InstallLocation, "chocolateyInstaller.psm1", SearchOption.AllDirectories);
var installerModule = installerModules.FirstOrDefault();
var scriptRunners = _fileSystem.get_files(ApplicationParameters.InstallLocation, "chocolateyScriptRunner.ps1", SearchOption.AllDirectories);
var scriptRunner = scriptRunners.FirstOrDefault();
// removed setting all errors to terminating. Will cause too
// many issues in existing packages, including upgrading
// Chocolatey from older POSH client due to log errors
//$ErrorActionPreference = 'Stop';
return "[System.Threading.Thread]::CurrentThread.CurrentCulture = '';[System.Threading.Thread]::CurrentThread.CurrentUICulture = ''; & import-module -name '{0}';{2} & '{1}'"
return "[System.Threading.Thread]::CurrentThread.CurrentCulture = '';[System.Threading.Thread]::CurrentThread.CurrentUICulture = ''; & import-module -name '{0}';{2} & '{1}' {3}"
.format_with(
installerModule,
script,
string.IsNullOrWhiteSpace(_customImports) ? string.Empty : "& {0}".format_with(_customImports.EndsWith(";") ? _customImports : _customImports + ";")
scriptRunner,
string.IsNullOrWhiteSpace(_customImports) ? string.Empty : "& {0}".format_with(_customImports.EndsWith(";") ? _customImports : _customImports + ";"),
get_script_arguments(script,config)
);
}

private string get_script_arguments(string script, ChocolateyConfiguration config)
{
return "-packageScript '{0}' -installArguments '{1}' -forceX86 {2} -packageParameters '{3}' -overrideArgs {4}".format_with(
script,
config.InstallArguments,
config.ForceX86 ? "$true" : "$false",
config.PackageParameters,
config.OverrideArguments ? "$true" : "$false"
);
}

public bool run_action(ChocolateyConfiguration configuration, PackageResult packageResult, CommandNameType command)
{
var installerRun = false;
Expand Down Expand Up @@ -160,8 +174,10 @@ public bool run_action(ChocolateyConfiguration configuration, PackageResult pack
Environment.SetEnvironmentVariable("packageVersion", package.Version.to_string());
Environment.SetEnvironmentVariable("chocolateyPackageFolder", packageDirectory);
Environment.SetEnvironmentVariable("packageFolder", packageDirectory);
Environment.SetEnvironmentVariable("installArguments", configuration.InstallArguments);
Environment.SetEnvironmentVariable("installerArguments", configuration.InstallArguments);
Environment.SetEnvironmentVariable("chocolateyInstallArguments", configuration.InstallArguments);
Environment.SetEnvironmentVariable("packageParameters", configuration.PackageParameters);
Environment.SetEnvironmentVariable("chocolateyPackageParameters", configuration.PackageParameters);
if (configuration.ForceX86)
{
Expand Down Expand Up @@ -194,15 +210,15 @@ public bool run_action(ChocolateyConfiguration configuration, PackageResult pack
//}

this.Log().Debug(ChocolateyLoggers.Important, "Contents of '{0}':".format_with(chocoPowerShellScript));
string chocoPowerShellScriptContents = _fileSystem.read_file(chocoPowerShellScript).escape_curly_braces();
this.Log().Debug(chocoPowerShellScriptContents);
string chocoPowerShellScriptContents = _fileSystem.read_file(chocoPowerShellScript);
this.Log().Debug(chocoPowerShellScriptContents.escape_curly_braces());

bool shouldRun = !configuration.PromptForConfirmation;

if (!shouldRun)
{
this.Log().Info(ChocolateyLoggers.Important, () => " Found '{0}':".format_with(_fileSystem.get_file_name(chocoPowerShellScript)));
this.Log().Info(() => "{0}{1}{0}".format_with(Environment.NewLine, chocoPowerShellScriptContents));
this.Log().Info(() => "{0}{1}{0}".format_with(Environment.NewLine, chocoPowerShellScriptContents.escape_curly_braces()));
var selection = InteractivePrompt
.prompt_for_confirmation(@"
Do you want to run the script?
Expand All @@ -223,7 +239,7 @@ public bool run_action(ChocolateyConfiguration configuration, PackageResult pack
{
installerRun = true;
var exitCode = PowershellExecutor.execute(
wrap_script_with_module(chocoPowerShellScript),
wrap_script_with_module(chocoPowerShellScript, configuration),
_fileSystem,
configuration.CommandExecutionTimeoutSeconds,
(s, e) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,10 @@ public void save_to_file(Registry snapshot, string filePath)

public bool value_exists(string keyPath, string value)
{
return Microsoft.Win32.Registry.GetValue(keyPath, value, null) != null;
//todo: make this check less crazy...
return get_installer_keys().RegistryKeys.Any(k => k.KeyPath == keyPath);

//return Microsoft.Win32.Registry.GetValue(keyPath, value, null) != null;
}

public Registry read_from_file(string filePath)
Expand Down
Loading

0 comments on commit ce90c21

Please sign in to comment.