-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.ps1
157 lines (142 loc) · 5.72 KB
/
install.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<#
.Synopsis
Скрипт подготовки среды сборки и тестирования проекта
.Description
Скрипт подготовки среды сборки и тестирования проекта.
Используется в том числе и для подготовки среды на серверах appveyor.
.Link
https://github.com/IT-Service/signcode
.Example
.\install.ps1 -GUI;
Устанавливаем необходимые пакеты, в том числе - и графические среды.
#>
[CmdletBinding(
SupportsShouldProcess = $true
, ConfirmImpact = 'Medium'
, HelpUri = 'https://github.com/IT-Service/signcode'
)]
param (
# Ключ, определяющий необходимость установки визуальных средств.
# По умолчанию устанавливаются только средства для командной строки.
[Switch]
$GUI
)
Function Execute-ExternalInstaller {
[CmdletBinding(
SupportsShouldProcess = $true
, ConfirmImpact = 'Medium'
)]
param (
[String]
$LiteralPath
,
[String]
$ArgumentList
)
$pinfo = [System.Diagnostics.ProcessStartInfo]::new();
$pinfo.FileName = $LiteralPath;
$pinfo.RedirectStandardError = $true;
$pinfo.RedirectStandardOutput = $true;
$pinfo.UseShellExecute = $false;
$pinfo.Arguments = $ArgumentList;
$p = [System.Diagnostics.Process]::new();
try {
$p.StartInfo = $pinfo;
$p.Start() | Out-Null;
$p.WaitForExit();
$LASTEXITCODE = $p.ExitCode;
$p.StandardOutput.ReadToEnd() `
| Write-Verbose `
;
if ( $p.ExitCode -ne 0 ) {
$p.StandardError.ReadToEnd() `
| Write-Error `
;
};
} finally {
$p.Close();
};
}
switch ( $env:PROCESSOR_ARCHITECTURE ) {
'amd64' { $ArchPath = 'x64'; }
'x86' { $ArchPath = 'x86'; }
default { Write-Error 'Unsupported processor architecture.'}
};
$ToPath = @();
Import-Module -Name PackageManagement;
$null = Install-PackageProvider -Name NuGet -Force;
$null = Import-PackageProvider -Name NuGet -Force;
$null = (
Get-PackageSource -ProviderName NuGet `
| Set-PackageSource -Trusted `
);
$null = Install-PackageProvider -Name Chocolatey -Force;
$null = Import-PackageProvider -Name Chocolatey -Force;
$null = (
Get-PackageSource -ProviderName Chocolatey `
| Set-PackageSource -Trusted `
);
if ( -not ( $env:APPVEYOR -eq 'True' ) ) {
$null = Install-Package -Name chocolatey -MinimumVersion 0.9.10.3 -ProviderName Chocolatey;
};
$null = Import-PackageProvider -Name Chocolatey -Force;
$null = (
Get-PackageSource -ProviderName Chocolatey `
| Set-PackageSource -Trusted `
);
& choco install GitVersion.Portable --confirm --failonstderr | Out-String -Stream | Write-Verbose;
& choco install GitReleaseNotes.Portable --confirm --failonstderr | Out-String -Stream | Write-Verbose;
if ( -not ( $env:APPVEYOR -eq 'True' ) ) {
& choco install git --confirm --failonstderr | Out-String -Stream | Write-Verbose;
};
& choco install checksum --confirm --failonstderr | Out-String -Stream | Write-Verbose;
& choco install cygwin --confirm --failonstderr | Out-String -Stream | Write-Verbose;
$env:CygWin = Get-ItemPropertyValue `
-Path HKLM:\SOFTWARE\Cygwin\setup `
-Name rootdir `
;
Write-Verbose "CygWin root directory: $env:CygWin";
# исправляем проблемы совместимости chocolatey, cyg-get и cygwin
If ( Test-Path "$env:CygWin\cygwinsetup.exe" ) {
$cygwinsetup = "$env:CygWin\cygwinsetup.exe";
} ElseIf ( Test-Path "$env:CygWin\setup-x86_64.exe" ) {
$cygwinsetup = "$env:CygWin\setup-x86_64.exe";
} ElseIf ( Test-Path "$env:CygWin\setup-x86.exe" ) {
$cygwinsetup = "$env:CygWin\setup-x86.exe";
} ElseIf ( Test-Path "$env:ChocolateyPath\lib\Cygwin\tools\cygwin\cygwinsetup.exe" ) {
$cygwinsetup = "$env:ChocolateyPath\lib\Cygwin\tools\cygwin\cygwinsetup.exe";
} ElseIf ( Test-Path "$env:ChocolateyPath\lib\Cygwin.$(( Get-Package -Name CygWin -ProviderName Chocolatey ).Version)\tools\cygwin\cygwinsetup.exe" ) {
$cygwinsetup = "$env:ChocolateyPath\lib\Cygwin.$(( Get-Package -Name CygWin -ProviderName Chocolatey ).Version)\tools\cygwin\cygwinsetup.exe";
} Else {
Write-Error 'I can not find CygWin setup!';
};
Write-Verbose "CygWin setup: $cygwinsetup";
if ($PSCmdLet.ShouldProcess('CygWin', 'Установить переменную окружения')) {
[System.Environment]::SetEnvironmentVariable( 'CygWin', $env:CygWin, [System.EnvironmentVariableTarget]::Machine );
};
$ToPath += "$env:CygWin\bin";
Write-Verbose 'Install CygWin tools...';
if ($PSCmdLet.ShouldProcess('make, mkdir, touch, zip', 'Установить пакет CygWin')) {
Execute-ExternalInstaller `
-LiteralPath $cygwinsetup `
-ArgumentList '--packages make,mkdir,touch,zip,ttfautohint --quiet-mode --no-desktop --no-startmenu --site http://mirrors.kernel.org/sourceware/cygwin/' `
;
};
if ( $GUI ) {
$null = Install-Package -Name SourceTree -ProviderName Chocolatey;
$null = Install-Package -Name notepadplusplus -ProviderName Chocolatey;
};
Write-Verbose 'Preparing PATH environment variable...';
if ($PSCmdLet.ShouldProcess('PATH', 'Установить переменную окружения')) {
$Path = `
( `
( $env:Path -split ';' ) `
+ $ToPath `
| Sort-Object -Unique `
) `
;
Write-Verbose 'Path variable:';
$Path | % { Write-Verbose " $_" };
$env:Path = $Path -join ';';
[System.Environment]::SetEnvironmentVariable( 'PATH', $env:Path, [System.EnvironmentVariableTarget]::User );
};