/
extract_runtime.sh
executable file
·60 lines (48 loc) · 1.82 KB
/
extract_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
#!/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.
# 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 named directory rather than one that contains the
# runtime release date.
#
# Usage:
# $ ./extract_runtime.sh <path to steam-runtime-release_latest.tar.xz> <amd|i386|all> <output directory>
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"