Repository navigation
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·95 lines (82 loc) · 3.29 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·95 lines (82 loc) · 3.29 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
#!/bin/sh
# Install the vexor binary without npm or Node.js.
#
# curl -fsSL https://raw.githubusercontent.com/gauravgitgithub/vexor/main/install.sh | sh
# curl -fsSL .../install.sh | sh -s -- v0.13.2 # a specific release
#
# Downloads vexor-<target>.tar.gz and SHA256SUMS from the GitHub release,
# refuses to install unless the checksum matches, and installs to
# $VEXOR_INSTALL_DIR (default: ~/.local/bin). Never uses sudo.
#
# Environment:
# VEXOR_INSTALL_DIR where to put the binary
# VEXOR_DOWNLOAD_BASE alternative base URL (mirrors, tests); release
# files are fetched from "$VEXOR_DOWNLOAD_BASE/<file>"
set -eu
REPO="gauravgitgithub/vexor"
VERSION="${1:-latest}"
DEST="${VEXOR_INSTALL_DIR:-$HOME/.local/bin}"
say() { printf 'vexor install: %s\n' "$*" >&2; }
die() { say "error: $*"; exit 1; }
case "$(uname -s)" in
Linux) os=unknown-linux-musl ;;
Darwin) os=apple-darwin ;;
*) die "unsupported OS $(uname -s); supported: Linux, macOS" ;;
esac
case "$(uname -m)" in
x86_64 | amd64) arch=x86_64 ;;
aarch64 | arm64) arch=aarch64 ;;
*) die "unsupported CPU $(uname -m); supported: x86_64, arm64" ;;
esac
target="$arch-$os"
asset="vexor-$target.tar.gz"
if command -v curl >/dev/null 2>&1; then
fetch() { curl -fsSL --proto '=https,file' --retry 2 -o "$2" "$1"; }
elif command -v wget >/dev/null 2>&1; then
fetch() { wget -q -O "$2" "$1"; }
else
die "need curl or wget"
fi
# "latest" means the newest release, prereleases included (GitHub's own
# releases/latest skips prereleases, which all 0.x releases are).
if [ -z "${VEXOR_DOWNLOAD_BASE:-}" ] && [ "$VERSION" = latest ]; then
meta=$(mktemp)
fetch "https://api.github.com/repos/$REPO/releases?per_page=1" "$meta" ||
die "cannot look up the latest release; pass a version, e.g. sh -s -- v0.13.2"
VERSION=$(sed -n 's/.*"tag_name": *"\([^"]*\)".*/\1/p' "$meta" | head -n 1)
rm -f "$meta"
[ -n "$VERSION" ] || die "no releases found for $REPO"
fi
if [ -n "${VEXOR_DOWNLOAD_BASE:-}" ]; then
base="$VEXOR_DOWNLOAD_BASE"
else
base="https://github.com/$REPO/releases/download/$VERSION"
fi
if command -v sha256sum >/dev/null 2>&1; then
sha256() { sha256sum "$1" | cut -d' ' -f1; }
elif command -v shasum >/dev/null 2>&1; then
sha256() { shasum -a 256 "$1" | cut -d' ' -f1; }
else
die "need sha256sum or shasum to verify the download"
fi
tmp=$(mktemp -d)
trap 'rm -rf "$tmp"' EXIT
say "downloading $asset ($VERSION)"
fetch "$base/$asset" "$tmp/$asset" || die "download failed: $base/$asset"
fetch "$base/SHA256SUMS" "$tmp/SHA256SUMS" || die "download failed: $base/SHA256SUMS"
expected=$(awk -v f="$asset" '$2 == f || $2 == "*" f { print $1 }' "$tmp/SHA256SUMS")
[ -n "$expected" ] || die "$asset is not listed in SHA256SUMS"
actual=$(sha256 "$tmp/$asset")
[ "$expected" = "$actual" ] || die "checksum mismatch for $asset (expected $expected, got $actual); not installing"
say "checksum ok"
tar -xzf "$tmp/$asset" -C "$tmp" vexor || die "unexpected archive contents"
mkdir -p "$DEST"
# Replace atomically, so a running vexor keeps its old binary.
cp "$tmp/vexor" "$DEST/.vexor.new"
chmod 755 "$DEST/.vexor.new"
mv -f "$DEST/.vexor.new" "$DEST/vexor"
say "installed $("$DEST/vexor" --version) to $DEST/vexor"
case ":$PATH:" in
*":$DEST:"*) ;;
*) say "note: $DEST is not on your PATH; add it, or run $DEST/vexor" ;;
esac