Repository navigation
Expand file tree
/
Copy pathinstall.sh
More file actions
195 lines (171 loc) · 5.73 KB
/
Copy pathinstall.sh
File metadata and controls
195 lines (171 loc) · 5.73 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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#!/usr/bin/env sh
# FocusFlow Universal POSIX Installer (Linux & macOS amd64/arm64)
# Usage:
# curl -fsSL https://raw.githubusercontent.com/aloneangel45/FocusFlow/main/install.sh | sh
# Optional environment variables:
# FOCUSFLOW_VERSION Release tag to install (e.g. "v2.3.1" or "latest", default: "latest")
# FOCUSFLOW_INSTALL_DIR Target directory for the focusflow binary
# FOCUSFLOW_REPO GitHub owner/repo (default: "aloneangel45/FocusFlow")
# FOCUSFLOW_BASE_URL Override release download base URL (for mirrors/testing)
set -eu
REPO="${FOCUSFLOW_REPO:-aloneangel45/FocusFlow}"
VERSION="${FOCUSFLOW_VERSION:-latest}"
log_info() {
printf '[INFO] %s\n' "$*"
}
log_ok() {
printf '[OK] %s\n' "$*"
}
log_err() {
printf '[ERR] %s\n' "$*" >&2
}
detect_os() {
raw_os="$(uname -s 2>/dev/null || echo unknown)"
case "$raw_os" in
Linux|linux)
printf 'linux'
;;
Darwin|darwin)
printf 'darwin'
;;
*)
log_err "Unsupported operating system: $raw_os (expected Linux or macOS)."
exit 1
;;
esac
}
detect_arch() {
raw_arch="$(uname -m 2>/dev/null || echo unknown)"
case "$raw_arch" in
x86_64|amd64)
printf 'amd64'
;;
aarch64|arm64)
printf 'arm64'
;;
*)
log_err "Unsupported CPU architecture: $raw_arch (expected amd64/x86_64 or arm64/aarch64)."
exit 1
;;
esac
}
download_file() {
src_url="$1"
dest_path="$2"
if command -v curl >/dev/null 2>&1; then
curl -fsSL "$src_url" -o "$dest_path"
elif command -v wget >/dev/null 2>&1; then
wget -qO "$dest_path" "$src_url"
else
log_err "Neither 'curl' nor 'wget' was found. Install curl or wget and retry."
exit 1
fi
}
compute_sha256() {
target_file="$1"
if command -v sha256sum >/dev/null 2>&1; then
sha256sum "$target_file" | awk '{print tolower($1)}'
elif command -v shasum >/dev/null 2>&1; then
shasum -a 256 "$target_file" | awk '{print tolower($1)}'
elif command -v openssl >/dev/null 2>&1; then
openssl dgst -sha256 "$target_file" | awk '{print tolower($NF)}'
else
log_err "No SHA-256 utility found (requires sha256sum, shasum, or openssl)."
exit 1
fi
}
resolve_base_url() {
if [ -n "${FOCUSFLOW_BASE_URL:-}" ]; then
printf '%s' "${FOCUSFLOW_BASE_URL%/}"
return
fi
trimmed_ver="$(printf '%s' "$VERSION" | tr -d '[:space:]')"
lower_ver="$(printf '%s' "$trimmed_ver" | tr '[:upper:]' '[:lower:]')"
if [ -z "$trimmed_ver" ] || [ "$lower_ver" = "latest" ]; then
printf 'https://github.com/%s/releases/latest/download' "$REPO"
else
clean_ver="${trimmed_ver#[vV]}"
printf 'https://github.com/%s/releases/download/v%s' "$REPO" "$clean_ver"
fi
}
resolve_install_dir() {
if [ -n "${FOCUSFLOW_INSTALL_DIR:-}" ]; then
printf '%s' "$FOCUSFLOW_INSTALL_DIR"
return
fi
if [ "$(id -u)" -eq 0 ] || [ -w "/usr/local/bin" ]; then
printf '/usr/local/bin'
else
printf '%s/.local/bin' "$HOME"
fi
}
main() {
OS_NAME="$(detect_os)"
ARCH_NAME="$(detect_arch)"
BIN_INNER="focusflow-${OS_NAME}-${ARCH_NAME}"
ARCHIVE_NAME="${BIN_INNER}.tar.gz"
BASE_URL="$(resolve_base_url)"
INSTALL_DIR="$(resolve_install_dir)"
TMP_DIR="$(mktemp -d 2>/dev/null || mktemp -d -t focusflow-install)"
trap 'rm -rf "$TMP_DIR"' EXIT INT TERM
ARCHIVE_PATH="${TMP_DIR}/${ARCHIVE_NAME}"
CHECKSUMS_PATH="${TMP_DIR}/checksums.txt"
log_info "Detected platform: ${OS_NAME}/${ARCH_NAME}"
log_info "Downloading ${ARCHIVE_NAME} from ${BASE_URL}..."
download_file "${BASE_URL}/${ARCHIVE_NAME}" "$ARCHIVE_PATH"
log_info "Downloading checksums.txt for mandatory SHA-256 verification..."
download_file "${BASE_URL}/checksums.txt" "$CHECKSUMS_PATH"
EXPECTED_HASH="$(awk -v asset="$ARCHIVE_NAME" '
{
sub(/^\357\273\277/, "", $0)
sub(/\r$/, "", $0)
}
NF >= 2 {
fname = $2
sub(/^\*/, "", fname)
if (fname == asset) {
hash = tolower($1)
if (hash ~ /^[0-9a-f]+$/ && length(hash) == 64) {
print hash
exit
}
}
}
' "$CHECKSUMS_PATH")"
if [ -z "$EXPECTED_HASH" ] || [ "${#EXPECTED_HASH}" -ne 64 ]; then
log_err "Could not find valid 64-char SHA-256 entry for ${ARCHIVE_NAME} in checksums.txt."
exit 1
fi
ACTUAL_HASH="$(compute_sha256 "$ARCHIVE_PATH")"
if [ "$ACTUAL_HASH" != "$EXPECTED_HASH" ]; then
log_err "SHA-256 checksum verification FAILED for ${ARCHIVE_NAME}!"
log_err " Expected: ${EXPECTED_HASH}"
log_err " Actual: ${ACTUAL_HASH}"
exit 1
fi
log_ok "Verified SHA-256: ${ACTUAL_HASH}"
tar -xzf "$ARCHIVE_PATH" -C "$TMP_DIR"
EXTRACTED_BIN="${TMP_DIR}/${BIN_INNER}"
if [ ! -f "$EXTRACTED_BIN" ]; then
log_err "Expected binary '${BIN_INNER}' not found inside ${ARCHIVE_NAME}."
exit 1
fi
mkdir -p "$INSTALL_DIR"
TARGET_BIN="${INSTALL_DIR}/focusflow"
TMP_TARGET_BIN="${TARGET_BIN}.tmp.$$"
rm -f "$TMP_TARGET_BIN"
cp "$EXTRACTED_BIN" "$TMP_TARGET_BIN"
chmod 0755 "$TMP_TARGET_BIN"
mv -f "$TMP_TARGET_BIN" "$TARGET_BIN"
log_ok "Installed FocusFlow binary to ${TARGET_BIN}"
"$TARGET_BIN" version || true
case ":${PATH:-}:" in
*":${INSTALL_DIR}:"*)
;;
*)
log_info "Add ${INSTALL_DIR} to your PATH if not already configured:"
log_info " export PATH=\"${INSTALL_DIR}:\$PATH\""
;;
esac
}
main "$@"