-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·385 lines (326 loc) · 10.4 KB
/
install.sh
File metadata and controls
executable file
·385 lines (326 loc) · 10.4 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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
#!/bin/bash
set -e
REPO="dev-dami/ignite"
INSTALL_DIR="${IGNITE_INSTALL_DIR:-$HOME/.ignite}"
BIN_DIR="$INSTALL_DIR/bin"
VERSION=""
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
MAGENTA='\033[0;35m'
BOLD='\033[1m'
DIM='\033[2m'
NC='\033[0m'
REVERSE='\033[7m'
clear_line() { echo -ne "\033[2K\r" >&2; }
move_up() { echo -ne "\033[1A" >&2; }
hide_cursor() { echo -ne "\033[?25l" >&2; }
show_cursor() { echo -ne "\033[?25h" >&2; }
print_banner() {
clear
echo -e "${CYAN}${BOLD}" >&2
cat >&2 << 'EOF'
╦╔═╗╔╗╔╦╔╦╗╔═╗
║║ ╦║║║║ ║ ║╣
╩╚═╝╝╚╝╩ ╩ ╚═╝
EOF
echo -e "${NC}" >&2
echo -e " ${DIM}Run JS/TS microservices in Docker${NC}" >&2
echo "" >&2
}
print_status() {
local installed_version latest_version status_color status_text
installed_version=$(get_installed_version)
latest_version=$(get_latest_version)
echo -e " ${DIM}─────────────────────────────────${NC}" >&2
if [ -n "$installed_version" ]; then
if [ "$installed_version" = "$latest_version" ]; then
status_color="${GREEN}"
status_text="Up to date"
else
status_color="${YELLOW}"
status_text="Update available"
fi
echo -e " ${DIM}Installed:${NC} ${BOLD}v$installed_version${NC} ${status_color}($status_text)${NC}" >&2
else
echo -e " ${DIM}Installed:${NC} ${DIM}Not installed${NC}" >&2
fi
echo -e " ${DIM}Latest:${NC} ${BOLD}$latest_version${NC}" >&2
echo -e " ${DIM}─────────────────────────────────${NC}" >&2
echo "" >&2
}
get_installed_version() {
if [ -f "$BIN_DIR/ignite" ]; then
"$BIN_DIR/ignite" --version 2>/dev/null || echo ""
fi
}
get_latest_version() {
curl -sL "https://api.github.com/repos/${REPO}/releases/latest" 2>/dev/null | grep '"tag_name"' | sed -E 's/.*"v?([^"]+)".*/\1/'
}
detect_platform() {
local os arch
case "$(uname -s)" in
Linux*) os="linux" ;;
Darwin*) os="darwin" ;;
*) echo ""; return ;;
esac
case "$(uname -m)" in
x86_64|amd64) arch="x64" ;;
arm64|aarch64) arch="arm64" ;;
*) echo ""; return ;;
esac
echo "${os}-${arch}"
}
show_menu() {
local selected=$1
local installed_version
installed_version=$(get_installed_version)
local options=()
if [ -z "$installed_version" ]; then
options+=("Install Ignite")
else
options+=("Update Ignite")
options+=("Reinstall Ignite")
options+=("Uninstall Ignite")
fi
options+=("Exit")
echo -e " ${BOLD}Select an option:${NC}" >&2
echo "" >&2
for i in "${!options[@]}"; do
if [ $i -eq $selected ]; then
echo -e " ${REVERSE}${CYAN} > ${options[$i]} ${NC}" >&2
else
echo -e " ${DIM}${options[$i]}${NC}" >&2
fi
done
echo "" >&2
echo -e " ${DIM}Use arrow keys ↑↓ and Enter to select${NC}" >&2
}
run_menu() {
local selected=0
local installed_version
installed_version=$(get_installed_version)
local num_options=2
[ -n "$installed_version" ] && num_options=4
# Check if we can access /dev/tty for interactive input
if ! exec 3</dev/tty 2>/dev/null; then
echo -e " ${YELLOW}!${NC} Non-interactive mode detected, auto-installing..." >&2
do_install
return
fi
hide_cursor
trap 'show_cursor; exec 3<&-' EXIT
while true; do
print_banner
print_status
show_menu $selected
# Read from /dev/tty (fd 3) instead of stdin
read -rsn1 key <&3
if [[ $key == $'\x1b' ]]; then
read -rsn2 key <&3
case $key in
'[A') ((selected > 0)) && ((selected--)) ;;
'[B') ((selected < num_options - 1)) && ((selected++)) ;;
esac
elif [[ $key == "" ]]; then
show_cursor
exec 3<&-
handle_selection $selected "$installed_version"
return
fi
done
}
handle_selection() {
local selected=$1
local installed=$2
echo "" >&2
if [ -z "$installed" ]; then
case $selected in
0) do_install ;;
1) echo -e "${DIM}Goodbye!${NC}" >&2; exit 0 ;;
esac
else
case $selected in
0) do_update ;;
1) do_install --force ;;
2) do_uninstall ;;
3) echo -e "${DIM}Goodbye!${NC}" >&2; exit 0 ;;
esac
fi
}
progress_bar() {
local current=$1
local total=$2
local width=40
local percent=$((current * 100 / total))
local filled=$((current * width / total))
local empty=$((width - filled))
printf "\r ${CYAN}[" >&2
printf "%${filled}s" | tr ' ' '█' >&2
printf "%${empty}s" | tr ' ' '░' >&2
printf "]${NC} %3d%%" "$percent" >&2
}
do_install() {
local force=$1
echo -e " ${CYAN}${BOLD}Installing Ignite${NC}" >&2
echo "" >&2
local platform version
platform=$(detect_platform)
[ -z "$platform" ] && { echo -e " ${RED}✗${NC} Unsupported platform" >&2; exit 1; }
echo -e " ${GREEN}✓${NC} Platform: $platform" >&2
version=$(get_latest_version)
[ -z "$version" ] && { echo -e " ${RED}✗${NC} Could not fetch version" >&2; exit 1; }
echo -e " ${GREEN}✓${NC} Version: v$version" >&2
local url="https://github.com/${REPO}/releases/download/v${version}/ignite-${platform}.tar.gz"
local tmp_dir
tmp_dir=$(mktemp -d)
echo -e " ${BLUE}>${NC} Downloading..." >&2
if command -v curl &> /dev/null; then
curl -fSL --progress-bar "$url" -o "$tmp_dir/ignite.tar.gz" 2>&1 | while read -r line; do
:
done
if [ ! -f "$tmp_dir/ignite.tar.gz" ]; then
curl -fSL "$url" -o "$tmp_dir/ignite.tar.gz" 2>/dev/null || {
rm -rf "$tmp_dir"
echo -e " ${RED}✗${NC} Download failed" >&2
exit 1
}
fi
else
wget -q "$url" -O "$tmp_dir/ignite.tar.gz" || {
rm -rf "$tmp_dir"
echo -e " ${RED}✗${NC} Download failed" >&2
exit 1
}
fi
echo -e " ${GREEN}✓${NC} Downloaded" >&2
echo -e " ${BLUE}>${NC} Extracting..." >&2
mkdir -p "$BIN_DIR"
tar -xzf "$tmp_dir/ignite.tar.gz" -C "$tmp_dir"
cp "$tmp_dir/ignite-${platform}" "$BIN_DIR/ignite"
chmod +x "$BIN_DIR/ignite"
[ -d "$tmp_dir/runtime-bun" ] && { mkdir -p "$INSTALL_DIR/runtime-bun"; cp -r "$tmp_dir/runtime-bun/"* "$INSTALL_DIR/runtime-bun/" 2>/dev/null || true; }
rm -rf "$tmp_dir"
echo -e " ${GREEN}✓${NC} Installed to $BIN_DIR/ignite" >&2
setup_path
echo "" >&2
echo -e " ${GREEN}${BOLD}✓ Installation complete!${NC}" >&2
echo "" >&2
echo -e " ${DIM}Restart your terminal or run:${NC}" >&2
echo -e " ${YELLOW}source ~/.bashrc${NC} ${DIM}(or ~/.zshrc)${NC}" >&2
echo "" >&2
echo -e " ${DIM}Then try:${NC}" >&2
echo -e " ${YELLOW}ignite init hello && cd hello && ignite run .${NC}" >&2
echo "" >&2
}
do_update() {
local installed latest
installed=$(get_installed_version)
latest=$(get_latest_version)
if [ "$installed" = "$latest" ]; then
echo -e " ${GREEN}✓${NC} Already up to date (v$installed)" >&2
echo "" >&2
return
fi
echo -e " ${CYAN}${BOLD}Updating Ignite${NC}" >&2
echo -e " ${DIM}v$installed → v$latest${NC}" >&2
echo "" >&2
do_install --force
}
do_uninstall() {
echo -e " ${CYAN}${BOLD}Uninstalling Ignite${NC}" >&2
echo "" >&2
if [ ! -d "$INSTALL_DIR" ]; then
echo -e " ${YELLOW}!${NC} Ignite is not installed" >&2
return
fi
echo -ne " ${YELLOW}Are you sure? [y/N]${NC} " >&2
read -r confirm
if [[ ! "$confirm" =~ ^[Yy]$ ]]; then
echo -e " ${DIM}Cancelled${NC}" >&2
return
fi
rm -rf "$INSTALL_DIR"
echo -e " ${GREEN}✓${NC} Removed $INSTALL_DIR" >&2
echo "" >&2
echo -e " ${DIM}You may want to remove the PATH entry from your shell config${NC}" >&2
echo "" >&2
}
setup_path() {
local shell_rc path_export
path_export="export PATH=\"\$PATH:$BIN_DIR\""
if [ -f "$HOME/.zshrc" ]; then
shell_rc="$HOME/.zshrc"
elif [ -f "$HOME/.bashrc" ]; then
shell_rc="$HOME/.bashrc"
elif [ -f "$HOME/.config/fish/config.fish" ]; then
shell_rc="$HOME/.config/fish/config.fish"
path_export="set -gx PATH \$PATH $BIN_DIR"
elif [ -f "$HOME/.profile" ]; then
shell_rc="$HOME/.profile"
fi
if echo "$PATH" | grep -q "$BIN_DIR"; then
return
fi
if [ -n "$shell_rc" ]; then
if ! grep -q "$BIN_DIR" "$shell_rc" 2>/dev/null; then
echo -e "\n# Ignite CLI\n$path_export" >> "$shell_rc"
echo -e " ${GREEN}✓${NC} Added to PATH in $(basename "$shell_rc")" >&2
fi
fi
}
show_help() {
echo "Ignite Installer" >&2
echo "" >&2
echo "Usage: install.sh [command]" >&2
echo "" >&2
echo "Commands:" >&2
echo " install Install Ignite (default)" >&2
echo " update Update to latest version" >&2
echo " uninstall Remove Ignite" >&2
echo " help Show this help" >&2
echo "" >&2
echo "Examples:" >&2
echo " curl -fsSL .../install.sh | bash" >&2
echo " curl -fsSL .../install.sh | bash -s install" >&2
echo " curl -fsSL .../install.sh | bash -s update" >&2
echo "" >&2
}
main() {
case "${1:-}" in
install)
print_banner
print_status
do_install
;;
update)
print_banner
print_status
do_update
;;
uninstall)
print_banner
do_uninstall
;;
help|--help|-h)
show_help
;;
"")
if [ -t 0 ] && [ -t 1 ]; then
run_menu
else
print_banner
print_status
do_install
fi
;;
*)
echo "Unknown command: $1" >&2
show_help
exit 1
;;
esac
}
main "$@"