-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.ps1
More file actions
88 lines (72 loc) · 3.01 KB
/
install.ps1
File metadata and controls
88 lines (72 loc) · 3.01 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
Write-Host "Installing godspeed-daemon..."
# Check if running with administrator privileges
$runAsAdmin = [Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()
$adminRole = [Security.Principal.WindowsBuiltInRole]::Administrator
if (-not $runAsAdmin.IsInRole($adminRole)) {
Write-Host "This script must be run as Administrator. Please right-click and 'Run as Administrator'." -ForegroundColor Red
exit
}
# Define the GitHub release URL
$executableUrl = "https://github.com/zero8dotdev/install-godspeed-daemon/releases/download/v1.1.2/godspeed-daemon-win.exe"
# Define the target installation directory
$targetDir = "$env:USERPROFILE\AppData\Local\Programs\godspeed"
# Create the directory if it doesn't exist
if (-not (Test-Path -Path $targetDir)) {
New-Item -ItemType Directory -Path $targetDir | Out-Null
}
# Define the destination path
$destinationPath = "$targetDir\godspeed-daemon.exe"
Write-Host "Downloading godspeed-daemon..."
try {
Invoke-WebRequest -Uri $executableUrl -OutFile $destinationPath -ErrorAction Stop
}
catch {
Write-Host "Download failed: $_" -ForegroundColor Red
exit
}
# Verify if the download was successful
if (Test-Path -Path $destinationPath) {
Write-Host "File downloaded successfully!"
} else {
Write-Host "Download failed. Exiting script." -ForegroundColor Red
exit
}
# Add the target directory to the PATH for persistence
$persistentPath = [Environment]::GetEnvironmentVariable('Path', 'User')
if (-not $persistentPath.Contains($targetDir)) {
[Environment]::SetEnvironmentVariable('Path', "$persistentPath;$targetDir", 'User')
}
# Add it to the current session as well (to take effect immediately)
$env:Path += ";$targetDir"
# Verify if the installation was successful
if (Test-Path -Path $destinationPath) {
Write-Host "Installation complete! You can now run '$destinationPath'." -ForegroundColor Green
} else {
Write-Host "Installation failed." -ForegroundColor Red
exit
}
# Create .godspeed directory and services.json if they don't exist
Write-Host "`nSetting up configuration files..." -ForegroundColor Cyan
$godspeedDir = Join-Path -Path $env:USERPROFILE -ChildPath ".godspeed"
$servicesJson = Join-Path -Path $godspeedDir -ChildPath "services.json"
# Create .godspeed directory
if (-not (Test-Path -Path $godspeedDir)) {
Write-Host "Creating configuration directory: $godspeedDir"
New-Item -ItemType Directory -Path $godspeedDir | Out-Null
}
else {
Write-Host "Configuration directory already exists: $godspeedDir"
}
# Create services.json file with '{ "services": [] }' if it doesn't exist (UTF-8 without BOM)
if (-not (Test-Path -Path $servicesJson)) {
Write-Host "Creating configuration file: $servicesJson"
$content = '{ "services": [] }'
[System.IO.File]::WriteAllText(
$servicesJson,
$content,
[System.Text.UTF8Encoding]::new($false)
)
} else {
Write-Host "Configuration file already exists: $servicesJson"
}
Write-Host "Configuration setup complete!`n" -ForegroundColor Cyan