-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInstall-Winlink.ps1
More file actions
95 lines (78 loc) · 3.07 KB
/
Install-Winlink.ps1
File metadata and controls
95 lines (78 loc) · 3.07 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
<#
.SYNOPSIS
Install Winlink Express for amateur radio email
.DESCRIPTION
Downloads and installs latest Winlink Express from downloads.winlink.org with silent installation.
.EXAMPLE
.\Install-Winlink.ps1
.NOTES
Requires Administrator privileges
Logs to C:\Logs\Winlink_Install_YYYYMMDD_HHMMSS.log
.INTUNE WIN32 APP DEPLOYMENT
Install command: powershell.exe -ExecutionPolicy Bypass -NoProfile -File "Install-Winlink.ps1"
Install behavior: System context
Detection: File exists %ProgramFiles(x86)%\RMS Express\Winlink Express.exe
Return codes: 0=success, 1=failure
#>
# Requires -RunAsAdministrator
# Logging setup
$LogDir = "C:\Logs"
if (-not (Test-Path $LogDir)) {
New-Item -Path $LogDir -ItemType Directory -Force | Out-Null
}
$Timestamp = Get-Date -Format "yyyyMMdd_HHmmss"
$LogFile = "$LogDir\Winlink_Install_$Timestamp.log"
function Write-Log {
param(
[string]$Message,
[ValidateSet('INFO','WARNING','ERROR')]
[string]$Level = 'INFO'
)
$LogMessage = "{0} [{1}] {2}" -f (Get-Date -Format "yyyy-MM-dd HH:mm:ss"), $Level, $Message
Add-Content -Path $LogFile -Value $LogMessage
switch ($Level) {
'ERROR' { Write-Host $Message -ForegroundColor Red }
'WARNING' { Write-Host $Message -ForegroundColor Yellow }
default { Write-Host $Message }
}
}
Write-Log "Starting Winlink Express installation"
# Check if already installed
$WinlinkExe = "${env:ProgramFiles(x86)}\RMS Express\Winlink Express.exe"
if (Test-Path $WinlinkExe) {
$version = (Get-Item $WinlinkExe).VersionInfo.FileVersion
Write-Log "Winlink Express already installed (version: $version)" -Level WARNING
Write-Log "To reinstall, uninstall first or delete: $WinlinkExe"
exit 0
}
$DownloadPage = "https://downloads.winlink.org/User%20Programs/"
$TempPath = "$env:TEMP\WinlinkInstaller.exe"
try {
Write-Log "Fetching download page: $DownloadPage"
$html = Invoke-WebRequest -Uri $DownloadPage -UseBasicParsing -ErrorAction Stop
$link = ($html.Links | Where-Object { $_.href -match "Winlink_Express_install.*\.exe" } | Select-Object -First 1).href
if (-not $link) {
Write-Log "No installer link found on download page" -Level ERROR
exit 1
}
if ($link -notmatch "^https?://") {
$link = [System.Uri]::new($DownloadPage, $link).AbsoluteUri
}
Write-Log "Downloading Winlink Express from $link"
Invoke-WebRequest -Uri $link -OutFile $TempPath -ErrorAction Stop
Write-Log "Download completed: $TempPath"
Write-Log "Starting silent installation"
$Process = Start-Process -FilePath $TempPath -ArgumentList "/S" -Wait -PassThru -ErrorAction Stop
if ($Process.ExitCode -eq 0) {
Write-Log "Winlink Express installed successfully"
Remove-Item -Path $TempPath -Force -ErrorAction SilentlyContinue
exit 0
} else {
Write-Log "Installation failed with exit code: $($Process.ExitCode)" -Level ERROR
exit 1
}
}
catch {
Write-Log "Failed to download or install Winlink Express: $_" -Level ERROR
exit 1
}