# Astelyx dedicated server for Windows: install or update it from the release
# archive. Windows PowerShell 5.1 or PowerShell 7.
#
# irm https://astelyx.com/install-server.ps1 | iex
#
# To choose the folder:
#
# & ([scriptblock]::Create((irm https://astelyx.com/install-server.ps1))) -Dir 'D:\astelyx-server'
#
# WHAT THIS DOES, AND NOTHING ELSE:
# 1. asks the Astelyx registry for the newest stable dedicated server build
# for Windows on this CPU;
# 2. downloads it over HTTPS from the short-lived link the registry hands
# out, and checks its size and SHA-256 (Get-FileHash) against the
# registry's answer;
# 3. unpacks it into
\astelyx\ (default %USERPROFILE%\astelyx-server),
# replacing only an earlier copy of the server program there. Worlds,
# server.toml and anything else in are left alone;
# 4. prints how to start it.
# It needs no administrator rights, never starts the server, never changes a
# firewall rule or any other setting, and writes nothing outside .
#
# The game client is not here: it is installed by the Astelyx launcher.
param(
[string]$Dir = ''
)
& {
param([string]$Dir)
Set-StrictMode -Version 3
$ErrorActionPreference = 'Stop'
# Invoke-WebRequest's progress bar slows a download down many times over
# in Windows PowerShell 5.1.
$ProgressPreference = 'SilentlyContinue'
# The registry this copy talks to. astelyx.com fills it in when it serves
# the script; $env:ASTELYX_REGISTRY_URL overrides it (https, or http on
# this machine).
$RegistryServed = 'https://api.astelyx.net'
$DownloadPage = 'https://astelyx.com/download'
function Say([string]$Message) { Write-Host "astelyx: $Message" }
function Fail([string]$Message) { throw "astelyx: error: $Message" }
function Test-AllowedUrl([string]$Url) {
return ($Url -match '^https://[A-Za-z0-9.-]+(:[0-9]+)?(/[^\s"\\]*)?$') -or
($Url -match '^http://(127\.0\.0\.1|localhost|\[::1\])(:[0-9]+)?(/[^\s"\\]*)?$')
}
# GET a JSON answer. Returns @{ Status = ; Body = }.
function Get-RegistryJson([string]$Url) {
try {
$r = Invoke-WebRequest -UseBasicParsing -Uri $Url -Headers @{ accept = 'application/json' } -MaximumRedirection 3
return @{ Status = [int]$r.StatusCode; Body = ($r.Content | ConvertFrom-Json); Detail = $null }
} catch {
$resp = $null
if ($_.Exception.PSObject.Properties['Response']) { $resp = $_.Exception.Response }
if ($null -eq $resp) { Fail "could not reach ${Url}: $($_.Exception.Message)" }
$detail = $null
if ($_.ErrorDetails -and $_.ErrorDetails.Message) {
try {
$e = $_.ErrorDetails.Message | ConvertFrom-Json
if ($e.PSObject.Properties['detail']) { $detail = $e.detail }
elseif ($e.PSObject.Properties['error']) { $detail = $e.error }
} catch { }
}
return @{ Status = [int]$resp.StatusCode; Body = $null; Detail = $detail }
}
}
if ($PSVersionTable.PSVersion.Major -lt 6) {
# Windows PowerShell 5.1 may not offer TLS 1.2 by default.
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
} elseif (-not $IsWindows) {
Fail 'this script is for Windows; on macOS and Linux use: curl -fsSL https://astelyx.com/install-server.sh | bash'
}
$Registry = $env:ASTELYX_REGISTRY_URL
if (-not $Registry) { $Registry = $RegistryServed }
if ($Registry.StartsWith('__')) { Fail "this copy of the script does not name a registry; use the command on $DownloadPage" }
$Registry = $Registry.TrimEnd('/')
if (-not (Test-AllowedUrl $Registry)) { Fail "the registry address '$Registry' is not an https:// URL" }
# ---- this machine ----------------------------------------------------
$cpu = $env:PROCESSOR_ARCHITEW6432
if (-not $cpu) { $cpu = $env:PROCESSOR_ARCHITECTURE }
switch ($cpu) {
'AMD64' { $Arch = 'x86_64' }
'ARM64' { $Arch = 'arm64' }
default { Fail "no Astelyx server is built for the '$cpu' processor" }
}
if (-not $Dir) {
if (-not $env:USERPROFILE) { Fail 'USERPROFILE is not set; pass -Dir' }
$Dir = Join-Path $env:USERPROFILE 'astelyx-server'
}
$null = New-Item -ItemType Directory -Force -Path $Dir
$Dir = (Resolve-Path -LiteralPath $Dir).ProviderPath
# Everything temporary lives inside , so the final step is a rename
# on one volume, and it all goes when the script ends.
$Work = Join-Path $Dir ('.astelyx-install.' + [Guid]::NewGuid().ToString('N').Substring(0, 8))
$null = New-Item -ItemType Directory -Path $Work
try {
# ---- what is published ------------------------------------------
Say "asking $Registry for the newest dedicated server for windows $Arch"
$latest = Get-RegistryJson "$Registry/v1/builds/latest?category=server&os=windows&arch=$Arch"
if ($latest.Status -eq 404 -and $Arch -eq 'arm64') {
# Windows on Arm runs x64 programs through its built-in emulation.
Say 'no arm64 build is published; looking for the x86_64 one (Windows on Arm runs it emulated)'
$Arch = 'x86_64'
$latest = Get-RegistryJson "$Registry/v1/builds/latest?category=server&os=windows&arch=$Arch"
}
if ($latest.Status -eq 404) { Fail "no dedicated server is published for Windows on $Arch yet (see $DownloadPage)" }
if ($latest.Status -ne 200) { Fail "the registry refused the lookup: $($latest.Detail)" }
$build = $latest.Body.build
$id = [string]$build.id
$version = [string]$build.version
$sha = [string]$build.sha256
$size = [int64]$build.size_bytes
if ($id -notmatch '^[0-9a-f-]{36}$') { Fail "the registry's answer has no build id" }
if ($version -notmatch '^[A-Za-z0-9.+_-]{1,64}$') { Fail "the registry's answer has no usable version" }
if ($sha -notmatch '^[0-9a-f]{64}$') { Fail "the registry's answer has no sha256" }
if ($build.category -ne 'server' -or $build.os -ne 'windows' -or $build.arch -ne $Arch) {
Fail "the registry answered with a $($build.category) build for $($build.os) $($build.arch), not a server for windows $Arch"
}
Say "newest: $version ($Arch, $size bytes, sha256 $sha)"
$desc = Get-RegistryJson "$Registry/v1/builds/$id/download"
if ($desc.Status -eq 403) {
Fail "server downloads are not open right now: $($desc.Detail). Install it from the Astelyx launcher instead."
}
if ($desc.Status -ne 200) { Fail "the registry refused the download: $($desc.Detail)" }
$url = [string]$desc.Body.url
if (-not (Test-AllowedUrl $url)) { Fail "the registry's download link is not an https:// URL" }
if ([string]$desc.Body.sha256 -ne $sha) { Fail 'the download the registry offers is not the build it listed; run the command again' }
# ---- download and verify ----------------------------------------
Say 'downloading'
$zip = Join-Path $Work 'server.zip'
try {
Invoke-WebRequest -UseBasicParsing -Uri $url -OutFile $zip -MaximumRedirection 3
} catch {
Fail "the download failed: $($_.Exception.Message)"
}
$gotSize = (Get-Item -LiteralPath $zip).Length
if ($gotSize -ne $size) { Fail "the download is $gotSize bytes, the registry says $size; nothing was installed" }
$got = (Get-FileHash -LiteralPath $zip -Algorithm SHA256).Hash.ToLowerInvariant()
if ($got -ne $sha) { Fail "the download's sha256 is $got, the registry says $sha; nothing was installed" }
Say "sha256 verified: $got"
# ---- unpack -----------------------------------------------------
# Every entry must be a plain relative name inside the archive; it is
# checked before anything is written.
Add-Type -AssemblyName System.IO.Compression.FileSystem
$unpacked = Join-Path $Work 'unpacked'
$null = New-Item -ItemType Directory -Path $unpacked
$archive = [System.IO.Compression.ZipFile]::OpenRead($zip)
try {
foreach ($entry in $archive.Entries) {
$name = $entry.FullName
$parts = $name.TrimEnd('/') -split '/'
if ($name -match '\\' -or $name -match ':' -or $name.StartsWith('/') -or
($parts | Where-Object { $_ -eq '..' -or $_ -eq '.' -or $_ -eq '' })) {
Fail "the archive holds an unsafe entry '$name'; nothing was installed"
}
}
} finally {
$archive.Dispose()
}
[System.IO.Compression.ZipFile]::ExtractToDirectory($zip, $unpacked)
$newProgram = Join-Path $unpacked 'astelyx\voxel-server.exe'
if (-not (Test-Path -LiteralPath $newProgram -PathType Leaf) -or (Get-Item -LiteralPath $newProgram).Length -eq 0) {
Fail 'the archive has no astelyx/voxel-server.exe; nothing was installed'
}
$sig = Get-AuthenticodeSignature -LiteralPath $newProgram
if ($sig.Status -eq 'Valid') { $signed = $sig.SignerCertificate.Subject } else { $signed = 'not Authenticode-signed' }
# ---- install ----------------------------------------------------
$target = Join-Path $Dir 'astelyx'
$replaced = $false
if (Test-Path -LiteralPath $target) {
if (-not (Test-Path -LiteralPath (Join-Path $target 'voxel-server.exe') -PathType Leaf)) {
Fail "$target exists and is not an Astelyx server program; move it away or pass another -Dir"
}
try {
Move-Item -LiteralPath $target -Destination (Join-Path $Work 'previous')
} catch {
Fail "could not move the old program aside (is the server still running? stop it first); nothing was changed"
}
$replaced = $true
}
try {
Move-Item -LiteralPath (Join-Path $unpacked 'astelyx') -Destination $target
} catch {
if ($replaced) { Move-Item -LiteralPath (Join-Path $Work 'previous') -Destination $target -ErrorAction SilentlyContinue }
Fail 'could not put the new program in place; the old one was kept'
}
# ---- what was done ----------------------------------------------
$program = Join-Path $target 'voxel-server.exe'
Write-Host ''
Say "installed the Astelyx dedicated server $version for windows $Arch"
Say " program $program"
Say " sha256 $sha (matches the registry)"
Say " signed $signed"
if ($replaced) {
Say " replaced the earlier program in $target; nothing else in $Dir was touched"
} else {
Say ' nothing else was written'
}
Write-Host @"
To start it:
cd "$Dir"
.\astelyx\voxel-server.exe
The first start stops at the Minecraft EULA, as the Minecraft server does:
it writes eula.txt in that folder and exits. Read the EULA at
https://aka.ms/MinecraftEULA, change eula=false to eula=true in eula.txt
to agree to it, and start the server again.
It needs Minecraft 26.1.2's own data, which is not part of this download:
- if the Minecraft Launcher has installed 26.1.2 on this computer, the
server finds it by itself;
- otherwise, with internet access turned on in server.toml
([internet] enabled = true), it downloads Mojang's official 26.1.2
server.jar from Mojang itself, checks it, and keeps it in
.astelyx\minecraft\26.1.2\ for later starts;
- or download the 26.1.2 server.jar from minecraft.net yourself and
start it with: .\astelyx\voxel-server.exe --minecraft-jar C:\path\to\server.jar
The world, server.toml and eula.txt are created in the folder you start it from.
Players join from the Astelyx launcher, signed in with a Minecraft account.
Windows Defender Firewall asks, the first time the server starts, whether
voxel-server.exe may accept connections. Allow "Private networks" for a home
network; allow "Public networks" only if you mean to. This script changed no
firewall rule.
"@
} finally {
Remove-Item -LiteralPath $Work -Recurse -Force -ErrorAction SilentlyContinue
}
} $Dir