-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInstall-CHIRP.ps1
More file actions
200 lines (166 loc) · 6.17 KB
/
Install-CHIRP.ps1
File metadata and controls
200 lines (166 loc) · 6.17 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
<#
.SYNOPSIS
Install CHIRP Next for radio programming
.DESCRIPTION
Downloads and installs latest CHIRP Next from trac.chirp.danplanet.com.
CHIRP is updated frequently, so this script always fetches the latest version.
.PARAMETER ConfigFile
Optional JSON configuration file for driver preferences
.EXAMPLE
.\Install-CHIRP.ps1
Install latest CHIRP Next
.EXAMPLE
.\Install-CHIRP.ps1 -ConfigFile "EmComm-Config.json"
Install with pre-configured driver preferences
.NOTES
Requires Administrator privileges
Logs to C:\Logs\CHIRP_Install_YYYYMMDD_HHMMSS.log
CHIRP Next is the current/modern version
.INTUNE WIN32 APP DEPLOYMENT
Install command: powershell.exe -ExecutionPolicy Bypass -NoProfile -File "Install-CHIRP.ps1"
Install behavior: System context
Detection: File exists %ProgramFiles%\CHIRP\chirp.exe OR %LOCALAPPDATA%\Programs\CHIRP\chirp.exe
Return codes: 0=success, 1=failure
#>
# Requires -RunAsAdministrator
param(
[string]$ConfigFile
)
# 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\CHIRP_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 CHIRP installation"
# Check if already installed (CHIRP can be in multiple locations)
$CHIRPPaths = @(
"$env:LOCALAPPDATA\Programs\CHIRP\chirp.exe",
"$env:ProgramFiles\CHIRP\chirp.exe",
"${env:ProgramFiles(x86)}\CHIRP\chirp.exe"
)
foreach ($path in $CHIRPPaths) {
if (Test-Path $path) {
$version = (Get-Item $path).VersionInfo.FileVersion
Write-Log "CHIRP already installed at: $path (version: $version)" -Level WARNING
Write-Log "To reinstall, uninstall first via Windows Settings"
exit 0
}
}
# CHIRP download page - always fetch latest
$DownloadPage = "https://trac.chirp.danplanet.com/chirp_next/next-win64"
$TempDir = "$env:TEMP\CHIRP"
if (-not (Test-Path $TempDir)) {
New-Item -Path $TempDir -ItemType Directory -Force | Out-Null
}
# Load configuration if provided
$Config = $null
if ($ConfigFile -and (Test-Path $ConfigFile)) {
Write-Log "Loading configuration from $ConfigFile"
try {
$Config = Get-Content $ConfigFile -Raw | ConvertFrom-Json
Write-Log "Configuration loaded successfully"
}
catch {
Write-Log "Failed to load configuration: $_" -Level WARNING
}
}
try {
Write-Log "Fetching latest CHIRP Next installer"
$html = Invoke-WebRequest -Uri $DownloadPage -UseBasicParsing -ErrorAction Stop
# Find latest installer link (usually chirp-next-YYYYMMDD-installer.exe)
$link = ($html.Links | Where-Object {
$_.href -match "chirp.*-installer\.exe$"
} | Sort-Object href -Descending | Select-Object -First 1).href
if (-not $link) {
Write-Log "No CHIRP installer found on download page" -Level ERROR
exit 1
}
if ($link -notmatch "^https?://") {
$BaseUrl = "https://trac.chirp.danplanet.com"
$link = "$BaseUrl$link"
}
# Extract version from filename for logging
if ($link -match "chirp.*-(\d{8})-installer\.exe") {
$Version = $Matches[1]
Write-Log "Latest CHIRP version: $Version"
}
Write-Log "Downloading CHIRP from $link"
$InstallerPath = "$TempDir\CHIRP-installer.exe"
Invoke-WebRequest -Uri $link -OutFile $InstallerPath -ErrorAction Stop
Write-Log "Download completed: $InstallerPath"
Write-Log "Installing CHIRP"
$Process = Start-Process -FilePath $InstallerPath -ArgumentList "/S" -Wait -PassThru -ErrorAction Stop
if ($Process.ExitCode -eq 0) {
Write-Log "CHIRP installed successfully"
} else {
Write-Log "CHIRP installation returned exit code: $($Process.ExitCode)" -Level WARNING
}
}
catch {
Write-Log "Failed to install CHIRP: $_" -Level ERROR
exit 1
}
# Pre-configure driver preferences if config provided
if ($Config) {
Write-Log "Configuring CHIRP settings"
# CHIRP stores config in %APPDATA%\CHIRP
$ChirpConfigDir = "$env:APPDATA\CHIRP"
if (-not (Test-Path $ChirpConfigDir)) {
New-Item -Path $ChirpConfigDir -ItemType Directory -Force | Out-Null
}
# Create prefs.conf with driver settings
$PrefsContent = @"
# CHIRP configuration generated by Install-CHIRP.ps1
# $(Get-Date -Format "yyyy-MM-dd HH:mm:ss")
[chirp]
developer=false
auto_edits=true
clone_prompt=false
[drivers]
# Windows driver preferences
use_zadig_driver=true
"@
$PrefsPath = "$ChirpConfigDir\prefs.conf"
Set-Content -Path $PrefsPath -Value $PrefsContent -Force
Write-Log "Configuration created at $PrefsPath"
}
# Create desktop shortcut
try {
$ChirpExe = Get-ChildItem -Path "$env:ProgramFiles\CHIRP" -Filter "chirp.exe" -Recurse -ErrorAction SilentlyContinue | Select-Object -First 1
if (-not $ChirpExe) {
$ChirpExe = Get-ChildItem -Path "$env:LOCALAPPDATA\Programs\CHIRP" -Filter "chirp.exe" -Recurse -ErrorAction SilentlyContinue | Select-Object -First 1
}
if ($ChirpExe) {
$WshShell = New-Object -ComObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut("$env:Public\Desktop\CHIRP.lnk")
$Shortcut.TargetPath = $ChirpExe.FullName
$Shortcut.WorkingDirectory = $ChirpExe.DirectoryName
$Shortcut.Save()
Write-Log "Desktop shortcut created"
}
}
catch {
Write-Log "Failed to create desktop shortcut: $_" -Level WARNING
}
# Cleanup
Write-Log "Cleaning up temporary files"
Remove-Item -Path $TempDir -Recurse -Force -ErrorAction SilentlyContinue
Write-Log "CHIRP installation completed successfully"
Write-Log "CHIRP updates frequently - rerun this script to get latest version" -Level INFO
exit 0