/
update_runtime.sh
executable file
·71 lines (56 loc) · 2.18 KB
/
update_runtime.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
71
#!/bin/bash -e
# Copyright (C) 2014 Jørgen P. Tjernø <jorgenpt@gmail.com>
# This script is licensed under the zlib license, which can be found in
# the LICENSE file.
# A small helper script that downloads the latest version of the steam
# runtime into the directory the script lives in, unless you already
# have the current version.
function has_tool() { which "$1" >/dev/null 2>&1; }
function fatal() { echo "$@" >&2; exit 1; }
RUNTIME_URL_BASE="http://media.steampowered.com/client/runtime"
RUNTIME_MD5_URL="${RUNTIME_URL_BASE}/steam-runtime-release_latest.tar.xz.md5"
BASEDIR="$(cd "$(dirname "$0")" && pwd)"
LOCAL_RUNTIME="${BASEDIR}/$(basename "$RUNTIME_MD5_URL" ".md5")"
# Check for a working md5 tool.
MD5TOOL="md5sum"
if ! has_tool "$MD5TOOL"; then
if ! has_tool md5; then
fatal "Cannot find md5 command line tool (looked for 'md5' and 'md5sum')."
fi
MD5TOOL="md5 -r"
fi
if ! has_tool curl; then
fatal "Cannot find curl"
fi
# Download the .md5 file that has the metadata.
echo "Retrieving information about latest runtime."
RUNTIME_INFO=$(curl -s "$RUNTIME_MD5_URL")
RUNTIME_MD5=$(awk '{print $1}' <<<"$RUNTIME_INFO")
RUNTIME_FILE=$(awk '{print $2}' <<<"$RUNTIME_INFO")
RUNTIME_URL="${RUNTIME_URL_BASE}/${RUNTIME_FILE}"
# If we already have a runtime, checksum it to see if it needs updating.
if [ -f "$LOCAL_RUNTIME" ]; then
echo "Found local copy of the runtime, checking if it's up to date."
LOCAL_MD5=$($MD5TOOL "$LOCAL_RUNTIME" | awk '{print $1}')
if [ "$LOCAL_MD5" == "$RUNTIME_MD5" ]; then
echo "Local runtime is up to date."
exit 0
else
echo "Local runtime is out of date."
fi
fi
# Do the actual download
echo "Downloading new runtime (from ${RUNTIME_FILE})."
curl -s -o "${LOCAL_RUNTIME}.tmp" "$RUNTIME_URL"
# Verify that we got the MD5 we expected.
LOCAL_MD5=$($MD5TOOL "${LOCAL_RUNTIME}.tmp" | awk '{print $1}')
if [ "$LOCAL_MD5" != "$RUNTIME_MD5" ]; then
fatal "Download has invalid checksum! Aborting!"
fi
# Attempt a p4 edit in case this is a Perforce repository.
if has_tool p4; then
p4 edit "${LOCAL_RUNTIME}" >/dev/null 2>&1 || true
fi
# Move it in place.
mv "${LOCAL_RUNTIME}.tmp" "${LOCAL_RUNTIME}"
echo "All done!"