-
Notifications
You must be signed in to change notification settings - Fork 78
/
install.sh
executable file
·74 lines (64 loc) · 1.88 KB
/
install.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
72
73
74
#!/usr/bin/env bash
set -e
main() {
BIN_DIR=${BIN_DIR-"$HOME/.bin"}
mkdir -p "$BIN_DIR"
case $SHELL in
*/zsh)
PROFILE=$HOME/.zshrc
;;
*/bash)
PROFILE=$HOME/.bashrc
;;
*/fish)
PROFILE=$HOME/.config/fish/config.fish
;;
*/ash)
PROFILE=$HOME/.profile
;;
*)
echo "could not detect shell, manually add ${BIN_DIR} to your PATH."
exit 1
esac
if [[ ":$PATH:" != *":${BIN_DIR}:"* ]]; then
echo >> "$PROFILE" && echo "export PATH=\"\$PATH:$BIN_DIR\"" >> "$PROFILE"
fi
PLATFORM="$(uname -s)"
case $PLATFORM in
Linux)
PLATFORM="linux"
;;
Darwin)
PLATFORM="darwin"
;;
*)
err "unsupported platform: $PLATFORM"
;;
esac
ARCHITECTURE="$(uname -m)"
if [ "${ARCHITECTURE}" = "x86_64" ]; then
# Redirect stderr to /dev/null to avoid printing errors if non Rosetta.
if [ "$(sysctl -n sysctl.proc_translated 2>/dev/null)" = "1" ]; then
ARCHITECTURE="aarch64" # Rosetta.
else
ARCHITECTURE="x86_64" # Intel.
fi
elif [ "${ARCHITECTURE}" = "arm64" ] ||[ "${ARCHITECTURE}" = "aarch64" ] ; then
ARCHITECTURE="aarch64" # Arm.
else
ARCHITECTURE="x86_64" # Amd.
fi
BINARY_URL="https://github.com/m1guelpf/plz-cli/releases/latest/download/plz-${PLATFORM}-${ARCHITECTURE}"
echo "$BINARY_URL"
echo "downloading latest binary"
ensure curl -L "$BINARY_URL" -o "$BIN_DIR/plz"
chmod +x "$BIN_DIR/plz"
echo "installed - $("$BIN_DIR/plz" --version)"
}
# Run a command that should never fail. If the command fails execution
# will immediately terminate with an error showing the failing
# command.
ensure() {
if ! "$@"; then err "command failed: $*"; fi
}
main "$@" || exit 1