Created
May 26, 2014 01:33
-
-
Save jorgenpt/07f207aefdd49b61c7b6 to your computer and use it in GitHub Desktop.
Helper scripts to update & extract the steam-runtime for direct distribution.
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 -e | |
# Helper script for extracting the steam-runtime that: | |
# - Strips unused parts of the runtime (documentation) | |
# - Allows you to extract a single architecture | |
# - Extracts it to a directory that doesn't contain the runtime date. | |
function fatal() { echo "$@" >&2; exit 1; } | |
if [ $# -lt 3 ]; then | |
fatal "Usage: $0 <steam-runtime path> <amd64|i386|all> <output directory>" >&2 | |
fi | |
LOCAL_RUNTIME="$1" | |
ARCH="$2" | |
OUTPUT="$3" | |
# Validate arguments. | |
if [ ! -f "$LOCAL_RUNTIME" ]; then fatal "Unable to find runtime '$LOCAL_RUNTIME'"; fi | |
case "$ARCH" in | |
amd64) ;; i386) ;; all) ;; | |
*) | |
fatal "Architecture '$ARCH' is not amd64, i386, or all." ;; | |
esac | |
if [ -e "$OUTPUT" ] && ! rmdir "$OUTPUT" >/dev/null 2>&1; then | |
fatal "Output directory '$OUTPUT' already exists and is non-empty, cowardly refusing to extract." | |
fi | |
# Create a file containing patterns to not extract | |
EXCLUSIONSFILE="$(mktemp $USER.extract_runtime.exclusions.XXXX)" | |
# Exclude man pages & docs. | |
echo '*/usr/share/doc' >>"$EXCLUSIONSFILE" | |
echo '*/usr/share/man' >>"$EXCLUSIONSFILE" | |
# Exclude the other arch. | |
case "$ARCH" in | |
amd64) echo 'i386/*' >>"$EXCLUSIONSFILE" ;; | |
i386) echo 'amd64/*' >>"$EXCLUSIONSFILE" ;; | |
esac | |
echo "Extracting runtime for $ARCH from $LOCAL_RUNTIME into $OUTPUT" | |
mkdir -p "$OUTPUT" | |
# Strip the date-specific prefix, exclude our various patterns, and | |
# change directory to $OUTPUT before extracting. | |
tar --strip-components 1 \ | |
-X "$EXCLUSIONSFILE" \ | |
-C "$OUTPUT" \ | |
-xJf "$LOCAL_RUNTIME" | |
rm -f "$EXCLUSIONSFILE" |
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 -e | |
function has_tool() { which "$1" >&- 2>&-; } | |
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!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment