[
    {
        "UpdateStageName": "Server Directory Creation",
        "UpdateSourcePlatform": "All",
        "UpdateSource": "CreateDirectory",
        "UpdateSourceArgs": "{{$FullBaseDir}}server",
        "SkipOnFailure": false
    },
    {
        "UpdateStageName": "Dotnet Directory Creation",
        "UpdateSourcePlatform": "All",
        "UpdateSource": "CreateDirectory",
        "UpdateSourceArgs": "{{$FullBaseDir}}dotnet",
        "SkipOnFailure": false
    },
    {
        "UpdateStageName": ".NET SDK Download",
        "UpdateSourcePlatform": "Linux",
        "UpdateSourceArch": "x86_64",
        "UpdateSource": "Executable",
        "UpdateSourceData": "/bin/bash",
        "UpdateSourceArgs": "-c \"DotnetVersion=\\\"{{DotnetSDKVersion}}\\\"; cd \\\"{{$FullBaseDir}}\\\" && if [[ -x dotnet/dotnet ]]; then InstalledVersion=$(dotnet/dotnet --version | xargs); else InstalledVersion=\\\"\\\"; fi; if [[ -z \\\"$DotnetVersion\\\" ]]; then DotnetVersion=$(wget -qO- https://builds.dotnet.microsoft.com/dotnet/release-metadata/{{DotnetRelease}}/releases.json | jq -r \\\".[\\\\\\\"latest-sdk\\\\\\\"]\\\"); fi; if [[ ! \\\"$DotnetVersion\\\" =~ ^[0-9]+\\.[0-9]+\\.[0-9]+$ ]]; then echo \\\"Invalid .NET SDK version format specified\\\" && exit 1; elif [[ \\\"$InstalledVersion\\\" == \\\"$DotnetVersion\\\" ]]; then echo \\\".NET SDK v$DotnetVersion already installed. Skipping\\\" && exit 0; else [[ -f dotnet.tar.gz ]] && rm -f dotnet.tar.gz >/dev/null 2>&1; wget -qO dotnet.tar.gz https://builds.dotnet.microsoft.com/dotnet/Sdk/$DotnetVersion/dotnet-sdk-$DotnetVersion-linux-x64.tar.gz || { echo \\\"Download failed from the Microsoft CDN. This is a fault with the CDN, not AMP. Aborting\\\"; exit 1; }; rm -rf dotnet/* >/dev/null 2>&1 && tar -xzf dotnet.tar.gz -C dotnet >/dev/null 2>&1 && rm -f dotnet.tar.gz >/dev/null 2>&1 && echo \\\".NET SDK v$DotnetVersion downloaded\\\"; fi\"",
        "SkipOnFailure": false
    },
    {
        "UpdateStageName": ".NET SDK Download",
        "UpdateSourcePlatform": "Linux",
        "UpdateSourceArch": "aarch64",
        "UpdateSource": "Executable",
        "UpdateSourceData": "/bin/bash",
        "UpdateSourceArgs": "-c \"DotnetVersion=\\\"{{DotnetSDKVersion}}\\\"; cd \\\"{{$FullBaseDir}}\\\" && if [[ -x dotnet/dotnet ]]; then InstalledVersion=$(dotnet/dotnet --version | xargs); else InstalledVersion=\\\"\\\"; fi; if [[ -z \\\"$DotnetVersion\\\" ]]; then DotnetVersion=$(wget -qO- https://builds.dotnet.microsoft.com/dotnet/release-metadata/{{DotnetRelease}}/releases.json | jq -r \\\".[\\\\\\\"latest-sdk\\\\\\\"]\\\"); fi; if [[ ! \\\"$DotnetVersion\\\" =~ ^[0-9]+\\.[0-9]+\\.[0-9]+$ ]]; then echo \\\"Invalid .NET SDK version format specified\\\" && exit 1; elif [[ \\\"$InstalledVersion\\\" == \\\"$DotnetVersion\\\" ]]; then echo \\\".NET SDK v$DotnetVersion already installed. Skipping\\\" && exit 0; else [[ -f dotnet.tar.gz ]] && rm -f dotnet.tar.gz >/dev/null 2>&1; wget -qO dotnet.tar.gz https://builds.dotnet.microsoft.com/dotnet/Sdk/$DotnetVersion/dotnet-sdk-$DotnetVersion-linux-arm64.tar.gz || { echo \\\"Download failed from the Microsoft CDN. This is a fault with the CDN, not AMP. Aborting\\\"; exit 1; }; rm -rf dotnet/* >/dev/null 2>&1 && tar -xzf dotnet.tar.gz -C dotnet >/dev/null 2>&1 && rm -f dotnet.tar.gz >/dev/null 2>&1 && echo \\\".NET SDK v$DotnetVersion downloaded\\\"; fi\"",
        "SkipOnFailure": false
    },
    {
        "UpdateStageName": ".NET SDK Download",
        "UpdateSourcePlatform": "Windows",
        "UpdateSource": "Executable",
        "UpdateSourceData": "powershell.exe",
        "UpdateSourceArgs": "-NoProfile -Command \"$ProgressPreference='SilentlyContinue'; [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $DotnetVersion='{{DotnetSDKVersion}}'; Set-Location -Path '{{$FullBaseDir}}'; if (Test-Path 'dotnet/dotnet.exe') { $InstalledVersion =  (& dotnet/dotnet.exe --version).Trim() } else { $InstalledVersion = '' }; if ( [string]::IsNullOrWhiteSpace($DotnetVersion) ) { $DotnetVersion=(Invoke-RestMethod -UseBasicParsing -Uri https://builds.dotnet.microsoft.com/dotnet/release-metadata/{{DotnetRelease}}/releases.json).\\\"latest-sdk\\\" }; if ($DotnetVersion -notmatch '^\\d+\\.\\d+\\.\\d+$') { Write-Output \\\"Invalid .NET SDK version format specified\\\"; exit 1 } elseif ( $InstalledVersion -eq $DotnetVersion ) { Write-Output \\\".NET SDK v$DotnetVersion already installed. Skipping\\\"; exit 0 } else { if ( Test-Path dotnet.zip ) { Remove-Item dotnet.zip -Force -ErrorAction SilentlyContinue *> $null }; try { Invoke-WebRequest -UseBasicParsing -Uri https://builds.dotnet.microsoft.com/dotnet/Sdk/$DotnetVersion/dotnet-sdk-$DotnetVersion-win-x64.zip -OutFile dotnet.zip -ErrorAction Stop } catch { Write-Output \\\"Download failed from the Microsoft CDN. This is a fault with the CDN, not AMP. Aborting\\\"; exit 1; }; Remove-Item -Path 'dotnet/*' -Recurse -Force -ErrorAction SilentlyContinue; Expand-Archive -Path \\\"dotnet.zip\\\" -DestinationPath \\\"dotnet\\\" -Force *> $null; if ( Test-Path dotnet.zip ) { Remove-Item dotnet.zip -Force -ErrorAction SilentlyContinue *> $null }; Write-Output \\\".NET SDK v$DotnetVersion downloaded\\\" }\"",
        "SkipOnFailure": false
    },
    {
        "UpdateStageName": "Server Download",
        "UpdateSourcePlatform": "Linux",
        "UpdateSourceArch": "x86_64",
        "UpdateSource": "Executable",
        "UpdateSourceData": "/bin/bash",
        "UpdateSourceArgs": "-c \"ServerVersion=\\\"{{ServerVersion}}\\\"; ServerReleaseStream=\\\"{{ServerReleaseStream}}\\\"; export DOTNET_ROOT=\\\"{{$FullRootDir}}dotnet\\\"; cd vintage-story && if [[ -x server/VintagestoryServer ]]; then InstalledVersion=$(server/VintagestoryServer --version 2>/dev/null | xargs); else InstalledVersion=\\\"\\\"; fi; if [[ -z \\\"$ServerVersion\\\" ]]; then if [[ \\\"$ServerReleaseStream\\\" == \\\"pre\\\" ]]; then echo \\\"No Vintage Story preview version specified\\\" && exit 1; else ServerVersion=\\\"$(wget -qO- https://api.vintagestory.at/${ServerReleaseStream}.json | jq -r \\\"keys_unsorted[0]\\\")\\\"; fi; fi; if [[ ! \\\"$ServerVersion\\\" =~ ^[0-9]+\\.[0-9]+\\.[0-9]+(-rc\\.[0-9]+|-pre\\.[0-9]+)?$ ]]; then echo \\\"Invalid Vintage Story version format specified\\\" && exit 1; elif [[ \\\"$ServerVersion\\\" =~ ^[0-9]+\\.[0-9]+\\.[0-9]+-rc\\.[0-9]+$ ]]; then ServerReleaseStream=\\\"unstable\\\"; elif [[ \\\"$ServerVersion\\\" =~ ^[0-9]+\\.[0-9]+\\.[0-9]+-pre\\.[0-9]+$ ]]; then ServerReleaseStream=\\\"pre\\\"; else ServerReleaseStream=\\\"stable\\\"; fi; if [[ \\\"$InstalledVersion\\\" == \\\"$ServerVersion\\\" ]]; then echo \\\"Vintage Story v$ServerVersion already installed. Skipping\\\" && exit 0; else [[ -f vs_server.tar.gz ]] && rm -f vs_server.tar.gz >/dev/null 2>&1; wget -qO vs_server.tar.gz https://{{ServerDownloadSource}}/$ServerReleaseStream/vs_server_linux-x64_$ServerVersion.tar.gz || { echo \\\"Download failed from the Vintage Story CDN. This is a fault with the CDN, not AMP. Try an alternative CDN. Aborting\\\"; exit 1; }; rm -rf server/* >/dev/null 2>&1 && tar -xzf vs_server.tar.gz -C server >/dev/null 2>&1 && rm -f vs_server.tar.gz >/dev/null 2>&1 && echo \\\"Vintage Story v$ServerVersion downloaded\\\"; fi\"",
        "SkipOnFailure": false
    },
    {
        "UpdateStageName": "Server Download",
        "UpdateSourcePlatform": "Linux",
        "UpdateSourceArch": "aarch64",
        "UpdateSource": "Executable",
        "UpdateSourceData": "/bin/bash",
        "UpdateSourceArgs": "-c \"ServerVersion=\\\"{{ServerVersion}}\\\"; ServerReleaseStream=\\\"{{ServerReleaseStream}}\\\"; export DOTNET_ROOT=\\\"{{$FullRootDir}}dotnet\\\"; cd vintage-story && if [[ -z \\\"$ServerVersion\\\" ]]; then if [[ \\\"$ServerReleaseStream\\\" == \\\"pre\\\" ]]; then echo \\\"No Vintage Story preview version specified\\\" && exit 1; else ServerVersion=\\\"$(wget -qO- https://api.vintagestory.at/${ServerReleaseStream}.json | jq -r \\\"keys_unsorted[0]\\\")\\\"; fi; fi; if [[ ! \\\"$ServerVersion\\\" =~ ^[0-9]+\\.[0-9]+\\.[0-9]+(-rc\\.[0-9]+|-pre\\.[0-9]+)?$ ]]; then echo \\\"Invalid Vintage Story version format specified\\\" && exit 1; elif [[ \\\"$ServerVersion\\\" =~ ^[0-9]+\\.[0-9]+\\.[0-9]+-rc\\.[0-9]+$ ]]; then ServerReleaseStream=\\\"unstable\\\"; elif [[ \\\"$ServerVersion\\\" =~ ^[0-9]+\\.[0-9]+\\.[0-9]+-pre\\.[0-9]+$ ]]; then ServerReleaseStream=\\\"pre\\\"; else ServerReleaseStream=\\\"stable\\\"; fi; [[ -f vs_server.tar.gz ]] && rm -f vs_server.tar.gz >/dev/null 2>&1; wget -qO vs_server.tar.gz https://{{ServerDownloadSource}}/$ServerReleaseStream/vs_server_linux-x64_$ServerVersion.tar.gz || { echo \\\"Download failed from the Vintage Story CDN. This is a fault with the CDN, not AMP. Try an alternative CDN. Aborting\\\"; exit 1; }; MinorVersion=\\\"${ServerVersion%.*}\\\"; [[ -f vs_experimentalserver.tar.gz ]] && rm -f vs_experimentalserver.tar.gz >/dev/null 2>&1; case $MinorVersion in 1.18) ExpDownloadURL=https://github.com/anegostudios/VintagestoryServerArm64/releases/download/1.18.8/vs_server_linux-arm64-1.18.tar.gz;; 1.19) ExpDownloadURL=https://github.com/anegostudios/VintagestoryServerArm64/releases/download/1.19.0-rc.6/vs_server_linux-arm64-1.19.tar.gz;; 1.20) ExpDownloadURL=https://github.com/anegostudios/VintagestoryServerArm64/releases/download/1.20.0-rc.8/vs_server_linux-arm64_1.20.0.tar.gz;; 1.21) ExpDownloadURL=https://github.com/anegostudios/VintagestoryServerArm64/releases/download/1.21.0/vs_server_linux-arm64_1.21.0.tar.gz;; 1.22) ExpDownloadURL=https://github.com/anegostudios/VintagestoryServerArm64/releases/download/1.22.0/vs_server_linux-arm64_1.22.0.tar.gz;; *) echo \\\"No Experimental Vintage Story version exists for Vintage Story v$ServerVersion\\\" && exit 1;; esac; wget -qO vs_experimentalserver.tar.gz $ExpDownloadURL || { echo \\\"Download failed for the Experimental Vintage Story. Aborting\\\"; exit 1; }; rm -rf server/* >/dev/null 2>&1 && tar -xzf vs_server.tar.gz -C server >/dev/null 2>&1 && rm -f vs_server.tar.gz >/dev/null 2>&1 && echo \\\"Vintage Story v$ServerVersion downloaded\\\" && rm -rf server/VintageStoryServer{,.deps.json,.dll,.pdb,.runtimeconfig.json} server/Lib >/dev/null 2>&1 && tar -xzf vs_experimentalserver.tar.gz -C server $([[ \\\"$MinorVersion\\\" == \\\"1.18\\\" || \\\"$MinorVersion\\\" == \\\"1.19\\\" ]] && echo \\\"--strip-components=1\\\") >/dev/null 2>&1 && rm -f vs_experimentalserver.tar.gz >/dev/null 2>&1 && echo \\\"Experimental Vintage Story v$MinorVersion downloaded\\\"\"",
        "SkipOnFailure": false
    },
    {
        "UpdateStageName": "Server Download",
        "UpdateSourcePlatform": "Windows",
        "UpdateSource": "Executable",
        "UpdateSourceData": "powershell.exe",
        "UpdateSourceArgs": "-NoProfile -Command \"$ProgressPreference='SilentlyContinue'; [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $env:DOTNET_ROOT='{{$FullRootDir}}dotnet'; $ServerVersion='{{ServerVersion}}'; $ServerReleaseStream='{{ServerReleaseStream}}'; Set-Location -Path 'vintage-story'; if (Test-Path 'server/VintagestoryServer.exe') { $versionRaw = & 'server/VintagestoryServer.exe' --version 2>$null; $InstalledVersion = if ($versionRaw) { $versionRaw.Trim() } else { '' } } else { $InstalledVersion = '' }; if ( [string]::IsNullOrWhiteSpace($ServerVersion) ) { if ($ServerReleaseStream -eq 'pre') { Write-Output \\\"No Vintage Story preview version specified\\\"; exit 1 } else { $ServerVersion=(Invoke-RestMethod https://api.vintagestory.at/${ServerReleaseStream}.json).PSObject.Members.Name[0] } }; if ( $ServerVersion -notmatch '^\\d+\\.\\d+\\.\\d+(-rc\\.\\d+|-pre\\.\\d+)?$') { Write-Output \\\"Invalid Vintage Story version format specified\\\"; exit 1 } elseif ( $ServerVersion -match '^\\d+\\.\\d+\\.\\d+-rc\\.\\d+$') { $ServerReleaseStream='unstable' } elseif ( $ServerVersion -match '^\\d+\\.\\d+\\.\\d+-pre\\.\\d+$') { $ServerReleaseStream='pre' } else { $ServerReleaseStream='stable' }; if ( $InstalledVersion -eq $ServerVersion ) { Write-Output \\\"Vintage Story v$ServerVersion already installed. Skipping\\\"; exit 0 } else { if ( Test-Path vs_server.zip ) { Remove-Item vs_server.zip -Force -ErrorAction SilentlyContinue *> $null }; try { Invoke-WebRequest -UseBasicParsing -Uri https://{{ServerDownloadSource}}/$ServerReleaseStream/vs_server_win-x64_$ServerVersion.zip -OutFile vs_server.zip -ErrorAction Stop } catch { Write-Output \\\"Download failed from the Vintage Story CDN. This is a fault with the CDN, not AMP. Try an alternative CDN. Aborting\\\"; exit 1; }; Remove-Item -Path 'server/*' -Recurse -Force -ErrorAction SilentlyContinue; Expand-Archive -Path \\\"vs_server.zip\\\" -DestinationPath \\\"server\\\" -Force *> $null; if ( Test-Path vs_server.zip ) { Remove-Item vs_server.zip -Force -ErrorAction SilentlyContinue *> $null }; Write-Output \\\"Vintage Story v$ServerVersion downloaded\\\" }\"",
        "SkipOnFailure": false
    },
    {
        "UpdateStageName": "Start Server",
        "UpdateSourcePlatform": "All",
        "UpdateSource": "StartApplication",
        "SkipOnFailure": false
    },
    {
        "UpdateStageName": "Wait For Server Start",
        "UpdateSourcePlatform": "All",
        "UpdateSource": "WaitForStartupComplete",
        "SkipOnFailure": false
    },
    {
        "UpdateStageName": "Stop Server",
        "UpdateSourcePlatform": "All",
        "UpdateSource": "ShutdownApplication",
        "SkipOnFailure": false
    }
]