-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall.sh
90 lines (75 loc) · 2.42 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# Modified from: https://github.com/m1guelpf/plz-cli/blob/main/install.sh
#!/usr/bin/env bash
set -e
main() {
PLATFORM="$(uname | tr '[:upper:]' '[:lower:]')"
if [ "$PLATFORM" = "mingw32_nt" ] || [ "$PLATFORM" = "mingw64_nt" ]; then
PLATFORM="windows"
fi
BIN_DIR=${BIN_DIR:-$HOME/.local/bin}
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
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
if [[ "$PLATFORM" == "windows" ]]; then
EXTENSION=".zip"
else
EXTENSION=".tar.xz"
fi
BINARY_URL="https://github.com/mufeez-amjad/avail/releases/latest/download/avail-${ARCHITECTURE}-${PLATFORM}${EXTENSION}"
unset exe
if [ ! -d "$BIN_DIR" ]; then
mkdir -p "$BIN_DIR"
fi
echo "Downloading latest binary from $BINARY_URL to $BIN_DIR"
if [[ "$PLATFORM" == "windows" ]]; then
ensure curl -L "$BINARY_URL" -o "$BIN_DIR/avail.zip"
unzip "$BIN_DIR/avail.zip" -d "$BIN_DIR"
rm "$BIN_DIR/avail.zip"
exe = ".exe"
else
ensure curl -L "$BINARY_URL" | tar -xJ -C "$BIN_DIR" --strip-components 1
fi
if [ ! -f "$BIN_DIR/avail$exe" ]; then
echo "Download failed, could not find $BIN_DIR/avail$exe"
exit 1
fi
chmod +x "$BIN_DIR/avail$exe"
echo "installed - $("$BIN_DIR/avail$exe" --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