-
Notifications
You must be signed in to change notification settings - Fork 111
Expand file tree
/
Copy pathinstall-fda
More file actions
executable file
·198 lines (172 loc) · 5.79 KB
/
install-fda
File metadata and controls
executable file
·198 lines (172 loc) · 5.79 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
196
197
198
#!/bin/sh
# Feldera fda CLI installer
# Usage:
# curl -fsSL https://feldera.com/install-fda | bash
# curl -fsSL https://feldera.com/install-fda | FDA_VERSION=v0.270.0 bash
# curl -fsSL https://feldera.com/install-fda | FELDERA_INSTALL=/opt/feldera bash
set -eu
main() {
need_cmd curl
need_cmd unzip
need_cmd mktemp
need_cmd chmod
need_cmd mkdir
need_cmd mv
need_cmd rm
need_cmd uname
FELDERA_INSTALL="${FELDERA_INSTALL:-$HOME/.feldera}"
BIN_DIR="$FELDERA_INSTALL/bin"
detect_platform
resolve_version
download_and_install
setup_path
print_success
}
err() {
printf "error: %s\n" "$1" >&2
exit 1
}
info() {
printf "%s\n" "$1"
}
need_cmd() {
if ! command -v "$1" > /dev/null 2>&1; then
err "need '$1' (command not found)"
fi
}
detect_platform() {
OS="$(uname -s)"
ARCH="$(uname -m)"
case "$OS" in
Linux)
case "$ARCH" in
x86_64 | amd64)
TARGET="x86_64-unknown-linux-gnu"
;;
aarch64 | arm64)
TARGET="aarch64-unknown-linux-gnu"
;;
*)
err "unsupported Linux architecture: $ARCH. Supported: x86_64, aarch64"
;;
esac
info "Detected platform: Linux $ARCH"
;;
Darwin)
err "macOS is not currently supported. Install fda with: cargo install fda"
;;
MINGW* | MSYS* | CYGWIN*)
err "Windows is not currently supported by this installer. Download fda from https://github.com/feldera/feldera/releases or install with: cargo install fda"
;;
*)
err "unsupported operating system: $OS"
;;
esac
}
resolve_version() {
if [ -n "${FDA_VERSION:-}" ]; then
VERSION="$FDA_VERSION"
DOWNLOAD_URL="https://github.com/feldera/feldera/releases/download/${VERSION}/fda-${TARGET}.zip"
info "Installing fda ${VERSION}"
else
DOWNLOAD_URL="https://github.com/feldera/feldera/releases/latest/download/fda-${TARGET}.zip"
info "Installing fda (latest)"
fi
}
download_and_install() {
TMPDIR=$(mktemp -d)
# shellcheck disable=SC2064
trap "rm -rf '$TMPDIR'" EXIT
TMPFILE="$TMPDIR/fda.zip"
info "Downloading from $DOWNLOAD_URL"
HTTP_CODE=$(curl -fSL --progress-bar -o "$TMPFILE" -w "%{http_code}" "$DOWNLOAD_URL") || {
case "$HTTP_CODE" in
404)
if [ -n "${FDA_VERSION:-}" ]; then
err "version ${FDA_VERSION} not found. Check available versions at https://github.com/feldera/feldera/releases"
else
err "release asset not found. The latest release may not include standalone fda binaries yet."
fi
;;
*)
err "download failed (HTTP $HTTP_CODE)"
;;
esac
}
info "Extracting fda binary"
unzip -jo "$TMPFILE" fda -d "$TMPDIR"
TMPBIN="$TMPDIR/fda"
chmod +x "$TMPBIN"
mkdir -p "$BIN_DIR"
mv "$TMPBIN" "$BIN_DIR/fda"
info "Installed fda to $BIN_DIR/fda"
}
setup_path() {
# Check if bin dir is already in PATH
case ":${PATH}:" in
*":${BIN_DIR}:"*)
return
;;
esac
SHELL_NAME="$(basename "${SHELL:-/bin/sh}")"
RC_LINES="export FELDERA_INSTALL=\"$FELDERA_INSTALL\"\nexport PATH=\"\$FELDERA_INSTALL/bin:\$PATH\""
UPDATED_RC=""
case "$SHELL_NAME" in
bash)
if [ -f "$HOME/.bashrc" ] && ! grep -q FELDERA_INSTALL "$HOME/.bashrc"; then
printf '\n# Feldera fda CLI\n%b\n' "$RC_LINES" >> "$HOME/.bashrc"
# shellcheck disable=SC2088
UPDATED_RC="~/.bashrc"
elif [ -f "$HOME/.bash_profile" ] && ! grep -q FELDERA_INSTALL "$HOME/.bash_profile"; then
printf '\n# Feldera fda CLI\n%b\n' "$RC_LINES" >> "$HOME/.bash_profile"
# shellcheck disable=SC2088
UPDATED_RC="~/.bash_profile"
fi
;;
zsh)
if [ -f "$HOME/.zshrc" ] && ! grep -q FELDERA_INSTALL "$HOME/.zshrc"; then
printf '\n# Feldera fda CLI\n%b\n' "$RC_LINES" >> "$HOME/.zshrc"
# shellcheck disable=SC2088
UPDATED_RC="~/.zshrc"
fi
;;
fish)
FISH_CONFIG="$HOME/.config/fish/config.fish"
if [ -d "$HOME/.config/fish" ] || mkdir -p "$HOME/.config/fish"; then
if ! grep -q FELDERA_INSTALL "$FISH_CONFIG" 2>/dev/null; then
# shellcheck disable=SC2016
printf '\n# Feldera fda CLI\nset -gx FELDERA_INSTALL %s\nset -gx PATH $FELDERA_INSTALL/bin $PATH\n' "$FELDERA_INSTALL" >> "$FISH_CONFIG"
# shellcheck disable=SC2088
UPDATED_RC="~/.config/fish/config.fish"
fi
fi
;;
esac
if [ -n "$UPDATED_RC" ]; then
info "Added $BIN_DIR to PATH in $UPDATED_RC"
fi
}
print_success() {
printf '\n'
info "fda was installed successfully!"
# Try to print version
if command -v "$BIN_DIR/fda" > /dev/null 2>&1; then
info "$("$BIN_DIR/fda" --version 2>/dev/null || echo "fda (version unknown)")"
fi
# PATH instructions
case ":${PATH}:" in
*":${BIN_DIR}:"*)
;;
*)
printf '\n'
info "To get started, restart your shell or run:"
info " export FELDERA_INSTALL=\"$FELDERA_INSTALL\""
info " export PATH=\"\$FELDERA_INSTALL/bin:\$PATH\""
;;
esac
# Shell completion hint
printf '\n'
info "To enable shell completions, see:"
info " https://docs.feldera.com/docs/interface/cli#optional-shell-completion"
}
main