72 lines
2.1 KiB
PowerShell
72 lines
2.1 KiB
PowerShell
param()
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
$portStart = $env:QORTAL_PORT_START
|
|
if ([string]::IsNullOrWhiteSpace($portStart)) {
|
|
$portStart = 23391
|
|
}
|
|
if (-not ($portStart -match '^\d+$')) {
|
|
Write-Error "Invalid port start '$portStart'."
|
|
exit 1
|
|
}
|
|
|
|
$portStart = [int]$portStart
|
|
$apiPort = $portStart
|
|
$listenPort = $portStart + 1
|
|
$devProxyPort = $portStart + 2
|
|
$listenDataPort = $portStart + 3
|
|
$setPorts = $portStart -ne 23391
|
|
|
|
$settingsPath = "settings.json"
|
|
if (-not (Test-Path $settingsPath)) {
|
|
Write-Host "settings.json not found. Downloading default settings.json..."
|
|
$url = "https://cloud.qortal.org/s/QortalDevNetDefaultSettingsFile/download/default-settings.json"
|
|
Invoke-WebRequest -Uri $url -OutFile $settingsPath
|
|
Write-Host "Downloaded default settings.json"
|
|
}
|
|
|
|
function Get-PublicIp {
|
|
$urls = @(
|
|
"https://api.ipify.org",
|
|
"https://ipv4.icanhazip.com",
|
|
"https://checkip.amazonaws.com",
|
|
"https://ifconfig.me",
|
|
"https://canhazip.com"
|
|
)
|
|
foreach ($url in $urls) {
|
|
try {
|
|
$ip = (Invoke-WebRequest -Uri $url -TimeoutSec 8 -Headers @{ "User-Agent" = "Mozilla/5.0" }).Content.Trim()
|
|
if ($ip -match '^\d{1,3}(\.\d{1,3}){3}$') {
|
|
return $ip
|
|
}
|
|
} catch {
|
|
continue
|
|
}
|
|
}
|
|
return $null
|
|
}
|
|
|
|
$publicIp = Get-PublicIp
|
|
if (-not $publicIp) {
|
|
Write-Warning "Could not obtain a valid public IPv4 address; please manually set 'ourExternalIpAddress' (find it at https://www.whatismyipaddress.com)."
|
|
exit 0
|
|
}
|
|
|
|
$json = Get-Content -Raw -Path $settingsPath | ConvertFrom-Json
|
|
$json.ourExternalIpAddress = $publicIp
|
|
|
|
if ($setPorts) {
|
|
$json.apiPort = $apiPort
|
|
$json.listenPort = $listenPort
|
|
$json.devProxyPort = $devProxyPort
|
|
$json.listenDataPort = $listenDataPort
|
|
}
|
|
|
|
$json | ConvertTo-Json -Depth 20 | Set-Content -Encoding UTF8 -Path $settingsPath
|
|
if ($setPorts) {
|
|
Write-Host "Successfully updated settings.json with ourExternalIpAddress=$publicIp and ports $apiPort-$listenDataPort."
|
|
} else {
|
|
Write-Host "Successfully updated settings.json with ourExternalIpAddress=$publicIp."
|
|
}
|