-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
111 lines (87 loc) · 3.06 KB
/
install.sh
File metadata and controls
111 lines (87 loc) · 3.06 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
#!/usr/bin/env bash
# braid installer script
# usage: curl -sSL https://raw.githubusercontent.com/alextes/braid/main/install.sh | bash
set -euo pipefail
REPO="alextes/braid"
BINARY_NAME="brd"
INSTALL_DIR="${INSTALL_DIR:-${CARGO_HOME:-$HOME/.cargo}/bin}"
# detect platform
detect_platform() {
local os arch
case "$(uname -s)" in
Linux*) os="unknown-linux-gnu" ;;
Darwin*) os="apple-darwin" ;;
*) echo "error: unsupported OS: $(uname -s)"; exit 1 ;;
esac
case "$(uname -m)" in
x86_64) arch="x86_64" ;;
aarch64) arch="aarch64" ;;
arm64) arch="aarch64" ;;
*) echo "error: unsupported architecture: $(uname -m)"; exit 1 ;;
esac
echo "${arch}-${os}"
}
# get latest release version
get_latest_version() {
curl -sSL "https://api.github.com/repos/${REPO}/releases/latest" \
| grep '"tag_name":' \
| sed -E 's/.*"([^"]+)".*/\1/'
}
# main
main() {
echo "installing braid..."
local platform version download_url tmp_dir
platform=$(detect_platform)
version=$(get_latest_version)
if [[ -z "$version" ]]; then
echo "error: could not determine latest version"
echo ""
echo "no releases found. install from source instead:"
echo " cargo install --git https://github.com/${REPO}.git"
exit 1
fi
echo " version: ${version}"
echo " platform: ${platform}"
# cargo-dist naming convention: <name>-<target>.tar.xz
download_url="https://github.com/${REPO}/releases/download/${version}/braid-${platform}.tar.xz"
echo " downloading from: ${download_url}"
tmp_dir=$(mktemp -d)
trap 'rm -rf "$tmp_dir"' EXIT
if ! curl -sSL "$download_url" -o "${tmp_dir}/braid.tar.xz"; then
echo "error: download failed"
echo ""
echo "the release may not have prebuilt binaries yet."
echo "install from source instead:"
echo " cargo install --git https://github.com/${REPO}.git"
exit 1
fi
tar -xJf "${tmp_dir}/braid.tar.xz" -C "$tmp_dir"
# ensure install directory exists
mkdir -p "$INSTALL_DIR"
# install binary - cargo-dist extracts to braid-<target>/ subdirectory
local binary_path
if [[ -f "${tmp_dir}/braid-${platform}/${BINARY_NAME}" ]]; then
binary_path="${tmp_dir}/braid-${platform}/${BINARY_NAME}"
elif [[ -f "${tmp_dir}/${BINARY_NAME}" ]]; then
binary_path="${tmp_dir}/${BINARY_NAME}"
else
echo "error: could not find binary in archive"
echo "contents of tmp_dir:"
ls -la "$tmp_dir"
exit 1
fi
mv "$binary_path" "${INSTALL_DIR}/${BINARY_NAME}"
chmod +x "${INSTALL_DIR}/${BINARY_NAME}"
echo ""
echo "installed ${BINARY_NAME} to ${INSTALL_DIR}/${BINARY_NAME}"
echo ""
# check if install dir is in PATH
if [[ ":$PATH:" != *":${INSTALL_DIR}:"* ]]; then
echo "note: ${INSTALL_DIR} is not in your PATH"
echo "add it with:"
echo " export PATH=\"${INSTALL_DIR}:\$PATH\""
else
echo "run 'brd --help' to get started"
fi
}
main "$@"