-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstallBase.ps1
More file actions
153 lines (134 loc) · 5.63 KB
/
installBase.ps1
File metadata and controls
153 lines (134 loc) · 5.63 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
# Script version | Based on original weget installer (see: https://github.com/KRWCLASSIC/weget/blob/2407bb9dca90645af8df5dbe99ac1ca621a68d61/install/install_weget.ps1)
# Below variables are handled by external script that scrapes versions and edits these variables.
$scriptVersion = "v2.1"
$APP_DISPLAYNAME = ""
$APP_NAME = ""
$APP_OWNER = ""
$APP_VERSION = ""
$APP_BINARY = ""
$APP_FOLDER = ""
$APP_AUTORUN = $false
$APP_AUTORUN_PREFIX = ""
$APP_AUTORUN_ARGS = ""
$APP_POST_INSTALL_MESSAGE = ""
Write-Host "$APP_DISPLAYNAME ($APP_VERSION) | IronShell installer $scriptVersion" -ForegroundColor Cyan
# Define installation path (user only)
$installPath = Join-Path $env:APPDATA "$APP_OWNER\$APP_FOLDER"
$binaryPath = Join-Path $installPath "$APP_BINARY"
# ISver file path
$isverPath = Join-Path $installPath "ISver.txt"
# Check if already installed in user path
$existingPaths = @($installPath) | Where-Object { Test-Path (Join-Path $_ "$APP_BINARY") }
if ($existingPaths) {
Write-Host "$APP_DISPLAYNAME is already installed at: $($existingPaths -join ', ')" -ForegroundColor Yellow
$installPath = $existingPaths
$alreadyInstalled = $true
} else {
$alreadyInstalled = $false
}
# Ensure install directory exists before download and ISver.txt write
if (!(Test-Path $installPath)) {
Write-Host "Creating installation directory: $installPath" -ForegroundColor Green
New-Item -ItemType Directory -Path $installPath -Force | Out-Null
}
# ISver version check
$skipInstall = $false
if (Test-Path $isverPath) {
$installedVersion = (Get-Content $isverPath -Raw).Trim()
$targetVersion = $APP_VERSION.Trim()
if ($installedVersion -eq $targetVersion) {
Write-Host "Existing installation is up to date ($installedVersion)." -ForegroundColor Green
$skipInstall = $true
} else {
Write-Host "Installed version ($installedVersion) differs from requested ($targetVersion). Updating..." -ForegroundColor Yellow
}
} else {
if ($alreadyInstalled) {
Write-Host "No ISver.txt found. Will perform fresh installation of $APP_DISPLAYNAME ($APP_VERSION)." -ForegroundColor Yellow
}
}
if ($skipInstall) {
if ($APP_POST_INSTALL_MESSAGE -ne "") {
Write-Host $APP_POST_INSTALL_MESSAGE -ForegroundColor Magenta
}
if ($APP_AUTORUN -eq $true) {
Write-Host "Press any key to continue... (autorun enabled)"
} else {
Write-Host "Press any key to continue..."
}
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
if ($APP_AUTORUN -eq $true) {
Write-Host "Autorun enabled. Running: "$APP_AUTORUN_PREFIX `"$binaryPath`" $APP_AUTORUN_ARGS"" -ForegroundColor Cyan
if ($APP_AUTORUN_PREFIX -ne "") {
Start-Process powershell -ArgumentList "-NoExit", "-Command", "$APP_AUTORUN_PREFIX `"$binaryPath`" $APP_AUTORUN_ARGS"
} else {
if ($APP_AUTORUN_ARGS -ne "") {
& $binaryPath $APP_AUTORUN_ARGS.Split(" ")
} else {
& $binaryPath
}
}
}
return
}
# Always download and install the binary if not skipping
$binaryUrl = "https://github.com/$APP_OWNER/$APP_NAME/releases/download/$APP_VERSION/$APP_BINARY"
Write-Host "Downloading $APP_DISPLAYNAME ($APP_VERSION) to: $binaryPath" -ForegroundColor Cyan
try {
Invoke-WebRequest -Uri $binaryUrl -OutFile $binaryPath -ErrorAction Stop
} catch {
if ($_.Exception.Response.StatusCode.value__ -eq 500) {
Write-Host "GitHub returned 500. GitHub seems to be down." -ForegroundColor Red
} else {
Write-Host ("Failed to download " + $APP_DISPLAYNAME + ": " + $_) -ForegroundColor Red
}
Write-Host "Press any key to continue..."
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
return
}
# After download, check if binary exists
if (!(Test-Path $binaryPath)) {
Write-Host "Download failed: $binaryPath does not exist." -ForegroundColor Red
Write-Host "Press any key to continue..."
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
return
}
# Add to user PATH
$userEnvPath = [System.Environment]::GetEnvironmentVariable("Path", "User")
if ($userEnvPath -notlike "*$installPath*") {
Write-Host "Adding to user PATH" -ForegroundColor Green
[System.Environment]::SetEnvironmentVariable("Path", "$userEnvPath;$installPath", "User")
} else {
Write-Host "Already in user PATH" -ForegroundColor Yellow
}
# Refresh PATH in current session
$env:Path = [System.Environment]::GetEnvironmentVariable("Path", "User")
# After successful install, write ISver.txt
Set-Content -Path $isverPath -Value $APP_VERSION.Trim()
# Only autorun and print success if binary exists
if (Test-Path $binaryPath) {
Write-Host "Installation complete! $APP_DISPLAYNAME ($APP_VERSION) is ready to use." -ForegroundColor Green
} else {
Write-Host "Binary not found for autorun or completion message. Something went wrong." -ForegroundColor Red
}
if ($APP_POST_INSTALL_MESSAGE -ne "") {
Write-Host $APP_POST_INSTALL_MESSAGE -ForegroundColor Magenta
}
if ($APP_AUTORUN -eq $true) {
Write-Host "Press any key to continue... (autorun enabled)"
} else {
Write-Host "Press any key to continue..."
}
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
if ($APP_AUTORUN -eq $true) {
Write-Host "Autorun enabled. Running: "$APP_AUTORUN_PREFIX `"$binaryPath`" $APP_AUTORUN_ARGS"" -ForegroundColor Cyan
if ($APP_AUTORUN_PREFIX -ne "") {
Start-Process powershell -ArgumentList "-NoExit", "-Command", "$APP_AUTORUN_PREFIX `"$binaryPath`" $APP_AUTORUN_ARGS"
} else {
if ($APP_AUTORUN_ARGS -ne "") {
& $binaryPath $APP_AUTORUN_ARGS.Split(" ")
} else {
& $binaryPath
}
}
}