Last active
December 4, 2022 05:13
-
-
Save ryunp/641eaac910bbbc5dcdf90350371cae57 to your computer and use it in GitHub Desktop.
Basic SteamCMD app management using a clever CSV file
We can make this file beautiful and searchable if this error is corrected: Illegal quoting in line 2.
This file contains hidden or 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
APP_ID,APP_NAME,APP_START_CMD | |
565060,Avorion,AvorionServer/server.sh --galaxy-name "Expert 2-3-0" --admin ryunp |
This file contains hidden or 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
#!/bin/bash | |
# Author: ryunp | |
# Date: 12/1/22 | |
# Descrption: Basic SteamCMD app management using a clever CSV file. | |
# Script accepts a single argument that filters the app list. | |
# CSV file values: APP_ID, APP_NAME, APP_START_CMD. | |
# APP_ID: The steam app id | |
# APP_NAME: Human friendly name, used for display purposes only | |
# APP_START_CMD: The command to start the app server assuming the CWD | |
# is set to Steam's common app dir (.../Steam/steamapps/common/) | |
STEAM_CMD="~/steamcmd" | |
STEAM_INSTALL_PATH="~/Steam" | |
SCRIPT_PATH=$( cd "$(dirname "$(readlink -f "$0")")" ; pwd -P ) | |
LOG_FILE="$SCRIPT_PATH/log.txt" | |
APPS_FILE="$SCRIPT_PATH/apps.csv" | |
declare -a APP_LIST | |
APP_INDEX=0 | |
## | |
# Load Data | |
## | |
# Read target file lines into array | |
{ | |
# Eat first line of input (header) | |
read | |
# Scan for matching entries | |
while read -r line; do | |
if [[ "${line}" != "" ]]; then | |
if [[ "${line,,}" = *"${1,,}"* ]]; then | |
APP_LIST+=("$line") | |
fi | |
fi | |
done | |
} < "$APPS_FILE" | |
# Ensure we have data | |
if (( ${#APP_LIST[@]} == 0 )); then exit 1; fi | |
## | |
# App Menu | |
## | |
# Prepare App display: Determine width of App ID column (dynamic data) | |
APPID_HDR_TEXT="AppId" | |
APPID_COL_WIDTH=0 | |
for line in "${APP_LIST[@]}"; do | |
# Decode app data | |
IFS="," read -ra VALUES <<< "$line" | |
# Capture field value length | |
if (( ${#VALUES[0]} > APPID_COL_WIDTH )); then | |
APPID_COL_WIDTH=${#VALUES[0]} | |
fi | |
done | |
if (( $APPID_COL_WIDTH < ${#APPID_HDR_TEXT} )); then | |
APPID_COL_WIDTH=${#APPID_HDR_TEXT}; | |
fi | |
TABLE_ROW_FORMAT="%-2s %-${APPID_COL_WIDTH}s %s\n" | |
# Prepare App display: Print table header | |
printf "$TABLE_ROW_FORMAT" "#" "$APPID_HDR_TEXT" "AppName" | |
# Display Apps | |
for i in "${!APP_LIST[@]}"; do | |
# Adjust for 1-based index | |
ITEM_ID=$(( i + 1 )) | |
# Decode app data | |
IFS="," read -ra VALUES <<< "${APP_LIST[$i]}" | |
# Present app info | |
printf "$TABLE_ROW_FORMAT" "$ITEM_ID" "${VALUES[0]}" "${VALUES[1]}" | |
done | |
# Handle App selection input | |
read -p "Select App # (submit nothing to exit): " USER_APP_IDX | |
echo "" | |
if [[ "$USER_APP_IDX" = "" ]]; then | |
exit 1 | |
elif (( USER_APP_IDX <= 0 || USER_APP_IDX > ${#APP_LIST[@]} )); then | |
echo "Selection out of provided range" | |
exit 1 | |
else | |
APP_INDEX=$(( USER_APP_IDX - 1 )) | |
fi | |
# Decode selected App data | |
IFS="," read -ra VALUES <<< "${APP_LIST[$APP_INDEX]}" | |
APP_ID=${VALUES[0]} | |
APP_NAME=${VALUES[1]} | |
APP_START_CMD=${VALUES[2]} | |
## | |
# Task Menu | |
## | |
# Prepare Task display: | |
TABLE_ROW_FORMAT="%-2s %-6s %s\n" | |
# Display avaialable Tasks | |
echo "__$APP_NAME ($APP_ID)__" | |
printf "$TABLE_ROW_FORMAT" "#" "Task" "Args" | |
printf "$TABLE_ROW_FORMAT" "1" "Update" | |
printf "$TABLE_ROW_FORMAT" "2" "Start" "$APP_START_CMD" | |
# Handle App selection input | |
read -p "Select Task # (submit nothing to exit): " TASK_IDX | |
echo "" | |
TIMESTAMP=$( date +%F@%T ) | |
if [[ $TASK_IDX -eq "1" ]]; then | |
# Update | |
echo "[$TIMESTAMP] Updating $APP_NAME ($APP_ID)" >> "$LOG_FILE" | |
eval $STEAM_CMD \ | |
"+@ShutdownOnFailedCommand 1 "\ | |
"+@NoPromptForPassword 1 "\ | |
"+login anonymous "\ | |
"+app_update $APP_ID validate "\ | |
"+quit" | |
elif [[ $TASK_IDX -eq "2" ]]; then | |
# Start | |
echo "[$TIMESTAMP] Starting $APP_NAME ($APP_ID) '../$APP_START_CMD'" >> "$LOG_FILE" | |
eval "$STEAM_INSTALL_PATH/steamapps/common/$APP_START_CMD" | |
fi |
This file contains hidden or 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
steam@compy:~$ ./manage_apps.sh | |
# AppId AppName | |
1 565060 Avorion | |
Select App # (submit nothing to exit): 1 | |
__Avorion (565060)__ | |
# Task Args | |
1 Update | |
2 Start AvorionServer/server.sh --galaxy-name "Expert 2-3-0" --admin ryunp | |
Select Task # (submit nothing to exit): 1 | |
Redirecting stderr to '/home/steam/Steam/logs/stderr.txt' | |
[ 0%] Checking for available updates... | |
[----] Verifying installation... | |
Steam Console Client (c) Valve Corporation - version 1669935972 | |
-- type 'quit' to exit -- | |
Loading Steam API...OK | |
"@ShutdownOnFailedCommand" = "1" | |
"@NoPromptForPassword" = "1" | |
Connecting anonymously to Steam Public...OK | |
Waiting for client config...OK | |
Waiting for user info...OK | |
Update state (0x5) verifying install, progress: 0.80 (1048576 / 131287015) | |
Success! App '565060' fully installed. | |
steam@compy:~$ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment