Created
September 7, 2024 19:22
-
-
Save jagoPG/0cdecbd7724a1f9480082ac52f401ac9 to your computer and use it in GitHub Desktop.
Updates a CoreKeeper server to the latest available version
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# This script updates the Corekeeper server if a new version is available | |
function get_version() { | |
# Get the latest version of the game | |
STEAM_GAME_VERSION=$(/usr/games/steamcmd +login anonymous +app_info_update 0 +app_info_print "1963720" +quit | \ | |
grep -EA 50 "\"branches\"" | grep -EA 5 "\"public\"" | \ | |
grep -E "\"buildid\"" | awk -F '"' '{print $4}') | |
echo $STEAM_GAME_VERSION | |
} | |
function update_game() { | |
# Updates the game and stores the new version | |
sudo -u corekeeper-server -s /bin/bash -c "steamcmd +login anonymous +app_update 1007 validate +app_update 1963720 validate +quit" | |
echo $STEAM_GAME_VERSION > $CURRENT_VERSION_FILE | |
echo "game updated to version $STEAM_GAME_VERSION" | |
} | |
# Set up this variables with your own values 👇👇 | |
SERVER_PROCESS_NAME="corekeeper-server" | |
CURRENT_VERSION_FILE="$HOME/corekeeper-version.txt" | |
CURRENT_VERSION=0 | |
# Main process starts here 👇👇 | |
# Get stored version | |
if [ -f $CURRENT_VERSION_FILE ]; then | |
CURRENT_VERSION=$(cat $CURRENT_VERSION_FILE) | |
echo "current version is $CURRENT_VERSION" | |
else | |
echo "game version file not found" >&2 | |
exit 1 | |
fi | |
STEAM_GAME_VERSION=$(get_version) | |
# Check if the game version has changed | |
if [ "$CURRENT_VERSION" != "$STEAM_GAME_VERSION" ]; then | |
echo "game version has changed from $CURRENT_VERSION to $STEAM_GAME_VERSION" | |
else | |
echo "game is up to date" | |
exit 0 | |
fi | |
# Update the game and the version file | |
echo "stopping corekeeper server" | |
systemctl stop "$SERVER_PROCESS_NAME" | |
echo "updating game" | |
update_game | |
echo "starting corekeeper server" | |
if systemctl start "$SERVER_PROCESS_NAME"; then | |
echo "game updated and server started" | |
else | |
echo "failed to start the server" >&2 | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment