To the pleasure of its fans, ARK has a really short update interval. This can however be infuriating for server administrators, so we set out to make your life a little bit easier: This script will automatically check whether there is a new update version, and in case there is, automatically update your server. The script is written in PowerShell (version 3 required). It will also inform your players before the update so that they can secure their stuff and log off in a safe location.
Requirements
Installation
Save this text as update.cmd
[sourcecode toolbar=”true” language=”plain” title=”update.cmd”]
@echo off
ver | find "2003" > nul
if %ERRORLEVEL% == 0 goto ver_2003
if not exist "%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe" goto install
"%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe" -command "exit $PSVersionTable.PSVersion.Major"
set PSVer=%ERRORLEVEL%
if %PSVer% LSS 3 goto ps1
powershell -ExecutionPolicy unrestricted -File "%~dp0mainscript.ps1"
exit
:ps1
echo Powershell 2 is not supported.
pause
exit
:ver_2003
echo Windows 2003 is not supported.
pause
exit
:install
echo PowerShell is not installed
pause
exit
[/sourcecode]
Save this text as mainscript.ps1
[sourcecode toolbar=”true” language=”powershell” title=”mainscript.ps1″]
$steamcmdFolder="C:\steamcmd"
$arksurvivalFolder="C:\arkserver"
$arksurvivalSteamScript="update_ark.txt"
$rconIP="127.0.0.1"
$rconPort=32330
$rconPassword="YOURPASSWORD"
$arkSurvivalStartArguments=$("TheIsland?QueryPort=27015?Port=7777?SetCheatPlayer=True?RCONEnabled=True?RCONPort="+$rconPort+"?listen")
$mcrconExec="C:\ARK-Scripts\mcrcon.exe"
$steamAppID="376030"
# Without clearing cache app_info_update may return old informations!
$clearCache=1
$scriptPath = Split-Path -parent $MyInvocation.MyCommand.Definition
$dataPath = $scriptPath+"\data"
$steamcmdExec = $steamcmdFolder+"\steamcmd.exe"
$steamcmdCache = $steamcmdFolder+"\appcache"
$latestAppInfo = $dataPath+"\latestappinfo.json"
$updateinprogress = $arksurvivalFolder+"\updateinprogress.dat"
$latestAvailableUpdate = $dataPath+"\latestavailableupdate.txt"
$latestInstalledUpdate = $dataPath+"\latestinstalledupdate.txt"
If (Test-Path $updateinprogress) {
Write-Host Update is already in progress
} Else {
Get-Date | Out-File $updateinprogress
Write-Host Creating data Directory
New-Item -Force -ItemType directory -Path $dataPath
If ($clearCache) {
Write-Host Removing Cache Folder
Remove-Item $steamcmdCache -Force -Recurse
}
Write-Host Checking for an update
& $steamcmdExec +login anonymous +app_info_update 1 +app_info_print $steamAppID +app_info_print $steamAppID +quit | Out-File $latestAppInfo
Get-Content $latestAppInfo -RAW | Select-String -pattern ‘(?m)"public"\s*\{\s*"buildid"\s*"\d{6,}"’ -AllMatches | %{$_.matches[0].value} | Select-String -pattern ‘\d{6,}’ -AllMatches | %{$_.matches} | %{$_.value} | Out-File $latestAvailableUpdate
If (Test-Path $latestInstalledUpdate) {
$installedVersion = Get-Content $latestInstalledUpdate
} Else {
$installedVersion = 0
}
$availableVersion = Get-Content $latestAvailableUpdate
if ($installedVersion -ne $availableVersion) {
Write-Host Update Available
Write-Host Installed build: $installedVersion – available build: $availableVersion
& $mcrconExec -c -H $rconIP -P $rconPort -p $rconPassword "broadcast New update available, server is restarting in 10 minutes!"
Start-Sleep -s 300
& $mcrconExec -c -H $rconIP -P $rconPort -p $rconPassword "broadcast New update available, server is restarting in 5 minutes!"
Start-Sleep -s 240
& $mcrconExec -c -H $rconIP -P $rconPort -p $rconPassword "broadcast New update available, server is restarting in 1 minute!"
Start-Sleep -s 60
& $mcrconExec -c -H $rconIP -P $rconPort -p $rconPassword "broadcast New update available, server is restarting!"
& $mcrconExec -c -H $rconIP -P $rconPort -p $rconPassword "saveworld"
Start-Sleep -s 10
#Does not work atm
# & $mcrconExec -c -H $rconIP -P $rconPort -p $rconPassword "quit"
$pidARK = (Wmic process where "Commandline like ‘%$rconPort%’ and Name=’ShooterGameServer.exe’" get ProcessId | findstr /r "[1-9][0-9]")
& taskkill /PID $pidARK
Start-Sleep -s 20
& $steamcmdExec +runscript $arksurvivalSteamScript
& $arksurvivalFolder"\ShooterGame\Binaries\Win64\ShooterGameServer.exe" $arkSurvivalStartArguments -nosteamclient -game -lowmemory -nosound -sm4 -server -log
$availableVersion | Out-File $latestInstalledUpdate
Write-Host Update Done!
}
Remove-Item $updateinprogress -Force
}
[/sourcecode]
This is an example of my steamscript (put this in the steamcmd root folder):
[sourcecode toolbar=”true” language=”plain” title=”update_ark.txt”]
//ark
@ShutdownOnFailedCommand 1
@NoPromptForPassword 1
nSubscribedAutoDownloadMaxSimultaneous 32
@cMaxContentServersToRequest 16
@cMaxInitialDownloadSources 1
@fMinDataRateToAttemptTwoConnectionsMbps 0.01
@fDownloadRateImprovementToAddAnotherConnection 0.01
login anonymous
force_install_dir C:\arkserver\
app_update 376030
// validate
quit[/sourcecode]
How to use it?
Edit the variables of mainscript.ps1 so that it fits to your environment.
To run it in an interval just use the Windows Task Scheduler and bind the update.cmd to it.
Hope we could help you with the automatic update script for windows!