/
chocolateyinstall.ps1
159 lines (131 loc) · 5 KB
/
chocolateyinstall.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
158
159
$ErrorActionPreference = 'Continue'
Import-Module Boxstarter.Chocolatey
Import-Module "$($Boxstarter.BaseDir)\Boxstarter.Common\boxstarter.common.psd1"
$packageName = 'flarevm.installer.flare'
$toolsDir = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)"
$flareFeed = "https://www.myget.org/F/flare/api/v2"
$cache = "${Env:UserProfile}\AppData\Local\ChocoCache"
$globalCinstArgs = "--cacheLocation $cache -y"
$startPath = Join-Path ${Env:ProgramData} "Microsoft\Windows\Start Menu\Programs\FLARE"
$pkgPath = Join-Path $toolsDir "packages.json"
# Set desktop background to black
Set-ItemProperty -Path 'HKCU:\Control Panel\Colors' -Name Background -Value "0 0 0" -Force | Out-Null
# https://stackoverflow.com/questions/28077854/powershell-2-0-convertfrom-json-and-convertto-json-implementation
function ConvertFrom-Json([object] $item) {
Add-Type -Assembly system.web.extensions
$ps_js = New-Object system.web.script.serialization.javascriptSerializer
#The comma operator is the array construction operator in PowerShell
return ,$ps_js.DeserializeObject($item)
}
function LoadPackages {
try {
$json = Get-Content $pkgPath -ErrorAction Stop
$packages = ConvertFrom-Json $json
} catch {
return $null
}
return $packages
}
function InstallOnePackage {
param([hashtable] $pkg)
$name = $pkg.name
$pkgargs = $pkg.args
try {
$is64Only = $pkg.x64Only
} catch {
$is64Only = $false
}
if ($is64Only) {
if (Get-OSArchitectureWidth -Compare 64) {
# pass
} else {
Write-Warning "[!] Not installing $name on x86 systems"
return $true
}
}
if ($pkgargs -eq $null) {
$args = $globalCinstArgs
} else {
$args = $pkgargs,$globalCinstArgs -Join " "
}
if ($args -like "*-source*" -Or $args -like "*--package-parameters*") {
Write-Warning "[!] Installing using host choco.exe! Errors are ignored. Please check to confirm $name is installed properly"
Write-Warning "[!] Executing: iex choco upgrade $name $args"
$rc = iex "choco upgrade $name $args"
Write-Host $rc
} else {
choco upgrade $name $args
}
if ($([System.Environment]::ExitCode) -ne 0 -And $([System.Environment]::ExitCode) -ne 3010) {
Write-Host "ExitCode: $([System.Environment]::ExitCode)"
return $false
}
return $true
}
function InitialSetup {
# Basic system setup
Update-ExecutionPolicy Unrestricted
Set-WindowsExplorerOptions -EnableShowProtectedOSFiles -EnableShowFileExtensions -EnableShowHiddenFilesFoldersDrives
Set-TaskbarOptions -Size Small
Disable-MicrosoftUpdate
Disable-BingSearch
Disable-GameBarTips
Disable-ComputerRestore -Drive ${Env:SystemDrive}
# Chocolatey setup
Write-Host "Initializing chocolatey"
iex "choco sources add -n=flare -s $flareFeed --priority 1"
iex "choco feature enable -n allowGlobalConfirmation"
iex "choco feature enable -n allowEmptyChecksums"
# Create the cache directory
New-Item -Path $cache -ItemType directory -Force
# Create FLARE desktop shortcut
if (-Not (Test-Path -Path $startPath) ) {
New-Item -Path $startPath -ItemType directory
}
$desktopShortcut = Join-Path ${Env:UserProfile} "Desktop\FLARE.lnk"
Install-ChocolateyShortcut -shortcutFilePath $desktopShortcut -targetPath $startPath
# Set common paths in environment variables
Install-ChocolateyEnvironmentVariable -VariableName "TOOL_LIST_DIR" -VariableValue $startPath -VariableType 'Machine'
refreshenv
# BoxStarter setup
Set-BoxstarterConfig -NugetSources "$flareFeed;https://chocolatey.org/api/v2"
# Tweak power options to prevent installs from timing out
& powercfg -change -monitor-timeout-ac 0 | Out-Null
& powercfg -change -monitor-timeout-dc 0 | Out-Null
& powercfg -change -disk-timeout-ac 0 | Out-Null
& powercfg -change -disk-timeout-dc 0 | Out-Null
& powercfg -change -standby-timeout-ac 0 | Out-Null
& powercfg -change -standby-timeout-dc 0 | Out-Null
& powercfg -change -hibernate-timeout-ac 0 | Out-Null
& powercfg -change -hibernate-timeout-dc 0 | Out-Null
}
function CleanUp {
# clean up the cache directory
Remove-Item $cache -Recurse
# Final flarevm installation
iex "choco upgrade flarevm.config.flare $globalCinstArgs"
}
function Main {
InitialSetup
$json = LoadPackages $pkgPath
if ($json -eq $null -Or $json.packages -eq $null) {
Write-Host "Packages property not found! Exiting"
return -1
}
$packages = $json.packages
foreach ($pkg in $packages) {
$name = $pkg.name
$rc = InstallOnePackage $pkg
if ($rc) {
# Try not to get rate-limited
if (-Not ($name.Contains(".flare"))) {
Start-Sleep -Seconds 5
}
} else {
Write-Host "Failed to install $name"
}
}
CleanUp
return 0
}
Main