-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·138 lines (120 loc) · 5.09 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·138 lines (120 loc) · 5.09 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
#!/bin/sh
# qvr installer for Linux and macOS (also works under WSL / Git Bash on Windows).
#
# curl -fsSL https://github.com/astra-sh/qvr/raw/main/install.sh | sh
#
# Downloads the prebuilt release binary (UI embedded) for your OS/arch from
# GitHub Releases, verifies its checksum, and installs it to a directory on PATH.
#
# Env overrides:
# QVR_VERSION pin a version, e.g. v0.12.0 (default: latest release)
# QVR_INSTALL_DIR install location (default: /usr/local/bin, ~/.local/bin if unwritable)
set -eu
REPO="astra-sh/qvr"
BINARY="qvr"
info() { printf '\033[1;34m==>\033[0m %s\n' "$1"; }
err() { printf '\033[1;31merror:\033[0m %s\n' "$1" >&2; exit 1; }
# --- prerequisites --------------------------------------------------------
if command -v curl >/dev/null 2>&1; then
dl() { curl -fsSL "$1"; }
dlo() { curl -fsSL "$1" -o "$2"; }
elif command -v wget >/dev/null 2>&1; then
dl() { wget -qO- "$1"; }
dlo() { wget -qO "$2" "$1"; }
else
err "need curl or wget"
fi
# --- detect platform ------------------------------------------------------
OS="$(uname -s)"
case "$OS" in
Linux) OS="Linux" ;;
Darwin) OS="Darwin" ;;
*) err "unsupported OS '$OS' — use install.ps1 on native Windows" ;;
esac
ARCH="$(uname -m)"
case "$ARCH" in
x86_64 | amd64) ARCH="x86_64" ;;
arm64 | aarch64) ARCH="arm64" ;;
*) err "unsupported architecture '$ARCH'" ;;
esac
# --- record any prior install (for staleness visibility) ------------------
# Capture the version and path of a qvr already on PATH, so we can report the
# before/after and warn if a different copy ends up shadowing the new one.
PRIOR_BIN="$(command -v "$BINARY" 2>/dev/null || true)"
PRIOR_VER=""
if [ -n "$PRIOR_BIN" ]; then
PRIOR_VER="$("$PRIOR_BIN" version 2>/dev/null | head -n1 | awk '{print $2}' || true)"
fi
# --- resolve version ------------------------------------------------------
VERSION="${QVR_VERSION:-}"
if [ -z "$VERSION" ]; then
info "Resolving latest release..."
VERSION="$(dl "https://api.github.com/repos/${REPO}/releases/latest" \
| grep '"tag_name":' | head -n1 | cut -d'"' -f4)"
[ -n "$VERSION" ] || err "could not determine latest version (set QVR_VERSION)"
fi
if [ -n "$PRIOR_VER" ]; then
if [ "$PRIOR_VER" = "$VERSION" ]; then
info "Already on ${VERSION} (${PRIOR_BIN}) — reinstalling cleanly"
else
info "Upgrading ${PRIOR_VER} -> ${VERSION} (current: ${PRIOR_BIN})"
fi
fi
ASSET="${BINARY}_${OS}_${ARCH}.tar.gz"
BASE="https://github.com/${REPO}/releases/download/${VERSION}"
info "Installing ${BINARY} ${VERSION} (${OS}/${ARCH})"
# --- download + verify ----------------------------------------------------
TMP="$(mktemp -d)"
trap 'rm -rf "$TMP"' EXIT
dlo "${BASE}/${ASSET}" "${TMP}/${ASSET}" || err "download failed: ${BASE}/${ASSET}"
dlo "${BASE}/checksums.txt" "${TMP}/checksums.txt" || err "checksums.txt unavailable"
if command -v sha256sum >/dev/null 2>&1; then
SUM="$(sha256sum "${TMP}/${ASSET}" | awk '{print $1}')"
elif command -v shasum >/dev/null 2>&1; then
SUM="$(shasum -a 256 "${TMP}/${ASSET}" | awk '{print $1}')"
else
err "need sha256sum or shasum for checksum verification"
fi
grep -q "$SUM $ASSET" "${TMP}/checksums.txt" \
|| err "checksum mismatch for ${ASSET}"
info "Checksum verified"
tar -xzf "${TMP}/${ASSET}" -C "$TMP"
[ -f "${TMP}/${BINARY}" ] || err "archive did not contain ${BINARY}"
chmod +x "${TMP}/${BINARY}"
# --- install --------------------------------------------------------------
DIR="${QVR_INSTALL_DIR:-/usr/local/bin}"
if [ ! -d "$DIR" ] || [ ! -w "$DIR" ]; then
if [ -w "${DIR%/*}" ] 2>/dev/null; then
mkdir -p "$DIR"
else
DIR="${HOME}/.local/bin"
mkdir -p "$DIR"
fi
fi
# Atomic replace via temp file + rename (a plain overwrite of a running binary
# corrupts its code-signing vnode on macOS).
TMP_BIN="${DIR}/.${BINARY}.tmp.$$"
if mv "${TMP}/${BINARY}" "$TMP_BIN" 2>/dev/null && mv -f "$TMP_BIN" "${DIR}/${BINARY}" 2>/dev/null; then
:
else
info "Elevating to write ${DIR} (sudo)"
sudo mv "${TMP}/${BINARY}" "$TMP_BIN" && sudo mv -f "$TMP_BIN" "${DIR}/${BINARY}"
fi
info "Installed to ${DIR}/${BINARY}"
case ":${PATH}:" in
*":${DIR}:"*) ;;
*) printf '\033[1;33mnote:\033[0m %s is not on your PATH — add it:\n export PATH="%s:$PATH"\n' "$DIR" "$DIR" ;;
esac
# Zero-staleness check: confirm the qvr that PATH actually resolves is the one we
# just wrote. If an older copy sits earlier on PATH it will shadow this install —
# the classic "I upgraded but qvr still reports the old version" trap.
RESOLVED="$(command -v "$BINARY" 2>/dev/null || true)"
if [ -n "$RESOLVED" ] && [ "$RESOLVED" != "${DIR}/${BINARY}" ]; then
printf '\033[1;33mwarning:\033[0m a different %s is earlier on PATH and will shadow this install:\n' "$BINARY"
printf ' shadowing : %s (%s)\n' "$RESOLVED" "$("$RESOLVED" version 2>/dev/null | head -n1 | awk '{print $2}' || echo '?')"
printf ' installed : %s (%s)\n' "${DIR}/${BINARY}" "$VERSION"
printf 'Remove the stale copy or put %s earlier on PATH.\n' "$DIR"
fi
# Report what is now in effect (the resolved binary, not just the freshly written
# one) so the user sees the real, post-install version.
"${RESOLVED:-${DIR}/${BINARY}}" version || true