-
Notifications
You must be signed in to change notification settings - Fork 3
/
choco-install.ps1
63 lines (58 loc) · 2.23 KB
/
choco-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
<#
Installs the choco.packages ignoring any comments
marked with a # at the start of the line.
#>
param(
[string]
$filename = "choco-base.packages",
[switch] $configure
)
# src: https://stackoverflow.com/a/2688572
function Write-Color([String[]]$Text, [ConsoleColor[]]$Color) {
for ($i = 0; $i -lt $Text.Length; $i++) {
Write-Host $Text[$i] -Foreground $Color[$i] -NoNewLine
}
Write-Host
}
Write-Color "Checking for Elevated permissions..." -Color DarkCyan
if (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator"))
{
Write-Color "WARNING: Please run script with elevated permissions." -Color Red
Write-Color "See how: ","https://www.thushanfernando.com/posts/2020/windows-terminal-setup/#elevate-powershell-easily" -Color Magenta,Green
Break
}
else
{
Write-Color "Script running under elevated permissions..." -Color Green
}
Write-Color "Checking Choco installed..." -Color DarkCyan
if (-Not (Test-Path $env:ChocolateyInstall\bin\choco.exe)) {
Write-Color "Installing Choco..." -Color Red
Invoke-Expression (New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1')
} else {
Write-Color "Choco installed already!" -Color Green
}
if ($configure.IsPresent)
{
Write-Color "Completed Configuring Choco ", "successfully!" -Color DarkCyan,Green
Exit(0)
}
# Iterates through the file and install or upgrade the silently.
$install_totald = 0
$install_succes = 0
$install_failed = 0
(Get-Content $filename) -notmatch '^#' -match "\S" `
| ForEach-Object {
Write-Color -Text "Installing ", $_, '...' -Color DarkCyan,Magenta,DarkCyan
$install_totald++
choco upgrade -y $_
if( $? ){
Write-Color -Text "Installing ", $_, "...", "Success :)" -Color DarkCyan,Magenta,DarkCyan,Green
$install_succes++
}
if( !$? ){
Write-Color -Text "Installing ", $_, "...", "Failed :(" -Color DarkCyan,Magenta,DarkCyan,Red
$install_failed++
}
}
Write-Color "Completed installing (", $install_totald , ") packages with (", $install_succes, ") succesful, (", $install_failed, ") failures." -Color DarkCyan,Magenta,DarkCyan,Green,DarkCyan,Red,DarkCyan