-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·113 lines (98 loc) · 3.41 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·113 lines (98 loc) · 3.41 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/bin/sh
set -eu
REPOSITORY="datavil/framex"
VERSION="${FX_VERSION:-latest}"
say() {
printf '%s\n' "framex: $*"
}
fail() {
say "$*" >&2
exit 1
}
command -v curl >/dev/null 2>&1 || fail "curl is required"
command -v tar >/dev/null 2>&1 || fail "tar is required"
os="$(uname -s)"
arch="$(uname -m)"
case "$os/$arch" in
Linux/x86_64 | Linux/amd64)
# The static musl build also runs on glibc distributions and does not
# inherit the GitHub runner's minimum glibc version.
target="x86_64-unknown-linux-musl"
;;
Linux/arm64 | Linux/aarch64)
target="aarch64-unknown-linux-musl"
;;
Darwin/arm64 | Darwin/aarch64)
target="aarch64-apple-darwin"
;;
Darwin/x86_64 | Darwin/amd64)
target="x86_64-apple-darwin"
;;
*)
fail "unsupported platform: $os/$arch"
;;
esac
archive="fx-$target.tar.gz"
if [ "$VERSION" = "latest" ]; then
release_url="https://github.com/$REPOSITORY/releases/latest/download"
else
VERSION="v${VERSION#v}"
release_url="https://github.com/$REPOSITORY/releases/download/$VERSION"
fi
if [ -n "${FX_INSTALL_DIR:-}" ]; then
install_dir="$FX_INSTALL_DIR"
default_install_dir=false
else
[ -n "${HOME:-}" ] || fail "HOME is not set; set FX_INSTALL_DIR explicitly"
install_dir="$HOME/.local/bin"
default_install_dir=true
fi
tmp_dir="$(mktemp -d 2>/dev/null || mktemp -d -t framex)"
cleanup() {
rm -rf "$tmp_dir"
}
trap cleanup EXIT HUP INT TERM
say "downloading $archive"
curl -fLsS --retry 3 "$release_url/$archive" -o "$tmp_dir/$archive"
curl -fLsS --retry 3 "$release_url/$archive.sha256" -o "$tmp_dir/$archive.sha256"
expected_checksum="$(sed 's/[[:space:]].*//' "$tmp_dir/$archive.sha256")"
if command -v sha256sum >/dev/null 2>&1; then
actual_checksum="$(sha256sum "$tmp_dir/$archive" | sed 's/[[:space:]].*//')"
elif command -v shasum >/dev/null 2>&1; then
actual_checksum="$(shasum -a 256 "$tmp_dir/$archive" | sed 's/[[:space:]].*//')"
else
fail "sha256sum or shasum is required to verify the download"
fi
[ "$expected_checksum" = "$actual_checksum" ] || fail "checksum verification failed"
tar -xzf "$tmp_dir/$archive" -C "$tmp_dir"
mkdir -p "$install_dir"
install -m 755 "$tmp_dir/fx" "$install_dir/fx"
"$install_dir/fx" --version >/dev/null 2>&1 || fail "installed binary could not be started"
say "installed fx to $install_dir/fx"
case ":${PATH:-}:" in
*":$install_dir:"*) ;;
*)
if [ "$default_install_dir" = true ]; then
case "${SHELL:-}" in
*/bash) shell_profile="$HOME/.bashrc" ;;
*/zsh) shell_profile="$HOME/.zshrc" ;;
*/fish)
shell_profile="$HOME/.config/fish/config.fish"
mkdir -p "$HOME/.config/fish"
;;
*) shell_profile="$HOME/.profile" ;;
esac
case "${SHELL:-}" in
*/fish) path_line='fish_add_path "$HOME/.local/bin"' ;;
*) path_line='export PATH="$HOME/.local/bin:$PATH"' ;;
esac
if ! grep -F "$path_line" "$shell_profile" >/dev/null 2>&1; then
printf '\n# FrameX CLI\n%s\n' "$path_line" >> "$shell_profile"
fi
say "added $install_dir to PATH in $shell_profile"
say "restart your shell or run: $path_line"
else
say "add $install_dir to PATH to run fx"
fi
;;
esac