Skip to content

Commit a3b5815

Browse files
committed
feat: add shell installer script
curl -sSL https://raw.githubusercontent.com/flashcatcloud/flashduty-cli/main/install.sh | sh - Auto-detects OS (Linux/macOS/Windows) and architecture (x86_64/arm64) - Auto-resolves latest version via GitHub API, or set FLASHDUTY_VERSION - Configurable install dir via FLASHDUTY_INSTALL_DIR (default /usr/local/bin) - Installs binary as 'flashduty' for convenience - Handles sudo automatically when install dir is not writable
1 parent b793b91 commit a3b5815

1 file changed

Lines changed: 120 additions & 0 deletions

File tree

install.sh

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
#!/bin/sh
2+
# Flashduty CLI installer
3+
# Usage: curl -sSL https://raw.githubusercontent.com/flashcatcloud/flashduty-cli/main/install.sh | sh
4+
set -e
5+
6+
REPO="flashcatcloud/flashduty-cli"
7+
BINARY="flashduty-cli"
8+
INSTALLED_NAME="flashduty"
9+
INSTALL_DIR="${FLASHDUTY_INSTALL_DIR:-/usr/local/bin}"
10+
11+
# --- helper functions ---
12+
13+
fail() {
14+
printf "Error: %s\n" "$1" >&2
15+
exit 1
16+
}
17+
18+
info() {
19+
printf "[flashduty] %s\n" "$1"
20+
}
21+
22+
need_cmd() {
23+
if ! command -v "$1" > /dev/null 2>&1; then
24+
fail "need '$1' (command not found)"
25+
fi
26+
}
27+
28+
# --- detect platform ---
29+
30+
detect_os() {
31+
case "$(uname -s)" in
32+
Linux*) echo "Linux" ;;
33+
Darwin*) echo "Darwin" ;;
34+
MINGW*|MSYS*|CYGWIN*) echo "Windows" ;;
35+
*) fail "unsupported OS: $(uname -s)" ;;
36+
esac
37+
}
38+
39+
detect_arch() {
40+
case "$(uname -m)" in
41+
x86_64|amd64) echo "x86_64" ;;
42+
aarch64|arm64) echo "arm64" ;;
43+
*) fail "unsupported architecture: $(uname -m)" ;;
44+
esac
45+
}
46+
47+
# --- resolve version ---
48+
49+
resolve_version() {
50+
if [ -n "${FLASHDUTY_VERSION}" ]; then
51+
echo "${FLASHDUTY_VERSION}"
52+
return
53+
fi
54+
need_cmd curl
55+
# Use the GitHub API to get the latest release tag
56+
version=$(curl -sL "https://api.github.com/repos/${REPO}/releases/latest" \
57+
| grep '"tag_name"' \
58+
| sed -E 's/.*"tag_name": *"([^"]+)".*/\1/')
59+
if [ -z "${version}" ]; then
60+
fail "could not determine latest version. Set FLASHDUTY_VERSION to install a specific version."
61+
fi
62+
echo "${version}"
63+
}
64+
65+
# --- main ---
66+
67+
main() {
68+
need_cmd uname
69+
need_cmd tar
70+
need_cmd curl
71+
72+
OS=$(detect_os)
73+
ARCH=$(detect_arch)
74+
VERSION=$(resolve_version)
75+
76+
if [ "${OS}" = "Windows" ]; then
77+
EXT="zip"
78+
need_cmd unzip
79+
else
80+
EXT="tar.gz"
81+
fi
82+
83+
ARCHIVE="flashduty-cli_${OS}_${ARCH}.${EXT}"
84+
URL="https://github.com/${REPO}/releases/download/${VERSION}/${ARCHIVE}"
85+
86+
info "Installing Flashduty CLI ${VERSION} (${OS}/${ARCH})"
87+
info "Downloading ${URL}"
88+
89+
TMP_DIR=$(mktemp -d)
90+
trap 'rm -rf "${TMP_DIR}"' EXIT
91+
92+
HTTP_CODE=$(curl -sL -H "Accept: application/octet-stream" -o "${TMP_DIR}/${ARCHIVE}" -w "%{http_code}" "${URL}")
93+
if [ "${HTTP_CODE}" != "200" ]; then
94+
fail "download failed (HTTP ${HTTP_CODE}). Check that ${VERSION} exists at https://github.com/${REPO}/releases"
95+
fi
96+
97+
if [ "${EXT}" = "zip" ]; then
98+
unzip -q "${TMP_DIR}/${ARCHIVE}" -d "${TMP_DIR}"
99+
else
100+
tar xzf "${TMP_DIR}/${ARCHIVE}" -C "${TMP_DIR}"
101+
fi
102+
103+
if [ ! -f "${TMP_DIR}/${BINARY}" ]; then
104+
fail "binary '${BINARY}' not found in archive"
105+
fi
106+
107+
# Install (rename flashduty-cli -> flashduty for convenience)
108+
if [ -w "${INSTALL_DIR}" ]; then
109+
mv "${TMP_DIR}/${BINARY}" "${INSTALL_DIR}/${INSTALLED_NAME}"
110+
else
111+
info "Need elevated permissions to install to ${INSTALL_DIR}"
112+
sudo mv "${TMP_DIR}/${BINARY}" "${INSTALL_DIR}/${INSTALLED_NAME}"
113+
fi
114+
chmod +x "${INSTALL_DIR}/${INSTALLED_NAME}"
115+
116+
info "Installed to ${INSTALL_DIR}/${INSTALLED_NAME}"
117+
info "Run 'flashduty version' to verify"
118+
}
119+
120+
main

0 commit comments

Comments
 (0)