-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·159 lines (124 loc) · 4.21 KB
/
install.sh
File metadata and controls
executable file
·159 lines (124 loc) · 4.21 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
#!/bin/bash
# install.sh — install recs binary from GitHub releases
#
# Usage:
# curl -fsSL https://raw.githubusercontent.com/benbernard/RecordStream/master/install.sh | bash
#
# Environment variables:
# INSTALL_DIR — custom install directory (default: /usr/local/bin or ~/.local/bin)
# VERSION — specific version to install (default: latest)
set -euo pipefail
REPO="benbernard/RecordStream"
BINARY_NAME="recs"
# ── Detect platform ──────────────────────────────────────────────
detect_platform() {
OS="$(uname -s | tr '[:upper:]' '[:lower:]')"
ARCH="$(uname -m)"
case "$OS" in
linux) OS="linux" ;;
darwin) OS="darwin" ;;
*)
echo "Error: Unsupported operating system: $OS" >&2
exit 1
;;
esac
case "$ARCH" in
x86_64|amd64) ARCH="x64" ;;
aarch64|arm64) ARCH="arm64" ;;
*)
echo "Error: Unsupported architecture: $ARCH" >&2
exit 1
;;
esac
PLATFORM="${OS}-${ARCH}"
}
# ── Determine install directory ──────────────────────────────────
determine_install_dir() {
if [ -n "${INSTALL_DIR:-}" ]; then
TARGET_DIR="$INSTALL_DIR"
elif [ -w /usr/local/bin ]; then
TARGET_DIR="/usr/local/bin"
else
TARGET_DIR="${HOME}/.local/bin"
mkdir -p "$TARGET_DIR"
fi
}
# ── Download helper ──────────────────────────────────────────────
download() {
url="$1"
output="$2"
if command -v curl >/dev/null 2>&1; then
curl -fsSL -o "$output" "$url"
elif command -v wget >/dev/null 2>&1; then
wget -qO "$output" "$url"
else
echo "Error: Neither curl nor wget found. Please install one of them." >&2
exit 1
fi
}
# ── Fetch JSON helper ────────────────────────────────────────────
fetch_json() {
url="$1"
if command -v curl >/dev/null 2>&1; then
curl -fsSL "$url"
elif command -v wget >/dev/null 2>&1; then
wget -qO- "$url"
else
echo "Error: Neither curl nor wget found." >&2
exit 1
fi
}
# ── Get latest version ───────────────────────────────────────────
get_latest_version() {
if [ -n "${VERSION:-}" ]; then
echo "$VERSION"
return
fi
RELEASES_URL="https://api.github.com/repos/${REPO}/releases/latest"
TAG=$(fetch_json "$RELEASES_URL" | grep '"tag_name"' | head -1 | sed 's/.*"tag_name"[[:space:]]*:[[:space:]]*"//' | sed 's/".*//')
if [ -z "$TAG" ]; then
echo "Error: Could not determine latest version." >&2
exit 1
fi
echo "$TAG"
}
# ── Main ─────────────────────────────────────────────────────────
main() {
echo "Installing recs..."
detect_platform
determine_install_dir
VERSION_TAG=$(get_latest_version)
VERSION_NUM="${VERSION_TAG#v}"
ASSET_NAME="${BINARY_NAME}-${PLATFORM}"
DOWNLOAD_URL="https://github.com/${REPO}/releases/download/${VERSION_TAG}/${ASSET_NAME}"
echo " Platform: ${PLATFORM}"
echo " Version: ${VERSION_TAG}"
echo " Directory: ${TARGET_DIR}"
TMPFILE=$(mktemp)
trap 'rm -f "$TMPFILE"' EXIT
echo " Downloading ${ASSET_NAME}..."
download "$DOWNLOAD_URL" "$TMPFILE"
chmod +x "$TMPFILE"
# Verify the binary runs
if ! "$TMPFILE" --version >/dev/null 2>&1; then
echo "Error: Downloaded binary failed to run. The release may not include a binary for ${PLATFORM}." >&2
exit 1
fi
# Install atomically via rename
mv "$TMPFILE" "${TARGET_DIR}/${BINARY_NAME}"
echo ""
echo " recs ${VERSION_NUM} installed to ${TARGET_DIR}/${BINARY_NAME}"
echo ""
# Check if install dir is in PATH
case ":${PATH}:" in
*":${TARGET_DIR}:"*) ;;
*)
echo " Note: ${TARGET_DIR} is not in your PATH."
echo " Add it with: export PATH=\"${TARGET_DIR}:\$PATH\""
echo ""
;;
esac
echo " Get started: recs help"
echo " Examples: recs examples"
}
main