summaryrefslogtreecommitdiff
path: root/update_and_start.sh
blob: 8e721056ac42a628c2344b520e59a24cbbd37442 (plain)
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
#!/bin/bash

SERVER_PATH=/opt/ss14/server
BUILD_JSON_PATH="$SERVER_PATH"/build.json
CONFIG_PATH="$SERVER_PATH"/server_config.toml
SERVER="$SERVER_PATH"/Robust.Server

TEMP_ZIP_PATH=/tmp/ss14-temp.zip
TEMP_CONFIG_PATH=/tmp/server_config.toml

LATEST_VER=$(curl https://wizards.cdn.spacestation14.com/fork/wizards | sed -nE 's/(\s*)<dd><span class="versionNumber">(.*)<\/span><\/dd>/\2/p' | head -1)

if [ \! -f "$BUILD_JSON_PATH" ] || ! grep -q "$LATEST_VER" "$BUILD_JSON_PATH"; then
	rm -r "$SERVER_PATH"/*

	# backup server config
	if [ -f "$CONFIG_PATH" ]; then
		cp "$CONFIG_PATH" "$TEMP_CONFIG_PATH"
	fi

	# ARM64 version
	wget "https://wizards.cdn.spacestation14.com/fork/wizards/version/$LATEST_VER/file/SS14.Server_linux-arm64.zip" -O "$TEMP_ZIP_PATH"

	# x64 version
	#wget "https://wizards.cdn.spacestation14.com/fork/wizards/version/$LATEST_VER/file/SS14.Server_linux-x64.zip" -O "$TEMP_ZIP_PATH"

	unzip "$TEMP_ZIP_PATH" -d "$SERVER_PATH"
	rm "$TEMP_ZIP_PATH"

	chmod +x "$SERVER"

	# restore config or copy default
	if [ -f "$TEMP_CONFIG_PATH" ]; then
		cp "$TEMP_CONFIG_PATH" "$SERVER_PATH"
	else
		cp server_config.toml "$SERVER_PATH"
	fi
fi

"$SERVER"