-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathinstall_ipm.ps1
More file actions
103 lines (88 loc) · 3.52 KB
/
install_ipm.ps1
File metadata and controls
103 lines (88 loc) · 3.52 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
# ipm-install.ps1
$ErrorActionPreference = "Stop"
$APPNAME = "ipm"
# Global installation dir for Windows (matching your Bash script logic)
$INSTALL_DIR = "$env:USERPROFILE\.local\bin"
# Detect ARCH (Normalize to amd64/arm64)
$RAW_ARCH = $env:PROCESSOR_ARCHITECTURE
$ARCH = "amd64"
if ($RAW_ARCH -eq "ARM64") { $ARCH = "arm64" }
# Since this is the .ps1 version, OS is explicitly windows
$OS = "windows"
$EXT = ".exe"
$TARGET = "$INSTALL_DIR\$APPNAME$EXT"
$DOWNLOAD_URL = "https://github.com/HexmosTech/Installerpedia/releases/latest/download/ipm-$OS-$ARCH$EXT"
###################################
# Ensure install dir exists
###################################
if (!(Test-Path -Path $INSTALL_DIR)) {
New-Item -ItemType Directory -Path $INSTALL_DIR -Force | Out-Null
}
function ipm { & "$TARGET" @args }
function Update-IpmPath {
$UserPath = [Environment]::GetEnvironmentVariable("Path", "User")
if ($UserPath -notlike "*$INSTALL_DIR*") {
Write-Host "==> Adding $INSTALL_DIR to user PATH..."
[Environment]::SetEnvironmentVariable("Path", "$UserPath;$INSTALL_DIR", "User")
$env:Path += ";$INSTALL_DIR"
}
}
###################################
# Check existing binary
###################################
if (Test-Path -Path $TARGET) {
Update-IpmPath # Ensure PATH is fixed even if already installed
Write-Host "==> $APPNAME already exists at $TARGET"
return
}
# Generate Install ID (date + random)
$INSTALL_ID = "install-$([DateTimeOffset]::Now.ToUnixTimeSeconds())-$(Get-Random -Minimum 1000 -Maximum 9999)"
###################################
# Track installation start (Background)
###################################
$StartPayload = @{
api_key = "phc_bC7cMka8DieEik61bxec1xAg3hANE8oNNGoelwXoE9I"
event = "ipm_install_started"
distinct_id = $INSTALL_ID
properties = @{
os = $OS
arch = $ARCH
method = "curl"
}
} | ConvertTo-Json -Compress
# Using Start-Job because it is built into all Windows versions
Start-Job -ScriptBlock {
param($Payload)
Invoke-RestMethod -Uri "https://us.i.posthog.com/i/v0/e/" -Method Post -Body $Payload -ContentType "application/json"
} -ArgumentList $StartPayload | Out-Null
###################################
# Download binary
###################################
Write-Host "==> Installing $APPNAME ($OS-$ARCH) to $INSTALL_DIR ..."
Write-Host "==> Downloading from $DOWNLOAD_URL ..."
try {
# Ensure TLS 1.2 for GitHub downloads
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Invoke-WebRequest -Uri $DOWNLOAD_URL -OutFile $TARGET -UseBasicParsing
} catch {
Write-Host "==> Download failed: $($_.Exception.Message)"
exit 1
}
###################################
# Track installation success (Background)
###################################
$SuccessPayload = $StartPayload -replace "ipm_install_started", "ipm_install_succeeded"
Start-Job -ScriptBlock {
param($Payload)
Invoke-RestMethod -Uri "https://us.i.posthog.com/i/v0/e/" -Method Post -Body $Payload -ContentType "application/json"
} -ArgumentList $SuccessPayload | Out-Null
# Update PATH for future sessions
$UserPath = [Environment]::GetEnvironmentVariable("Path", "User")
if ($UserPath -notlike "*$INSTALL_DIR*") {
Write-Host "==> Adding $INSTALL_DIR to user PATH..."
[Environment]::SetEnvironmentVariable("Path", "$UserPath;$INSTALL_DIR", "User")
# Update current session's PATH as well
$env:Path += ";$INSTALL_DIR"
}
Update-IpmPath
Write-Host "==> Installation complete! You can now run '$APPNAME'."