-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·177 lines (151 loc) · 5.5 KB
/
install.sh
File metadata and controls
executable file
·177 lines (151 loc) · 5.5 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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#!/usr/bin/env bash
# fuseraft CLI installer — Linux and macOS
#
# Usage:
# curl -fsSL https://raw.githubusercontent.com/fuseraft/fuseraft-cli/main/install.sh | bash
# bash install.sh [--system] # install to /usr/local/bin instead of ~/.local/bin
set -euo pipefail
REPO="fuseraft/fuseraft-cli"
BINARY="fuseraft"
###############################################################################
# Flags
###############################################################################
SYSTEM_INSTALL=false
for arg in "$@"; do
case "$arg" in
--system) SYSTEM_INSTALL=true ;;
*) echo "Unknown argument: $arg" >&2; exit 1 ;;
esac
done
if $SYSTEM_INSTALL; then
INSTALL_DIR="/usr/local/bin"
else
INSTALL_DIR="${HOME}/.local/bin"
fi
###############################################################################
# Dependency checks
###############################################################################
if ! command -v tar >/dev/null 2>&1; then
echo "ERROR: tar is required." >&2
exit 1
fi
###############################################################################
# Platform detection
###############################################################################
OS="$(uname -s)"
ARCH="$(uname -m)"
case "$OS" in
Linux*) OS_TAG="linux" ;;
Darwin*) OS_TAG="osx" ;;
*)
echo "ERROR: Unsupported OS: $OS" >&2
echo " Supported: Linux, macOS (Darwin)" >&2
exit 1
;;
esac
case "$ARCH" in
x86_64) ARCH_TAG="x64" ;;
aarch64 | arm64) ARCH_TAG="arm64" ;;
*)
echo "ERROR: Unsupported architecture: $ARCH" >&2
echo " Supported: x86_64, aarch64/arm64" >&2
exit 1
;;
esac
RID="${OS_TAG}-${ARCH_TAG}"
###############################################################################
# Downloader — array avoids command-string quoting pitfalls
###############################################################################
if command -v curl >/dev/null 2>&1; then
FETCH_CMD=(curl -fsSL --retry 3 --retry-delay 1 --retry-connrefused)
elif command -v wget >/dev/null 2>&1; then
FETCH_CMD=(wget -qO-)
else
echo "ERROR: curl or wget is required." >&2
exit 1
fi
###############################################################################
# Resolve latest release
###############################################################################
echo "Fetching latest release from github.com/${REPO}..."
API_URL="https://api.github.com/repos/${REPO}/releases/latest"
RELEASE_JSON="$("${FETCH_CMD[@]}" "$API_URL")"
TAG="$(printf '%s\n' "$RELEASE_JSON" | grep '"tag_name"' | head -n1 | \
sed -E 's/.*"tag_name"[[:space:]]*:[[:space:]]*"([^"]+)".*/\1/')"
if [[ -z "$TAG" ]]; then
echo "ERROR: Could not determine the latest release tag." >&2
echo " Check https://github.com/${REPO}/releases" >&2
exit 1
fi
VERSION="${TAG#v}"
ARCHIVE="fuseraft-${VERSION}-${RID}.tar.gz"
# Validate the expected asset exists in the release metadata
if ! printf '%s\n' "$RELEASE_JSON" | grep -qF "\"${ARCHIVE}\""; then
echo "ERROR: Release asset '${ARCHIVE}' not found in release ${TAG}." >&2
exit 1
fi
DOWNLOAD_URL="https://github.com/${REPO}/releases/download/${TAG}/${ARCHIVE}"
# UX: show current version when updating
if command -v "$BINARY" >/dev/null 2>&1; then
CURRENT_VERSION="$("$BINARY" --version 2>/dev/null || true)"
echo "Updating${CURRENT_VERSION:+ from ${CURRENT_VERSION}} to fuseraft ${VERSION} (${RID})..."
else
echo "Installing fuseraft ${VERSION} (${RID})..."
fi
###############################################################################
# Download and extract
###############################################################################
TMP_DIR="$(mktemp -d 2>/dev/null || mktemp -d -t fuseraft)"
trap 'rm -rf "$TMP_DIR"' EXIT
echo "Downloading ${ARCHIVE}..."
"${FETCH_CMD[@]}" "$DOWNLOAD_URL" > "${TMP_DIR}/${ARCHIVE}"
echo "Extracting..."
tar -xzf "${TMP_DIR}/${ARCHIVE}" -C "$TMP_DIR"
# Locate the binary regardless of archive folder layout
BIN_PATH="$(find "$TMP_DIR" -type f -name "$BINARY" | head -n 1)"
if [[ -z "$BIN_PATH" ]]; then
echo "ERROR: ${BINARY} not found in archive. The release may be malformed." >&2
exit 1
fi
###############################################################################
# Atomic install: write .new then move into place
###############################################################################
TMP_TARGET="${INSTALL_DIR}/${BINARY}.new"
if $SYSTEM_INSTALL; then
SUDO=""
if [[ "$(id -u)" -ne 0 ]]; then
if command -v sudo >/dev/null 2>&1; then
SUDO="sudo"
else
echo "ERROR: --system install requires root or sudo." >&2
exit 1
fi
fi
$SUDO mkdir -p "$INSTALL_DIR"
$SUDO install -m 755 "$BIN_PATH" "$TMP_TARGET"
$SUDO mv -f "$TMP_TARGET" "${INSTALL_DIR}/${BINARY}"
else
mkdir -p "$INSTALL_DIR"
install -m 755 "$BIN_PATH" "$TMP_TARGET"
mv -f "$TMP_TARGET" "${INSTALL_DIR}/${BINARY}"
fi
echo ""
echo " fuseraft ${VERSION} installed to ${INSTALL_DIR}/${BINARY}"
###############################################################################
# PATH hint — case avoids regex metacharacter false positives
###############################################################################
case ":${PATH}:" in
*":${INSTALL_DIR}:"*)
;;
*)
SHELL_NAME="$(basename "${SHELL:-sh}")"
echo ""
echo " NOTE: ${INSTALL_DIR} is not in your PATH."
echo " Add the following line to your ~/.${SHELL_NAME}rc (or equivalent):"
echo ""
echo " export PATH=\"\$PATH:${INSTALL_DIR}\""
echo ""
;;
esac
echo " Run 'fuseraft --version' to verify the installation."
echo ""