-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPerpetual.sh
More file actions
executable file
·77 lines (66 loc) · 2 KB
/
Copy pathPerpetual.sh
File metadata and controls
executable file
·77 lines (66 loc) · 2 KB
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
72
73
74
75
76
77
#!/usr/bin/env bash
#
# Perpetual.sh - launcher script that detects current OS architecture
# and executes the matching Perpetual binary located alongside this script.
#
# Fallback: if a matching binary cannot be found next to this script,
# a generic "Perpetual" binary in the current working directory will be used instead.
#
# All command line arguments and stdin are passed through to the selected binary,
# and its exit code becomes the exit code of this script.
set -u
SCRIPT_DIR="$( cd "$( dirname "$0" )" && pwd )"
# Detect CPU architecture and map it to the naming scheme used by release binaries.
detect_arch() {
local machine
machine="$(uname -m 2>/dev/null || echo unknown)"
case "$machine" in
x86_64|amd64)
echo "amd64"
;;
aarch64|arm64)
echo "arm64"
;;
i386|i486|i586|i686|x86)
echo "x86"
;;
*)
echo "unknown"
;;
esac
}
ARCH="$(detect_arch)"
TARGET_BIN=""
if [ "$ARCH" != "unknown" ]; then
CANDIDATE="$SCRIPT_DIR/Perpetual_${ARCH}.bin"
if [ -f "$CANDIDATE" ]; then
TARGET_BIN="$CANDIDATE"
fi
fi
# Fallback to a generic "Perpetual" binary
if [ -z "$TARGET_BIN" ]; then
FALLBACK="$SCRIPT_DIR/Perpetual"
if [ -f "$FALLBACK" ]; then
TARGET_BIN="$FALLBACK"
fi
fi
if [ -z "$TARGET_BIN" ]; then
FALLBACK="./Perpetual"
if [ -f "$FALLBACK" ]; then
TARGET_BIN="$FALLBACK"
fi
fi
if [ -z "$TARGET_BIN" ]; then
echo "Error: could not find a suitable Perpetual binary to run." >&2
echo "Looked for: $SCRIPT_DIR/Perpetual_${ARCH}.bin and ./Perpetual" >&2
exit 1
fi
# Make sure the resolved binary is executable (archive extraction may strip permissions).
if [ ! -x "$TARGET_BIN" ]; then
chmod +x "$TARGET_BIN" 2>/dev/null
fi
if [ ! -x "$TARGET_BIN" ]; then
echo "Error: found Perpetual binary at '$TARGET_BIN' but it is not executable, and permissions could not be changed." >&2
exit 1
fi
exec "$TARGET_BIN" "$@"