This repository has been archived by the owner on Feb 19, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 342
/
Run-ChocolateyPS1.ps1
66 lines (56 loc) · 3 KB
/
Run-ChocolateyPS1.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
function Run-ChocolateyPS1 {
param(
[string] $packageFolder,
[string] $packageName,
[string] $action,
[string] $installerArguments = ''
)
Write-Debug "Running 'Run-ChocolateyPS1' for $packageName with packageFolder:`'$packageFolder`', action: `'$action`'";
switch ($action)
{
"install" { $actionFile = "chocolateyinstall.ps1"; }
"uninstall" {$actionFile = "chocolateyuninstall.ps1"; }
default { $actionFile = "chocolateyinstall.ps1";}
}
if ($packageFolder -notlike '') {
Write-Debug " __ PowerShell $action ($actionFile) __"
Write-Debug " Looking for $actionFile in folder `'$packageFolder`'. If $actionFile is found, it will be run."
$ps1 = Get-ChildItem $packageFolder -recurse | ?{$_.name -match $actionFile} | sort name -Descending | select -First 1
$installps1 = Get-ChildItem $packageFolder -recurse | ?{$_.name -match 'chocolateyinstall.ps1'} | sort name -Descending | select -First 1
Write-Debug "Action file is `'$ps1`'"
if ($ps1 -notlike '') {
$env:chocolateyPackageFolder ="$packageFolder"
$env:chocolateyInstallArguments = "$installerArguments"
$env:chocolateyInstallOverride = $null
if ($overrideArgs -eq $true) {
$env:chocolateyInstallOverride = $true
}
$ps1FullPath = $ps1.FullName
Write-Debug "Running `'$ps1FullPath`'";
& "$ps1FullPath"
$env:chocolateyInstallArguments = ''
$env:chocolateyInstallOverride = $null
# $importChocolateyHelpers = "";
# Get-ChildItem "$nugetChocolateyPath\helpers" -Filter *.psm1 | ForEach-Object { $importChocolateyHelpers = "& import-module -name `'$($_.FullName)`';$importChocolateyHelpers" };
# Run-ChocolateyProcess powershell "-NoProfile -ExecutionPolicy unrestricted -Command `"$importChocolateyHelpers & `'$ps1FullPath`'`"" -elevated
##testing Start-Process -FilePath "powershell.exe" -ArgumentList " -noexit `"$ps1FullPath`"" -Verb "runas" -Wait #-PassThru -UseNewEnvironment ##-RedirectStandardError $errorLog -WindowStyle Normal
#detect errors
$chocTempDir = Join-Path $env:TEMP "chocolatey"
$tempDir = Join-Path $chocTempDir "$packageName"
$failureLog = Join-Path $tempDir 'failure.log'
if ([System.IO.File]::Exists($failureLog)) {
#we have issues, time to throw an error
$errorContents = Get-Content $failureLog
if ($errorContents -ne '') {
foreach ($errorLine in $errorContents) {
Write-Host $errorLine -BackgroundColor Red -ForegroundColor White
}
throw $errorContents
}
}
}
if ($installps1 -notlike '' -and $ps1 -like '') {
Write-Host "This package has a chocolateyInstall.ps1 without a chocolateyUninstall.ps1. You will need to manually reverse whatever steps the installer did. Please ask the package maker to include a chocolateyUninstall.ps1 in the file to really remove the package." -ForegroundColor $Warning -BackgroundColor Black
}
}
}