Skip to content

Commit d7c687f

Browse files
authored
Add install.sh script (#15)
1 parent 41352f4 commit d7c687f

File tree

2 files changed

+185
-0
lines changed

2 files changed

+185
-0
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ A terminal-based music player for [SomaFM](https://somafm.com/) radio stations b
2828
brew install glebovdev/tap/somafm
2929
```
3030

31+
### Shell Script
32+
33+
```bash
34+
curl -sSL https://raw.githubusercontent.com/glebovdev/somafm-cli/master/install.sh | sh
35+
```
36+
3137
### Linux (manual)
3238

3339
Download from the [Releases page](https://github.com/glebovdev/somafm-cli/releases):

install.sh

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
#!/bin/sh
2+
# SomaFM CLI Installer
3+
# Usage: curl -sSL https://raw.githubusercontent.com/glebovdev/somafm-cli/master/install.sh | sh
4+
#
5+
# Options (via environment variables):
6+
# VERSION=v0.1.5 Install specific version (default: latest)
7+
# INSTALL_DIR=/path Custom install directory (default: /usr/local/bin)
8+
9+
set -e
10+
11+
REPO="glebovdev/somafm-cli"
12+
INSTALL_DIR="${INSTALL_DIR:-/usr/local/bin}"
13+
BINARY_NAME="somafm"
14+
15+
# Colors
16+
RED='\033[0;31m'
17+
GREEN='\033[0;32m'
18+
YELLOW='\033[1;33m'
19+
NC='\033[0m'
20+
21+
info() {
22+
printf "${GREEN}[INFO]${NC} %s\n" "$1"
23+
}
24+
25+
warn() {
26+
printf "${YELLOW}[WARN]${NC} %s\n" "$1"
27+
}
28+
29+
error() {
30+
printf "${RED}[ERROR]${NC} %s\n" "$1"
31+
exit 1
32+
}
33+
34+
# Detect OS
35+
detect_os() {
36+
case "$(uname -s)" in
37+
Linux*) echo "linux";;
38+
Darwin*) echo "darwin";;
39+
MINGW*|MSYS*|CYGWIN*) echo "windows";;
40+
*) error "Unsupported operating system: $(uname -s)";;
41+
esac
42+
}
43+
44+
# Detect architecture
45+
detect_arch() {
46+
case "$(uname -m)" in
47+
x86_64|amd64) echo "amd64";;
48+
arm64|aarch64) echo "arm64";;
49+
*) error "Unsupported architecture: $(uname -m)";;
50+
esac
51+
}
52+
53+
# Get latest version from GitHub
54+
get_latest_version() {
55+
curl -sSL "https://api.github.com/repos/${REPO}/releases/latest" | \
56+
grep '"tag_name":' | \
57+
sed -E 's/.*"([^"]+)".*/\1/'
58+
}
59+
60+
# Verify checksum
61+
verify_checksum() {
62+
CHECKSUM_URL="https://github.com/${REPO}/releases/download/${VERSION}/checksums.txt"
63+
64+
info "Verifying checksum..."
65+
66+
CHECKSUMS=$(curl -sSL "${CHECKSUM_URL}") || {
67+
warn "Could not download checksums, skipping verification"
68+
return 0
69+
}
70+
71+
EXPECTED=$(echo "${CHECKSUMS}" | grep "${FILENAME}" | awk '{print $1}')
72+
if [ -z "$EXPECTED" ]; then
73+
warn "Checksum not found for ${FILENAME}, skipping verification"
74+
return 0
75+
fi
76+
77+
if command -v sha256sum >/dev/null 2>&1; then
78+
ACTUAL=$(sha256sum "${FILENAME}" | awk '{print $1}')
79+
elif command -v shasum >/dev/null 2>&1; then
80+
ACTUAL=$(shasum -a 256 "${FILENAME}" | awk '{print $1}')
81+
else
82+
warn "No sha256 tool found, skipping verification"
83+
return 0
84+
fi
85+
86+
if [ "$EXPECTED" != "$ACTUAL" ]; then
87+
error "Checksum verification failed"
88+
fi
89+
90+
info "Checksum verified"
91+
}
92+
93+
# Download and install
94+
install() {
95+
OS=$(detect_os)
96+
ARCH=$(detect_arch)
97+
98+
info "Detected OS: ${OS}, Arch: ${ARCH}"
99+
100+
# Use VERSION env var or fetch latest
101+
if [ -z "$VERSION" ]; then
102+
VERSION=$(get_latest_version)
103+
if [ -z "$VERSION" ]; then
104+
error "Could not determine latest version"
105+
fi
106+
info "Latest version: ${VERSION}"
107+
else
108+
info "Installing version: ${VERSION}"
109+
fi
110+
111+
# Build download URL
112+
FILENAME="${BINARY_NAME}_${VERSION#v}_${OS}_${ARCH}.tar.gz"
113+
if [ "$OS" = "windows" ]; then
114+
FILENAME="${BINARY_NAME}_${VERSION#v}_${OS}_${ARCH}.zip"
115+
fi
116+
117+
DOWNLOAD_URL="https://github.com/${REPO}/releases/download/${VERSION}/${FILENAME}"
118+
119+
info "Downloading from: ${DOWNLOAD_URL}"
120+
121+
# Create temp directory
122+
TMP_DIR=$(mktemp -d)
123+
trap "rm -rf ${TMP_DIR}" EXIT
124+
125+
# Download
126+
curl -sSL "${DOWNLOAD_URL}" -o "${TMP_DIR}/${FILENAME}"
127+
128+
# Verify checksum
129+
cd "${TMP_DIR}"
130+
verify_checksum
131+
132+
# Extract
133+
if [ "$OS" = "windows" ]; then
134+
unzip -q "${FILENAME}"
135+
else
136+
tar -xzf "${FILENAME}"
137+
fi
138+
139+
# Install
140+
if [ -w "${INSTALL_DIR}" ]; then
141+
mv "${BINARY_NAME}" "${INSTALL_DIR}/${BINARY_NAME}"
142+
else
143+
info "Requesting sudo access to install to ${INSTALL_DIR}"
144+
sudo mv "${BINARY_NAME}" "${INSTALL_DIR}/${BINARY_NAME}"
145+
fi
146+
147+
chmod +x "${INSTALL_DIR}/${BINARY_NAME}"
148+
149+
info "Installed ${BINARY_NAME} to ${INSTALL_DIR}/${BINARY_NAME}"
150+
151+
# Verify installation
152+
if "${INSTALL_DIR}/${BINARY_NAME}" --version >/dev/null 2>&1; then
153+
info "Verified: $(${INSTALL_DIR}/${BINARY_NAME} --version | head -1)"
154+
else
155+
warn "Binary installed but verification failed"
156+
fi
157+
}
158+
159+
# Main
160+
main() {
161+
echo ""
162+
echo " SomaFM CLI Installer"
163+
echo ""
164+
165+
# Check for required tools
166+
command -v curl >/dev/null 2>&1 || error "curl is required but not installed"
167+
command -v tar >/dev/null 2>&1 || error "tar is required but not installed"
168+
169+
install
170+
171+
echo ""
172+
printf "${GREEN}Installation complete!${NC}\n"
173+
echo ""
174+
echo " Run 'somafm' to start listening"
175+
echo " Run 'somafm --help' for options"
176+
echo ""
177+
}
178+
179+
main

0 commit comments

Comments
 (0)