-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·61 lines (47 loc) · 1.72 KB
/
install.sh
File metadata and controls
executable file
·61 lines (47 loc) · 1.72 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
#!/bin/sh
set -eu
# hlgo installer — downloads the latest release binary from GitHub.
# Usage:
# curl -sSfL https://raw.githubusercontent.com/timbrinded/hlgo/main/install.sh | sh
#
# Environment variables:
# HLGO_INSTALL_DIR — override install directory (default: ~/.local/bin)
REPO="timbrinded/hlgo"
INSTALL_DIR="${HLGO_INSTALL_DIR:-$HOME/.local/bin}"
fail() { printf 'Error: %s\n' "$1" >&2; exit 1; }
# Detect OS
case "$(uname -s)" in
Linux*) OS="linux" ;;
Darwin*) OS="darwin" ;;
*) fail "unsupported OS: $(uname -s)" ;;
esac
# Detect architecture
case "$(uname -m)" in
x86_64|amd64) ARCH="amd64" ;;
aarch64|arm64) ARCH="arm64" ;;
*) fail "unsupported architecture: $(uname -m)" ;;
esac
# Fetch latest release tag
printf 'Fetching latest release...\n'
TAG=$(curl -sSf "https://api.github.com/repos/${REPO}/releases/latest" \
| grep '"tag_name"' | head -1 | cut -d '"' -f 4)
[ -z "$TAG" ] && fail "could not determine latest release tag"
VERSION="${TAG#v}"
ARCHIVE="hlgo_${VERSION}_${OS}_${ARCH}.tar.gz"
URL="https://github.com/${REPO}/releases/download/${TAG}/${ARCHIVE}"
printf 'Installing hlgo %s (%s/%s)...\n' "$TAG" "$OS" "$ARCH"
# Download and extract
TMPDIR=$(mktemp -d)
trap 'rm -rf "$TMPDIR"' EXIT
curl -sSfL -o "${TMPDIR}/${ARCHIVE}" "$URL" || fail "download failed: $URL"
tar -xzf "${TMPDIR}/${ARCHIVE}" -C "$TMPDIR"
# Install binary
mkdir -p "$INSTALL_DIR"
mv "${TMPDIR}/hlgo" "${INSTALL_DIR}/hlgo"
chmod +x "${INSTALL_DIR}/hlgo"
printf 'Installed hlgo %s to %s/hlgo\n' "$TAG" "$INSTALL_DIR"
# Check PATH
case ":$PATH:" in
*":${INSTALL_DIR}:"*) ;;
*) printf '\nNote: %s is not in your PATH. Add it with:\n export PATH="%s:$PATH"\n' "$INSTALL_DIR" "$INSTALL_DIR" ;;
esac