-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·176 lines (144 loc) · 6.63 KB
/
install.sh
File metadata and controls
executable file
·176 lines (144 loc) · 6.63 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
#!/usr/bin/env bash
# Firefly Framework CLI Installer
# Usage:
# curl -fsSL https://raw.githubusercontent.com/fireflyframework/fireflyframework-cli/main/install.sh | bash
# FLYWORK_VERSION=v26.02.03 bash install.sh
# FLYWORK_INSTALL_DIR=/custom/path bash install.sh
set -euo pipefail
REPO="fireflyframework/fireflyframework-cli"
BINARY="flywork"
# ── Colors ───────────────────────────────────────────────────────────────────
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
CYAN='\033[0;36m'
BOLD='\033[1m'
NC='\033[0m'
info() { printf "${CYAN} ℹ ${NC}%s\n" "$1"; }
success() { printf "${GREEN} ✓ ${NC}%s\n" "$1"; }
warn() { printf "${YELLOW} ! ${NC}%s\n" "$1"; }
error() { printf "${RED} ✗ ${NC}%s\n" "$1"; exit 1; }
# ── Banner ───────────────────────────────────────────────────────────────────
printf "${BOLD}${CYAN}"
cat << 'EOF'
_____.__ _____.__
_/ ____\__|______ _____/ ____\ | ___.__.
\ __\| \_ __ \_/ __ \ __\| |< | |
| | | || | \/\ ___/| | | |_\___ |
|__| |__||__| \___ >__| |____/ ____|
\/ \/
_____ __
_/ ____\___________ _____ ______ _ _____________| | __
\ __\\_ __ \__ \ / \_/ __ \ \/ \/ / _ \_ __ \ |/ /
| | | | \// __ \| Y Y \ ___/\ ( <_> ) | \/ <
|__| |__| (____ /__|_| /\___ >\/\_/ \____/|__| |__|_ \
\/ \/ \/ \/
EOF
printf "${NC}\n"
info "Firefly Framework CLI Installer"
echo ""
# ── Detect platform ──────────────────────────────────────────────────────────
detect_os() {
local os
os="$(uname -s | tr '[:upper:]' '[:lower:]')"
case "$os" in
darwin) echo "darwin" ;;
linux) echo "linux" ;;
*) error "Unsupported OS: $os (use install.ps1 for Windows)" ;;
esac
}
detect_arch() {
local arch
arch="$(uname -m)"
case "$arch" in
x86_64|amd64) echo "amd64" ;;
aarch64|arm64) echo "arm64" ;;
*) error "Unsupported architecture: $arch" ;;
esac
}
OS="$(detect_os)"
ARCH="$(detect_arch)"
info "Detected platform: ${OS}/${ARCH}"
# ── Resolve version ──────────────────────────────────────────────────────────
if [ -z "${FLYWORK_VERSION:-}" ]; then
info "Fetching latest release..."
FLYWORK_VERSION="$(curl -fsSL "https://api.github.com/repos/${REPO}/releases/latest" | grep '"tag_name"' | sed -E 's/.*"([^"]+)".*/\1/')"
if [ -z "$FLYWORK_VERSION" ]; then
error "Could not determine latest version"
fi
fi
# Ensure version starts with 'v' (matches Makefile archive naming)
case "$FLYWORK_VERSION" in v*) ;; *) FLYWORK_VERSION="v${FLYWORK_VERSION}" ;; esac
info "Version: ${FLYWORK_VERSION}"
# ── Resolve install directory ────────────────────────────────────────────────
if [ -z "${FLYWORK_INSTALL_DIR:-}" ]; then
if [ -w "/usr/local/bin" ]; then
FLYWORK_INSTALL_DIR="/usr/local/bin"
else
FLYWORK_INSTALL_DIR="${HOME}/.flywork/bin"
fi
fi
mkdir -p "$FLYWORK_INSTALL_DIR"
info "Install directory: ${FLYWORK_INSTALL_DIR}"
# ── Download ─────────────────────────────────────────────────────────────────
ARCHIVE_NAME="${BINARY}-${FLYWORK_VERSION}-${OS}-${ARCH}.tar.gz"
DOWNLOAD_URL="https://github.com/${REPO}/releases/download/${FLYWORK_VERSION}/${ARCHIVE_NAME}"
TMP_DIR="$(mktemp -d)"
trap 'rm -rf "$TMP_DIR"' EXIT
info "Downloading ${ARCHIVE_NAME}..."
if ! curl -fsSL -o "${TMP_DIR}/${ARCHIVE_NAME}" "$DOWNLOAD_URL"; then
error "Download failed — check that version ${FLYWORK_VERSION} exists for ${OS}/${ARCH}"
fi
# ── Extract & install ────────────────────────────────────────────────────────
info "Extracting..."
tar -xzf "${TMP_DIR}/${ARCHIVE_NAME}" -C "$TMP_DIR"
# Find the binary inside the extracted directory
EXTRACTED_BIN="$(find "$TMP_DIR" -name "$BINARY" -type f | head -1)"
if [ -z "$EXTRACTED_BIN" ]; then
error "Binary not found in archive"
fi
chmod +x "$EXTRACTED_BIN"
mv "$EXTRACTED_BIN" "${FLYWORK_INSTALL_DIR}/${BINARY}"
success "Installed ${BINARY} to ${FLYWORK_INSTALL_DIR}/${BINARY}"
# ── Update PATH if needed ───────────────────────────────────────────────────
add_to_path() {
local dir="$1"
local shell_rc
case "${SHELL:-/bin/bash}" in
*/zsh) shell_rc="$HOME/.zshrc" ;;
*/bash)
if [ -f "$HOME/.bashrc" ]; then
shell_rc="$HOME/.bashrc"
else
shell_rc="$HOME/.profile"
fi
;;
*) shell_rc="$HOME/.profile" ;;
esac
if ! echo "$PATH" | tr ':' '\n' | grep -q "^${dir}$"; then
local export_line="export PATH=\"${dir}:\$PATH\""
if [ -f "$shell_rc" ] && grep -qF "$dir" "$shell_rc" 2>/dev/null; then
return
fi
echo "" >> "$shell_rc"
echo "# Firefly Framework CLI" >> "$shell_rc"
echo "$export_line" >> "$shell_rc"
warn "Added ${dir} to PATH in ${shell_rc} — restart your shell or run: source ${shell_rc}"
fi
}
if ! echo "$PATH" | tr ':' '\n' | grep -q "^${FLYWORK_INSTALL_DIR}$"; then
add_to_path "$FLYWORK_INSTALL_DIR"
export PATH="${FLYWORK_INSTALL_DIR}:$PATH"
fi
# ── Verify ───────────────────────────────────────────────────────────────────
echo ""
if command -v "$BINARY" &>/dev/null; then
success "Installation complete!"
echo ""
"$BINARY" version
else
warn "Installed, but '${BINARY}' is not in PATH yet. Restart your shell or run:"
echo " export PATH=\"${FLYWORK_INSTALL_DIR}:\$PATH\""
fi
echo ""
printf "${CYAN} ℹ ${NC}Get started: ${BOLD}flywork setup${NC}\n"