-
Notifications
You must be signed in to change notification settings - Fork 93
Expand file tree
/
Copy pathdeepstudio-install.ps1
More file actions
63 lines (51 loc) · 1.91 KB
/
Copy pathdeepstudio-install.ps1
File metadata and controls
63 lines (51 loc) · 1.91 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
# ===============================
# DeepStudio bootstrap installer
# ===============================
$ErrorActionPreference = "Stop"
$PackageName = if ($env:DEEPSTUDIO_PKG) { $env:DEEPSTUDIO_PKG } else { "deepstudio-server" }
$Registry = if ($env:DEEPSTUDIO_REGISTRY) { $env:DEEPSTUDIO_REGISTRY } else { "https://microsoft.pkgs.visualstudio.com/OS/_packaging/DeepStudio/npm/registry/" }
$AuthPrefix = "//microsoft.pkgs.visualstudio.com/OS/_packaging/DeepStudio/npm/registry/"
function Require-Npm {
if (-not (Get-Command npm -ErrorAction SilentlyContinue)) {
Write-Host ""
Write-Host "❌ Node.js / npm not found."
Write-Host ""
Write-Host "Please install Node.js first:"
Write-Host "https://nodejs.org/en/download"
Write-Host ""
exit 1
}
}
function Read-PatSecure {
$secure = Read-Host "Enter Azure DevOps PAT (Packaging:Read)" -AsSecureString
$bstr = [Runtime.InteropServices.Marshal]::SecureStringToBSTR($secure)
try {
return [Runtime.InteropServices.Marshal]::PtrToStringBSTR($bstr)
}
finally {
[Runtime.InteropServices.Marshal]::ZeroFreeBSTR($bstr)
}
}
function SetCfg($k, $v) { npm config set --global $k $v | Out-Null }
function DelCfg($k) { try { npm config delete --global $k | Out-Null } catch {} }
Require-Npm
$pat = Read-PatSecure
if ([string]::IsNullOrWhiteSpace($pat)) { throw "PAT is empty." }
$patB64 = [Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes($pat))
$pat = $null
try {
Write-Host "Installing $PackageName@latest ..."
SetCfg "registry" $Registry
SetCfg "${AuthPrefix}:username" "microsoft"
SetCfg "${AuthPrefix}:_password" $patB64
SetCfg "${AuthPrefix}:email" "npm@example.com"
npm install -g "$PackageName@latest" --registry $Registry
Write-Host ""
Write-Host "✅ DeepStudio installed or upgraded successfully."
}
finally {
DelCfg "registry"
DelCfg "${AuthPrefix}:username"
DelCfg "${AuthPrefix}:_password"
DelCfg "${AuthPrefix}:email"
}