-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·128 lines (103 loc) · 3.29 KB
/
install.sh
File metadata and controls
executable file
·128 lines (103 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
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
#!/bin/sh
# Flashduty CLI installer
# Usage: curl -sSL https://raw.githubusercontent.com/flashcatcloud/flashduty-cli/main/install.sh | sh
set -e
REPO="flashcatcloud/flashduty-cli"
BINARY="flashduty-cli"
INSTALLED_NAME="flashduty"
INSTALL_DIR="${FLASHDUTY_INSTALL_DIR:-/usr/local/bin}"
# --- helper functions ---
fail() {
printf "Error: %s\n" "$1" >&2
exit 1
}
info() {
printf "[flashduty] %s\n" "$1"
}
need_cmd() {
if ! command -v "$1" > /dev/null 2>&1; then
fail "need '$1' (command not found)"
fi
}
# --- detect platform ---
detect_os() {
case "$(uname -s)" in
Linux*) echo "Linux" ;;
Darwin*) echo "Darwin" ;;
MINGW*|MSYS*|CYGWIN*) echo "Windows" ;;
*) fail "unsupported OS: $(uname -s)" ;;
esac
}
detect_arch() {
case "$(uname -m)" in
x86_64|amd64) echo "x86_64" ;;
aarch64|arm64) echo "arm64" ;;
*) fail "unsupported architecture: $(uname -m)" ;;
esac
}
# --- resolve version ---
resolve_version() {
if [ -n "${FLASHDUTY_VERSION}" ]; then
echo "${FLASHDUTY_VERSION}"
return
fi
need_cmd curl
# Use the GitHub API to get the latest release tag
version=$(curl -sL "https://api.github.com/repos/${REPO}/releases/latest" \
| grep '"tag_name"' \
| sed -E 's/.*"tag_name": *"([^"]+)".*/\1/')
if [ -z "${version}" ]; then
fail "could not determine latest version. Set FLASHDUTY_VERSION to install a specific version."
fi
echo "${version}"
}
# --- main ---
main() {
need_cmd uname
need_cmd tar
need_cmd curl
OS=$(detect_os)
ARCH=$(detect_arch)
VERSION=$(resolve_version)
if [ "${OS}" = "Windows" ]; then
EXT="zip"
need_cmd unzip
else
EXT="tar.gz"
fi
ARCHIVE="flashduty-cli_${OS}_${ARCH}.${EXT}"
URL="https://github.com/${REPO}/releases/download/${VERSION}/${ARCHIVE}"
info "Installing Flashduty CLI ${VERSION} (${OS}/${ARCH})"
info "Downloading ${URL}"
TMP_DIR=$(mktemp -d)
trap 'rm -rf "${TMP_DIR}"' EXIT
HTTP_CODE=$(curl -sL -H "Accept: application/octet-stream" -o "${TMP_DIR}/${ARCHIVE}" -w "%{http_code}" "${URL}")
if [ "${HTTP_CODE}" != "200" ]; then
fail "download failed (HTTP ${HTTP_CODE}). Check that ${VERSION} exists at https://github.com/${REPO}/releases"
fi
if [ "${EXT}" = "zip" ]; then
unzip -q "${TMP_DIR}/${ARCHIVE}" -d "${TMP_DIR}"
else
tar xzf "${TMP_DIR}/${ARCHIVE}" -C "${TMP_DIR}"
fi
if [ ! -f "${TMP_DIR}/${BINARY}" ]; then
fail "binary '${BINARY}' not found in archive"
fi
# Install (rename flashduty-cli -> flashduty for convenience)
if [ -w "${INSTALL_DIR}" ]; then
mv "${TMP_DIR}/${BINARY}" "${INSTALL_DIR}/${INSTALLED_NAME}"
else
info "Need elevated permissions to install to ${INSTALL_DIR}"
sudo mv "${TMP_DIR}/${BINARY}" "${INSTALL_DIR}/${INSTALLED_NAME}"
fi
chmod +x "${INSTALL_DIR}/${INSTALLED_NAME}"
info "Installed to ${INSTALL_DIR}/${INSTALLED_NAME}"
# Warn if install dir is not in PATH
case ":${PATH}:" in
*":${INSTALL_DIR}:"*) ;;
*) info "WARNING: ${INSTALL_DIR} is not in your PATH. Add it with:"
info " export PATH=\"${INSTALL_DIR}:\$PATH\"" ;;
esac
info "Run 'flashduty version' to verify"
}
main