-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·120 lines (105 loc) · 4.54 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·120 lines (105 loc) · 4.54 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
114
115
116
117
118
119
120
#!/usr/bin/env sh
# binvim Linux installer.
#
# curl -fsSL https://binvim.dev/install.sh | sh
#
# Optional environment overrides:
# BINVIM_VERSION=v0.5.9 pin to a specific tag (default: latest release)
# BINVIM_INSTALL_DIR=/opt/bin override install directory (default: $HOME/.local/bin)
#
# macOS users: use Homebrew instead — `brew install bgunnarsson/binvim/binvim`.
set -eu
REPO="bgunnarsson/binvim"
INSTALL_DIR="${BINVIM_INSTALL_DIR:-$HOME/.local/bin}"
err() { printf 'error: %s\n' "$1" >&2; exit 1; }
info() { printf '==> %s\n' "$1"; }
need() {
command -v "$1" >/dev/null 2>&1 || err "missing required tool: $1"
}
need curl
need tar
need uname
uname_s=$(uname -s 2>/dev/null || echo unknown)
uname_m=$(uname -m 2>/dev/null || echo unknown)
case "$uname_s/$uname_m" in
Linux/x86_64|Linux/amd64) target="x86_64-unknown-linux-musl" ;;
Linux/aarch64|Linux/arm64) target="aarch64-unknown-linux-musl" ;;
# No pre-built macOS binary — cargo + brew are both first-class
# paths on macOS and avoid the extra GitHub-Actions matrix.
# Print both install paths and exit; copy-pasting either works.
Darwin/*)
printf 'binvim does not ship a pre-built macOS binary.\n\n' >&2
printf 'Install via Homebrew:\n' >&2
printf ' brew install bgunnarsson/binvim/binvim\n\n' >&2
printf 'Or via cargo:\n' >&2
printf ' cargo install --locked binvim\n\n' >&2
printf 'Both build from source against the version published on crates.io.\n' >&2
exit 1
;;
# Git Bash / MSYS2 / Cygwin all run on Windows but report
# MINGW*/MSYS*/CYGWIN* from uname. Point users at the PowerShell
# installer + cargo + the GitHub Releases zip; this shell script
# isn't the right surface for a Windows install.
MINGW*/*|MSYS*/*|CYGWIN*/*)
printf 'binvim on Windows:\n\n' >&2
printf ' Native installer (PowerShell):\n' >&2
printf ' iwr https://binvim.dev/install.ps1 -UseBasicParsing | iex\n\n' >&2
printf ' Or via cargo:\n' >&2
printf ' cargo install --locked binvim\n\n' >&2
printf ' Or grab the prebuilt zip from\n' >&2
printf ' https://github.com/%s/releases/latest\n' "$REPO" >&2
exit 1
;;
Linux/*) err "unsupported Linux architecture: $uname_m" ;;
*) err "unsupported OS: $uname_s" ;;
esac
if [ -z "${BINVIM_VERSION:-}" ]; then
info "resolving latest release"
BINVIM_VERSION=$(curl -fsSL "https://api.github.com/repos/$REPO/releases/latest" \
| sed -n 's/.*"tag_name": *"\([^"]*\)".*/\1/p' | head -n1)
[ -n "$BINVIM_VERSION" ] || err "could not resolve latest release; set BINVIM_VERSION explicitly"
fi
archive="binvim-${BINVIM_VERSION}-${target}.tar.gz"
url="https://github.com/${REPO}/releases/download/${BINVIM_VERSION}/${archive}"
sha_url="${url}.sha256"
tmp=$(mktemp -d)
trap 'rm -rf "$tmp"' EXIT INT TERM
info "downloading ${archive}"
curl -fsSL "$url" -o "$tmp/$archive" || err "download failed: $url"
curl -fsSL "$sha_url" -o "$tmp/$archive.sha256" || err "checksum download failed: $sha_url"
info "verifying checksum"
(
cd "$tmp"
if command -v sha256sum >/dev/null 2>&1; then
sha256sum -c "$archive.sha256" >/dev/null 2>&1 || err "checksum verification failed"
elif command -v shasum >/dev/null 2>&1; then
shasum -a 256 -c "$archive.sha256" >/dev/null 2>&1 || err "checksum verification failed"
else
err "no sha256 tool available (need sha256sum or shasum)"
fi
)
info "extracting"
tar -C "$tmp" -xzf "$tmp/$archive"
mkdir -p "$INSTALL_DIR"
mv "$tmp/binvim" "$INSTALL_DIR/binvim"
chmod +x "$INSTALL_DIR/binvim"
ln -sf "$INSTALL_DIR/binvim" "$INSTALL_DIR/bim"
# `binvim-install` ships alongside binvim from v0.4.5 onward. Older
# tarballs don't contain it — extract conditionally so this script keeps
# working when BINVIM_VERSION is pinned to an older release.
if [ -f "$tmp/binvim-install" ]; then
mv "$tmp/binvim-install" "$INSTALL_DIR/binvim-install"
chmod +x "$INSTALL_DIR/binvim-install"
info "installed binvim ${BINVIM_VERSION} → $INSTALL_DIR/binvim (also as 'bim') + $INSTALL_DIR/binvim-install"
else
info "installed binvim ${BINVIM_VERSION} → $INSTALL_DIR/binvim (also as 'bim')"
fi
case ":$PATH:" in
*":$INSTALL_DIR:"*) ;;
*)
printf '\n'
printf 'note: %s is not on your PATH.\n' "$INSTALL_DIR"
printf ' add this to your shell init (e.g. ~/.bashrc or ~/.zshrc):\n\n'
printf ' export PATH="%s:$PATH"\n\n' "$INSTALL_DIR"
;;
esac