-
Notifications
You must be signed in to change notification settings - Fork 95
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·64 lines (53 loc) · 1.88 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·64 lines (53 loc) · 1.88 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
#!/bin/sh
set -eu
VERSION=2.0.0
RELEASE_URL="https://github.com/zhongwencool/observer_cli/releases/download/v$VERSION"
INSTALL_DIR="$HOME/.local/bin"
for cmd in curl erl escript awk install; do
command -v "$cmd" >/dev/null 2>&1 || {
printf 'observer_cli installer: missing command: %s\n' "$cmd" >&2
exit 1
}
done
if command -v sha256sum >/dev/null 2>&1; then
verify_checksum() { sha256sum -c "$1"; }
elif command -v shasum >/dev/null 2>&1; then
verify_checksum() { shasum -a 256 -c "$1"; }
else
printf 'observer_cli installer: missing command: sha256sum or shasum\n' >&2
exit 1
fi
OTP=$(erl -noshell -eval 'io:put_chars(erlang:system_info(otp_release)), halt().')
case "$OTP" in
26 | 27 | 28 | 29) ;;
*)
printf 'observer_cli installer: unsupported controller OTP: %s\n' "$OTP" >&2
exit 1
;;
esac
ASSET="observer_cli-$VERSION-otp$OTP"
TMP=$(mktemp -d "${TMPDIR:-/tmp}/observer-cli-install.XXXXXX")
STAGED=
cleanup() {
rm -rf "$TMP"
[ -z "$STAGED" ] || rm -f "$STAGED"
}
trap cleanup 0 HUP INT TERM
curl -fsSL "$RELEASE_URL/$ASSET" -o "$TMP/$ASSET"
curl -fsSL "$RELEASE_URL/SHA256SUMS" -o "$TMP/SHA256SUMS"
awk -v asset="$ASSET" '$2 == asset {print}' "$TMP/SHA256SUMS" > "$TMP/$ASSET.sha256"
test "$(wc -l < "$TMP/$ASSET.sha256")" -eq 1
(cd "$TMP" && verify_checksum "$ASSET.sha256")
mkdir -p "$INSTALL_DIR"
STAGED=$(mktemp "$INSTALL_DIR/.observer_cli.XXXXXX")
install -m 0755 "$TMP/$ASSET" "$STAGED"
VERSION_OUTPUT=$("$STAGED" --version)
printf '%s\n' "$VERSION_OUTPUT" | grep -Fx "observer_cli $VERSION" >/dev/null
printf '%s\n' "$VERSION_OUTPUT" | grep -Fx "controller OTP $OTP" >/dev/null
mv -f "$STAGED" "$INSTALL_DIR/observer_cli"
STAGED=
printf '%s\nInstalled observer_cli at %s\n' "$VERSION_OUTPUT" "$INSTALL_DIR/observer_cli"
case ":$PATH:" in
*":$INSTALL_DIR:"*) ;;
*) printf 'Add %s to PATH.\n' "$INSTALL_DIR" ;;
esac