-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathinstall-windows-dev.ps1
More file actions
272 lines (242 loc) · 9.54 KB
/
install-windows-dev.ps1
File metadata and controls
272 lines (242 loc) · 9.54 KB
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
# Copyright 2022-2026 Salesforce, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
param(
[Parameter(HelpMessage = "Alias of Slack CLI")]
[string]$Alias,
[Parameter(HelpMessage = "Version of Slack CLI")]
[string]$Version = "dev",
[Parameter(HelpMessage = "Skip Git installation")]
[bool]$SkipGit = $false
)
# As this script is for internal usage only, we should set SLACK_DISABLE_TELEMETRY environment variable
[System.Environment]::SetEnvironmentVariable('SLACK_DISABLE_TELEMETRY', $true)
Function delay ([float]$seconds, [string]$message, [string]$newlineOption) {
if ($newlineOption -eq "-n") {
Write-Host -NoNewline $message
}
else {
Write-Host $message
}
Start-Sleep -Seconds $seconds
}
function check_slack_binary_exist() {
param(
[Parameter(HelpMessage = "Alias of Slack CLI")]
[string]$Alias,
[Parameter(HelpMessage = "Version of Slack CLI")]
[string]$Version,
[Parameter(HelpMessage = "Display diagnostic information")]
[boolean]$Diagnostics
)
$FINGERPRINT = "d41d8cd98f00b204e9800998ecf8427e"
$SLACK_CLI_NAME = "slack"
if ($alias) {
$SLACK_CLI_NAME = $alias
}
if (Get-Command $SLACK_CLI_NAME -ErrorAction SilentlyContinue) {
if ($Diagnostics) {
delay 0.3 "Checking if ``$SLACK_CLI_NAME`` already exists on this system..."
delay 0.2 "Heads up! A binary called ``$SLACK_CLI_NAME`` was found!"
delay 0.3 "Now checking if it's the same Slack CLI..."
}
& $SLACK_CLI_NAME _fingerprint | Tee-Object -Variable get_finger_print | Out-Null
if ($get_finger_print -ne $FINGERPRINT) {
& $SLACK_CLI_NAME --version | Tee-Object -Variable slack_cli_version | Out-Null
if (!($slack_cli_version -contains "Using ${SLACK_CLI_NAME}.exe v")) {
Write-Host "Error: Your existing ``$SLACK_CLI_NAME`` command is different from this Slack CLI!"
Write-Host "Halting the install to avoid accidentally overwriting it."
Write-Host "`nTry using an alias when installing to avoid name conflicts:"
Write-Host "`nirm https://downloads.slack-edge.com/slack-cli/install-windows.ps1 -Alias your-preferred-alias | iex"
throw
}
}
$message = "It is the same Slack CLI! Upgrading to the latest version..."
if ($Version) {
$SLACK_CLI_VERSION = $Version
$message = "It is the same Slack CLI! Switching over to v$Version..."
}
if ($Diagnostics) {
delay 0.3 "$message`n"
}
}
return $SLACK_CLI_NAME
}
function install_slack_cli {
param(
[Parameter(HelpMessage = "Alias of Slack CLI")]
[string]$Alias,
[Parameter(HelpMessage = "Version of Slack CLI")]
[string]$Version
)
delay 0.6 "Hello and welcome! Now beginning to install the..."
delay 0.1 " ________ _ _ _____ _ __ _____ _ ________"
delay 0.1 " / ______/ | / \ / ____/ | / / / ____/ | /___ __/"
delay 0.1 " /______ | | / _ \ | | / | | | | | | "
delay 0.1 " ____ / | |___ __ \ |____ |\ \ | |____ |__ _| |___"
delay 0.1 " /_______ /|______/ \_\ ____/_| \__\ _____/______/_____/"
delay 0.2 ""
$confirmed_alias = check_slack_binary_exist $Alias $Version $true
$error.clear()
try {
if ($Version) {
$SLACK_CLI_VERSION = $Version
}
else {
Write-Host "Finding the latest Slack CLI release version"
$cli_info = Invoke-RestMethod -Uri "https://docs.slack.dev/tools/metadata.json"
$SLACK_CLI_VERSION = $cli_info.'slack-cli'.releases[0].version
}
}
catch {
Write-Error "Installer cannot find latest Slack CLI release version"
throw
}
$slack_cli_dir = "${Home}\AppData\Local\slack-cli"
try {
if (!(Test-Path $slack_cli_dir)) {
try {
New-Item $slack_cli_dir -ItemType Directory | Out-Null
}
catch {
$alternative_slack_cli_dir = "${Home}\.slack-cli"
if (!(Test-Path $alternative_slack_cli_dir)) {
try {
New-Item $alternative_slack_cli_dir -ItemType Directory | Out-Null
$slack_cli_dir = $alternative_slack_cli_dir
}
catch {
Write-Error "Installer cannot create folder in $($alternative_slack_cli_dir). `nPlease manually create $($slack_cli_dir) folder and re-run the installation script"
throw
}
}
}
}
}
catch {
Write-Error "Installer cannot create folder for Slack CLI, `nPlease manually create $($slack_cli_dir) folder and re-run the installation script"
throw
}
if ($Version -eq "dev") {
Write-Host "Downloading the latest development build..."
}
else {
Write-Host "Downloading Slack CLI v$SLACK_CLI_VERSION..."
}
try {
Invoke-WebRequest -Uri "https://downloads.slack-edge.com/slack-cli/slack_cli_$($SLACK_CLI_VERSION)_windows_64-bit.zip" -OutFile "$($slack_cli_dir)\slack_cli.zip"
}
catch {
Write-Error "Installer cannot download Slack CLI"
throw
}
$slack_cli_bin_dir = "$($slack_cli_dir)\bin"
$slack_cli_binary_path = "$($slack_cli_dir)\bin\slack.exe"
$slack_cli_new_binary_path = "$($slack_cli_dir)\bin\${confirmed_alias}.exe"
delay 0.3 "Extracting the executable to:`n $slack_cli_new_binary_path"
Expand-Archive "$($slack_cli_dir)\slack_cli.zip" -DestinationPath "$($slack_cli_dir)" -Force
Move-Item -Path $slack_cli_binary_path -Destination $slack_cli_new_binary_path -Force
$User = [System.EnvironmentVariableTarget]::User
$Path = [System.Environment]::GetEnvironmentVariable('Path', $User)
if (!(";${Path};".ToLower() -like "*;${slack_cli_bin_dir};*".ToLower())) {
Write-Host "Adding ``$confirmed_alias.exe`` to your Path environment variable"
[System.Environment]::SetEnvironmentVariable('Path', $Path.TrimEnd(';') + ";${slack_cli_bin_dir}", $User)
$Env:Path = $Env:Path.TrimEnd(';') + ";$slack_cli_bin_dir"
}
Remove-Item "$($slack_cli_dir)\slack_cli.zip"
}
function install_git {
param(
[Parameter(HelpMessage = "Skip Git installation")]
[bool]$SkipGit = $false
)
if ($SkipGit) {
Write-Host "Skipping the check for a Git installation!"
}
else {
try {
Get-Command git -ErrorAction Stop | Out-Null
Write-Host "Git is already installed. Nice!"
}
catch [System.Management.Automation.CommandNotFoundException] {
Write-Host "Git is not installed. Installing now..."
$MIN_GIT_VERSION = "2.40.0"
$exePath = "$env:TEMP\git.exe"
Invoke-WebRequest -Uri https://github.com/git-for-windows/git/releases/download/v$($MIN_GIT_VERSION).windows.1/Git-$($MIN_GIT_VERSION)-64-bit.exe -UseBasicParsing -OutFile $exePath
Start-Process $exePath -ArgumentList '/VERYSILENT /NORESTART /NOCANCEL /SP- /CLOSEAPPLICATIONS /RESTARTAPPLICATIONS /COMPONENTS="icons,ext\reg\shellhere,assoc,assoc_sh"' -Wait
[Environment]::SetEnvironmentVariable('Path', "$([Environment]::GetEnvironmentVariable('Path', 'Machine'));C:\Program Files\Git\bin", 'Machine')
foreach ($level in "Machine", "User") {
[Environment]::GetEnvironmentVariables($level).GetEnumerator() | % {
if ($_.Name -match 'Path$') {
$_.Value = ($((Get-Content "Env:$($_.Name)") + ";$($_.Value)") -split ';' | Select -unique) -join ';'
}
$_
} | Set-Content -Path { "Env:$($_.Name)" }
}
Write-Host "Git is installed and ready!"
}
}
}
function terms_of_service {
param(
[Parameter(HelpMessage = "Alias of Slack CLI")]
[string]$Alias
)
$confirmed_alias = check_slack_binary_exist $Alias $Version $false
if (Get-Command $confirmed_alias) {
Write-Host "`nUse of the Slack CLI should comply with the Slack API Terms of Service:"
Write-Host " https://slack.com/terms-of-service/api"
}
}
function feedback_message {
param(
[Parameter(HelpMessage = "Alias of Slack CLI")]
[string]$Alias
)
$confirmed_alias = check_slack_binary_exist $Alias $Version $false
if (Get-Command $confirmed_alias) {
Write-Host "`nWe would love to know how things are going. Really. All of it."
Write-Host " Survey your development experience with ``$confirmed_alias feedback``"
}
}
function next_step_message {
param(
[Parameter(HelpMessage = "Alias of Slack CLI")]
[string]$Alias
)
$confirmed_alias = check_slack_binary_exist $Alias $Version $false
if (Get-Command $confirmed_alias -ErrorAction SilentlyContinue) {
try {
$confirmed_alias | Out-Null
Write-Host "`nYou're all set! Relaunch your terminal to ensure changes take effect."
Write-Host " Then, authorize your CLI in your workspace with ``$confirmed_alias login``.`n"
}
catch {
Write-Error "Slack CLI was not installed."
Write-Host "`nFind help troubleshooting: https://docs.slack.dev/tools/slack-cli"
throw
}
}
}
trap {
Write-Host "`nWe would love to know how things are going. Really. All of it."
Write-Host "Submit installation issues: https://github.com/slackapi/slack-cli/issues"
exit 1
}
install_slack_cli $Alias $Version
Write-Host "`nAdding developer tooling for an enhanced experience..."
install_git $SkipGit
Write-Host "Sweet! You're all set to start developing!"
terms_of_service $Alias
feedback_message $Alias
next_step_message $Alias