-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·224 lines (195 loc) · 6.34 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·224 lines (195 loc) · 6.34 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
#!/usr/bin/env bash
# Install javinfo CLI from GitHub Releases.
#
# Usage:
# curl -fsSL https://javinfo.dev/install.sh | bash
# curl -fsSL https://raw.githubusercontent.com/javinfo/cli/main/install.sh | bash
#
# Options (env):
# VERSION=0.1.0 Pin a release (default: latest)
# INSTALL_DIR=~/.local/bin
# REPO=javinfo/cli GitHub owner/repo
# NO_VERIFY=1 Skip sha256 check (not recommended)
#
# Requires: curl or wget, tar, and sha256sum / shasum / openssl.
set -euo pipefail
REPO="${REPO:-javinfo/cli}"
INSTALL_DIR="${INSTALL_DIR:-${HOME}/.local/bin}"
VERSION="${VERSION:-}"
NO_VERIFY="${NO_VERIFY:-0}"
GITHUB_BASE="https://github.com/${REPO}"
TMPDIR_ROOT="${TMPDIR:-/tmp}"
info() { printf '==> %s\n' "$*"; }
warn() { printf 'warning: %s\n' "$*" >&2; }
die() { printf 'error: %s\n' "$*" >&2; exit 1; }
need_cmd() {
command -v "$1" >/dev/null 2>&1 || die "missing required command: $1"
}
download() {
# download <url> <dest>
local url="$1" dest="$2"
if command -v curl >/dev/null 2>&1; then
curl -fsSL --proto '=https' --tlsv1.2 -o "$dest" "$url"
elif command -v wget >/dev/null 2>&1; then
wget -qO "$dest" "$url"
else
die "need curl or wget to download"
fi
}
sha256_file() {
local file="$1"
if command -v sha256sum >/dev/null 2>&1; then
sha256sum "$file" | awk '{print $1}'
elif command -v shasum >/dev/null 2>&1; then
shasum -a 256 "$file" | awk '{print $1}'
elif command -v openssl >/dev/null 2>&1; then
openssl dgst -sha256 "$file" | awk '{print $NF}'
else
die "need sha256sum, shasum, or openssl to verify downloads"
fi
}
detect_target() {
local os arch
os="$(uname -s | tr '[:upper:]' '[:lower:]')"
arch="$(uname -m)"
case "$os" in
linux) os="linux" ;;
darwin) os="darwin" ;;
msys*|mingw*|cygwin*|windows*)
die "Windows is not supported yet (serve control uses Unix sockets). Build from source on WSL/Linux, or wait for a future release."
;;
*)
die "unsupported OS: $(uname -s). Supported: Linux, macOS (Apple Silicon)."
;;
esac
case "$arch" in
x86_64|amd64) arch="x86_64" ;;
aarch64|arm64) arch="aarch64" ;;
*)
die "unsupported architecture: $(uname -m). Supported: x86_64, aarch64/arm64."
;;
esac
case "${os}-${arch}" in
linux-x86_64) echo "x86_64-unknown-linux-gnu" ;;
linux-aarch64) echo "aarch64-unknown-linux-gnu" ;;
darwin-aarch64) echo "aarch64-apple-darwin" ;;
darwin-x86_64)
die "no prebuilt binary for Intel macOS (GitHub free Intel runners retired). Install from source: cargo install --git https://github.com/${REPO}.git"
;;
*)
die "no prebuilt binary for ${os}/${arch}"
;;
esac
}
resolve_version() {
# Prefer explicit VERSION=…; otherwise latest via sha256sums redirect.
if [ -n "$VERSION" ]; then
# Strip optional leading v
VERSION="${VERSION#v}"
echo "$VERSION"
return
fi
local sums sums_url
sums="$(mktemp "${TMPDIR_ROOT}/javinfo-sums.XXXXXX")"
sums_url="${GITHUB_BASE}/releases/latest/download/sha256sums.txt"
download "$sums_url" "$sums" || {
rm -f "$sums"
die "could not fetch latest release metadata from ${sums_url}"
}
# Asset names: javinfo-<version>-<rust-target>.tar.gz
# Targets contain hyphens, so strip a known target suffix (do not greedy-match version).
local first name version
first="$(awk '/javinfo-.*\.tar\.gz$/ {print $2; exit}' "$sums")"
rm -f "$sums"
[ -n "$first" ] || die "could not parse version from sha256sums.txt"
name="${first%.tar.gz}"
name="${name#javinfo-}"
version=""
# Longest targets first (order matters for prefix collisions).
for t in \
aarch64-unknown-linux-gnu \
x86_64-unknown-linux-gnu \
aarch64-apple-darwin
do
case "$name" in
*-"$t")
version="${name%-"$t"}"
break
;;
esac
done
[ -n "$version" ] || die "unexpected asset name in sha256sums.txt: $first"
echo "$version"
}
main() {
need_cmd tar
need_cmd uname
need_cmd mktemp
need_cmd mkdir
need_cmd chmod
need_cmd awk
if ! command -v curl >/dev/null 2>&1 && ! command -v wget >/dev/null 2>&1; then
die "need curl or wget to download"
fi
local target version tag archive sums_url archive_url
target="$(detect_target)"
version="$(resolve_version)"
tag="v${version}"
archive="javinfo-${version}-${target}.tar.gz"
sums_url="${GITHUB_BASE}/releases/download/${tag}/sha256sums.txt"
archive_url="${GITHUB_BASE}/releases/download/${tag}/${archive}"
info "installing javinfo ${version} (${target})"
info "destination: ${INSTALL_DIR}/javinfo"
local work
work="$(mktemp -d "${TMPDIR_ROOT}/javinfo-install.XXXXXX")"
# shellcheck disable=SC2064
trap "rm -rf '${work}'" EXIT
info "downloading ${archive}"
download "$archive_url" "${work}/${archive}" || die "download failed: ${archive_url}"
if [ "$NO_VERIFY" = "1" ]; then
warn "skipping checksum verification (NO_VERIFY=1)"
else
info "verifying sha256"
download "$sums_url" "${work}/sha256sums.txt" || die "could not download sha256sums.txt"
local expected actual line
line="$(awk -v f="$archive" '$2 == f {print $1; exit}' "${work}/sha256sums.txt")"
[ -n "$line" ] || die "no checksum entry for ${archive} in sha256sums.txt"
expected="$line"
actual="$(sha256_file "${work}/${archive}")"
if [ "$expected" != "$actual" ]; then
die "checksum mismatch for ${archive}
expected: ${expected}
got: ${actual}"
fi
fi
info "extracting"
tar -xzf "${work}/${archive}" -C "$work"
[ -f "${work}/javinfo" ] || die "archive did not contain javinfo binary"
mkdir -p "$INSTALL_DIR"
# Atomic-ish replace
mv -f "${work}/javinfo" "${INSTALL_DIR}/javinfo"
chmod 755 "${INSTALL_DIR}/javinfo"
info "installed ${INSTALL_DIR}/javinfo"
if "${INSTALL_DIR}/javinfo" --version 2>/dev/null; then
:
else
warn "binary installed but --version failed (wrong arch or missing libs?)"
fi
case ":${PATH}:" in
*":${INSTALL_DIR}:"*) ;;
*)
warn "${INSTALL_DIR} is not on your PATH"
printf '\nAdd it with:\n export PATH="%s:$PATH"\n\n' "$INSTALL_DIR"
printf 'Persist in your shell rc, e.g. ~/.bashrc or ~/.zshrc.\n'
;;
esac
cat <<EOF
Next:
1. Sign up at https://app.javinfo.dev if you haven't yet (get an API key).
2. javinfo login
3. javinfo movie EBOD-391
4. javinfo --help
Docs: https://docs.javinfo.dev
EOF
}
main "$@"