-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate.sh
executable file
·70 lines (55 loc) · 1.88 KB
/
update.sh
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env bash
# Setup error handling
set -e
#set -o pipefail
# Enable debugging
# set -x
# Print the user we're currently running as
echo "Running as user: $(whoami)"
echo "Checking for updates.."
# Remove the old cached app info if it exists
if [ -f "$HOME/Steam/appcache/appinfo.vdf" ]; then
rm -fr $HOME/Steam/appcache/appinfo.vdf
fi
# Use "steamer" to get the Steam app info as valid JSON
APPINFO=$(steamer --appinfo 748090)
# Validate $APPINFO as valid JSON using jq
if echo ${APPINFO} | jq -e . >/dev/null 2>&1; then
echo "Parsed app info successfully"
else
echo "Failed to parse app info"
exit 1
fi
# Use jq to get the latest build id
BUILDID=$(echo ${APPINFO} | jq '.depots.branches.public.buildid')
## TODO: Further validate that the build id is a number
# Validate $BUILDID as a non-empty string
if [ -n "$BUILDID" ]; then
echo "Parsed build id successfully: $BUILDID"
else
echo "Failed to parse build id"
exit 1
fi
# Check if an existing build id is found, keeping track of whether this is a fresh install or not
BUILDID_PATH="/steamcmd/colonysurvival/build.id"
FRESH_INSTALL="false"
if [ ! -f "$BUILDID_PATH" ]; then FRESH_INSTALL="true"; fi
# Get the existing build id (if any)
BUILDID_OLD=$(cat "$BUILDID_PATH" || true)
echo "Existing build id: $BUILDID_OLD"
# Check between if the build id has changed
if [ "$BUILDID" != "$BUILDID_OLD" ]; then
echo "New build id $BUILDID does not match old build id $BUILDID_OLD"
# Store the build id in a file, overwriting any existing file
echo $BUILDID > "$BUILDID_PATH"
cat "$BUILDID_PATH"
# Gracefully shutdown the server to apply the updates (if necessary)
if [ $FRESH_INSTALL == "true" ]; then
echo "Fresh install detected, skipping update.."
else
echo "Shutting down to install the update.."
kill -INT $(pidof expect)
fi
else
echo "New build id $BUILDID matches the old build id $BUILDID_OLD, skipping.."
fi