-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·77 lines (63 loc) · 2.39 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·77 lines (63 loc) · 2.39 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
#!/usr/bin/env sh
# byokey installer — downloads a release binary from GitHub.
#
# Usage:
# curl -fsSL https://raw.githubusercontent.com/AprilNEA/BYOKEY/master/install.sh | sh
#
# Environment overrides:
# BYOKEY_VERSION Tag to install (default: latest release, e.g. v1.2.0).
# BYOKEY_INSTALL_DIR Where to install the binary (default: $HOME/.byokey/bin).
set -eu
REPO="AprilNEA/BYOKEY"
INSTALL_DIR="${BYOKEY_INSTALL_DIR:-$HOME/.byokey/bin}"
err() { printf 'error: %s\n' "$1" >&2; exit 1; }
info() { printf '%s\n' "$1"; }
# --- Detect platform ---------------------------------------------------------
case "$(uname -s)" in
Linux) os="unknown-linux-gnu" ;;
Darwin) os="apple-darwin" ;;
*) err "Unsupported OS: $(uname -s). Use Homebrew or 'cargo install byokey'." ;;
esac
case "$(uname -m)" in
x86_64|amd64) arch="x86_64" ;;
aarch64|arm64) arch="aarch64" ;;
*) err "Unsupported architecture: $(uname -m)." ;;
esac
target="${arch}-${os}"
# --- Resolve version ---------------------------------------------------------
version="${BYOKEY_VERSION:-}"
if [ -z "$version" ]; then
info "Resolving latest release..."
version=$(curl -fsSL "https://api.github.com/repos/${REPO}/releases/latest" 2>/dev/null \
| sed -n -E '/"tag_name":/{ s/.*"tag_name": *"([^"]+)".*/\1/p; q; }')
[ -n "$version" ] || err "Could not determine latest release tag."
fi
archive="byokey-${version}-${target}.tar.gz"
url="https://github.com/${REPO}/releases/download/${version}/${archive}"
# --- Download & install ------------------------------------------------------
tmp=$(mktemp -d)
trap 'rm -rf "$tmp"' EXIT
info "Downloading $url"
if ! curl -fsSL "$url" -o "$tmp/$archive"; then
err "Download failed. Check that ${version} has a build for ${target} at https://github.com/${REPO}/releases"
fi
tar -xzf "$tmp/$archive" -C "$tmp"
[ -f "$tmp/byokey" ] || err "Archive did not contain a 'byokey' binary."
mkdir -p "$INSTALL_DIR"
mv "$tmp/byokey" "$INSTALL_DIR/byokey"
chmod +x "$INSTALL_DIR/byokey"
info ""
info "Installed byokey ${version} to ${INSTALL_DIR}/byokey"
# --- PATH hint ---------------------------------------------------------------
case ":${PATH}:" in
*":${INSTALL_DIR}:"*)
info "Run: byokey --help"
;;
*)
info ""
info "Add to your shell profile (~/.bashrc, ~/.zshrc, etc.):"
info " export PATH=\"${INSTALL_DIR}:\$PATH\""
info ""
info "Then run: byokey --help"
;;
esac