This repository was archived by the owner on Apr 14, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
Β·717 lines (651 loc) Β· 26.6 KB
/
install.sh
File metadata and controls
executable file
Β·717 lines (651 loc) Β· 26.6 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
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
#!/bin/sh
# Install script for Nest CLI tool
# Supports Linux and macOS
set -e
# Detect if colors are supported
if [ -t 1 ] && command -v tput > /dev/null 2>&1; then
RED=$(tput setaf 1)
GREEN=$(tput setaf 2)
YELLOW=$(tput setaf 3)
BLUE=$(tput setaf 4)
BOLD=$(tput bold)
RESET=$(tput sgr0)
HAS_COLORS=1
else
RED=''
GREEN=''
YELLOW=''
BLUE=''
BOLD=''
RESET=''
HAS_COLORS=0
fi
# Detect Unicode support
if [ "$HAS_COLORS" = "1" ] && [ -n "$LANG" ] && echo "$LANG" | grep -q "UTF-8\|utf8"; then
CHECK="${GREEN}β${RESET}"
CROSS="${RED}β${RESET}"
ARROW="${BLUE}β${RESET}"
INFO="${BLUE}βΉ${RESET}"
WARN="${YELLOW}β ${RESET}"
NEST_ICON="πͺΊ"
else
CHECK="${GREEN}[OK]${RESET}"
CROSS="${RED}[FAIL]${RESET}"
ARROW="${BLUE}=>${RESET}"
INFO="${BLUE}[i]${RESET}"
WARN="${YELLOW}[!]${RESET}"
NEST_ICON="Nest"
fi
# Initialize variables with defaults
REPO="quonaro/nest"
VERSION="latest"
LIBC_FLAVOR="glibc"
INSTALL_SCOPE="user"
INTERACTIVE=0
INSTALL_TUI=1
# Check if running interactively
if [ -t 0 ]; then
INTERACTIVE=1
INPUT_SOURCE="/dev/stdin"
elif [ -r /dev/tty ]; then
INTERACTIVE=1
INPUT_SOURCE="/dev/tty"
fi
# Parse command line arguments
TARGET_EXPLICITLY_SET=0
VERSION_EXPLICITLY_SET=0
while [ "$#" -gt 0 ]; do
case "$1" in
-T|--target)
if [ -n "$2" ]; then
LIBC_FLAVOR="$2"
TARGET_EXPLICITLY_SET=1
shift 2
else
echo "${CROSS} ${BOLD}${RED}Error: Argument for $1 is missing${RESET}" >&2
exit 1
fi
;;
-V|--version)
if [ -n "$2" ]; then
VERSION="$2"
VERSION_EXPLICITLY_SET=1
shift 2
else
echo "${CROSS} ${BOLD}${RED}Error: Argument for $1 is missing${RESET}" >&2
exit 1
fi
;;
-h|--help)
echo "Usage: ./install.sh [OPTIONS]"
echo ""
echo "Options:"
echo " -T, --target <flavor> Target libc flavor: 'glibc' (default) or 'musl'"
echo " -V, --version <ver> Install specific version (default: latest)"
echo " -h, --help Show this help message"
echo ""
exit 0
;;
*)
# Backward compatibility: first arg as version if not a flag
if [ "$1" != "${1#-}" ]; then
echo "${CROSS} ${BOLD}${RED}Error: Unknown option $1${RESET}" >&2
exit 1
fi
VERSION="$1"
VERSION_EXPLICITLY_SET=1
shift
;;
esac
done
# Overlay environment variables if set (CLI args take precedence if defaults were used logic-wise,
# but here we just let CLI args overwrite defaults.
# If user wants to mix env vars and CLI, CLI wins for explicitly set things.)
# However, to respect "defaults", we need to know if they were changed.
# Simpler approach: Env vars set the initial state, flags override them.
# Refactoring slightly to allow ENV vars to set defaults before arg parsing?
# Actually, the block above sets defaults to hardcoded values.
# Let's re-apply env vars only if they differ from default AND arg wasn't passed?
# Standard unix convention: Env < CLI.
# So:
# 1. Defaults
# 2. Env vars
# 3. CLI args
# Reset to defaults for detecting overrides? No, let's just do:
# [Existing Env Logic was]: VERSION="${NEST_VERSION:-latest}"
# So let's respect that.
VERSION="${NEST_VERSION:-$VERSION}"
LIBC_FLAVOR="${NEST_LIBC:-$LIBC_FLAVOR}"
INSTALL_SCOPE="${NEST_INSTALL_SCOPE:-$INSTALL_SCOPE}"
# Platform detection
OS="$(uname -s)"
ARCH="$(uname -m)"
case "$OS" in
Linux*) PLATFORM="linux" ;;
Darwin*) PLATFORM="macos" ;;
*) echo "${CROSS} ${BOLD}${RED}Error: Unsupported OS: $OS${RESET}" >&2; exit 1 ;;
esac
case "$ARCH" in
x86_64) ARCHITECTURE="x86_64" ;;
aarch64|arm64) ARCHITECTURE="aarch64" ;;
*) echo "${CROSS} ${BOLD}${RED}Error: Unsupported architecture: $ARCH${RESET}" >&2; exit 1 ;;
esac
# Determine binary name
if [ "$PLATFORM" = "windows" ]; then
BINARY_NAME="nest.exe"
else
BINARY_NAME="nest"
fi
# Interactive Prompts
# Only if interactive AND no specific flags were likely passed used to suppress this?
# The user said: "If interactive, select musl or glibc via [y/n]".
# If the user passed flags, maybe they don't want prompts.
# Let's assume if they ran just `./install.sh` they want prompts.
# If they ran `./install.sh -T musl` they probably decided already.
# But checking which args were passed is complex.
# Let's ask only if we are using defaults?
# OR just ask "Do you want to use musl? [y/N]" showing current default logic.
if [ "$INTERACTIVE" = "1" ] && [ -z "$NEST_NONINTERACTIVE" ]; then
# Only ask for musl/glibc on Linux x86_64
if [ "$PLATFORM" = "linux" ] && [ "$ARCHITECTURE" = "x86_64" ]; then
# Check if user already specified it via flag/env. If it's already "musl", confirm?
# Simpler: Just ask.
# But if I typed `./install.sh -T musl`, getting asked "Use musl?" is annoying.
# So, we need a way to know if it was explicitly set.
# Let's assume if the user provided ANY arguments, we skip prompts?
# No, the user might provide version but want to be asked about libc.
# Let's go with a simple prompt flow that defaults to the current value.
echo ""
echo "${INFO} ${BOLD}Detected Linux x86_64.${RESET}"
# If currently glibc (default), ask if they want musl.
if [ "$TARGET_EXPLICITLY_SET" != "1" ] && [ "$LIBC_FLAVOR" != "musl" ]; then
printf "${INFO} Do you want to use the ${BOLD}musl (static)${RESET} libc instead of glibc? [y/N] "
read -r REPLY < "$INPUT_SOURCE"
if echo "$REPLY" | grep -iq "^y"; then
LIBC_FLAVOR="musl"
echo " ${ARROW} Using ${BOLD}musl${RESET}"
else
echo " ${ARROW} Using ${BOLD}glibc${RESET}"
fi
else
# Already musl (via flag/env/explicit), or forced glibc.
:
fi
fi
# Version Prompt
# If version is latest, ask if they want specific.
if [ "$VERSION_EXPLICITLY_SET" != "1" ] && [ "$VERSION" = "latest" ]; then
echo ""
printf "${INFO} Do you want to install a specific version? [y/N] "
read -r REPLY < "$INPUT_SOURCE"
if echo "$REPLY" | grep -iq "^y"; then
echo "${INFO} Fetching recent versions..."
if command -v curl > /dev/null 2>&1; then
# Fetch tags from GitHub API
# Retrieve up to 100 recent versions per page
TAGS=$(curl -s "https://api.github.com/repos/${REPO}/releases?per_page=100" | grep '"tag_name":' | sed -E 's/.*"tag_name": "([^"]+)".*/\1/')
if [ -n "$TAGS" ]; then
echo "${INFO} Available versions:"
# Pagination logic
TOTAL_LINES=$(echo "$TAGS" | wc -l)
CURRENT_LINE=1
PAGE_SIZE=5
while true; do
END_LINE=$((CURRENT_LINE + PAGE_SIZE - 1))
# Display current page
echo "$TAGS" | sed -n "${CURRENT_LINE},${END_LINE}p" | while read -r line; do
echo " - ${BOLD}$line${RESET}"
done
REMAINING=$((TOTAL_LINES - END_LINE))
echo ""
if [ "$REMAINING" -gt 0 ]; then
printf "${INFO} Enter version (or press 'm' to see more): "
else
printf "${INFO} Enter version: "
fi
read -r V_INPUT < "$INPUT_SOURCE"
if [ "$V_INPUT" = "m" ] && [ "$REMAINING" -gt 0 ]; then
CURRENT_LINE=$((END_LINE + 1))
continue
elif [ -n "$V_INPUT" ]; then
CLEAN_VERSION="${V_INPUT#v}"
VERSION="$CLEAN_VERSION"
echo " ${ARROW} You selected: ${BOLD}v${VERSION}${RESET}"
break
else
# If empty input, keep asking or treat as cancel?
# Better to loop if empty or maybe strictly require input?
# Logic above: if -n V_INPUT check was used.
# If user just hits enter, loop again or do nothing?
# If empty, let's just re-prompt essentially by continuing loop logic but without advancing page?
# Actually if empty, staying on same page is confusing if we reprint.
# Let's assume empty input = cancel/skip? No, user said "Enter version".
# Re-prompting is best.
echo "${WARN} Please enter a version."
# Don't advance page
fi
done
else
echo "${WARN} Could not fetch versions (network or API limit). You can still type a version manually."
printf "${INFO} Enter version: "
read -r V_INPUT < "$INPUT_SOURCE"
if [ -n "$V_INPUT" ]; then
CLEAN_VERSION="${V_INPUT#v}"
VERSION="$CLEAN_VERSION"
echo " ${ARROW} You selected: ${BOLD}v${VERSION}${RESET}"
fi
fi
else
echo "${WARN} curl not found, cannot list versions. Please type manually."
printf "${INFO} Enter version: "
read -r V_INPUT < "$INPUT_SOURCE"
if [ -n "$V_INPUT" ]; then
CLEAN_VERSION="${V_INPUT#v}"
VERSION="$CLEAN_VERSION"
echo " ${ARROW} You selected: ${BOLD}v${VERSION}${RESET}"
fi
fi
fi
fi
# TUI Installation Prompt
if [ "$INTERACTIVE" = "1" ] && [ -z "$NEST_NONINTERACTIVE" ]; then
echo ""
printf "${INFO} Do you want to install the Nest TUI (nestui)? [Y/n] "
read -r REPLY < "$INPUT_SOURCE"
if echo "$REPLY" | grep -iq "^n"; then
INSTALL_TUI=0
echo " ${ARROW} Skipping TUI installation"
else
INSTALL_TUI=1
echo " ${ARROW} Installing TUI"
fi
fi
# Install Path Prompt
echo ""
echo "${INFO} ${BOLD}Choose installation location:${RESET}"
echo " 1) User (${HOME}/.local/bin) [Default]"
# Determine system path based on OS
if [ "$PLATFORM" = "macos" ]; then
SYSTEM_PATH="/usr/local/bin"
else
SYSTEM_PATH="/usr/local/bin" # Standard for Linux too usually, but sometimes /usr/bin is preferred by distros. Sticking to /usr/local/bin as safe default.
fi
# Just to be sure about "standard paths", /usr/local/bin is generally safer than /usr/bin for user installed stuff.
echo " 2) System (${SYSTEM_PATH})"
echo " 3) Custom"
printf "${INFO} Enter selection [1]: "
read -r REPLY < "$INPUT_SOURCE"
case "$REPLY" in
2)
INSTALL_DIR="${SYSTEM_PATH}"
INSTALL_SCOPE="system"
;;
3)
printf "${INFO} Enter custom path: "
read -r CUSTOM_PATH < "$INPUT_SOURCE"
# Expand tilde if present
CUSTOM_PATH="${CUSTOM_PATH/#\~/$HOME}"
if [ -z "$CUSTOM_PATH" ]; then
echo "${WARN} No path entered, defaulting to User location.${RESET}"
INSTALL_DIR="${HOME}/.local/bin"
INSTALL_SCOPE="user"
else
INSTALL_DIR="$CUSTOM_PATH"
INSTALL_SCOPE="custom"
fi
;;
*)
INSTALL_DIR="${HOME}/.local/bin"
INSTALL_SCOPE="user"
;;
esac
echo " ${ARROW} Installing to ${BOLD}${INSTALL_DIR}${RESET}"
fi
# Resolve Platform Archive Name
PLATFORM_ARCHIVE="${PLATFORM}"
if [ "${PLATFORM}" = "linux" ] && [ "${ARCHITECTURE}" = "x86_64" ]; then
case "${LIBC_FLAVOR}" in
musl|Musl|MUSL)
PLATFORM_ARCHIVE="linux-musl"
;;
glibc|Glibc|GLIBC|"")
PLATFORM_ARCHIVE="linux"
;;
*)
echo "${WARN} Unknown target flavor '${LIBC_FLAVOR}', falling back to glibc (linux archive)${RESET}" >&2
PLATFORM_ARCHIVE="linux"
;;
esac
fi
# Set defaults if not set interactively (for non-interactive mode)
if [ -z "$INSTALL_DIR" ]; then
case "${INSTALL_SCOPE}" in
global|system)
INSTALL_DIR="/usr/local/bin"
;;
user|"")
INSTALL_DIR="${HOME}/.local/bin"
;;
*)
# Scope might be unset or weird, existing logic fallbacks
echo "${WARN} Unknown NEST_INSTALL_SCOPE='${INSTALL_SCOPE}', falling back to user scope${RESET}" >&2
INSTALL_DIR="${HOME}/.local/bin"
INSTALL_SCOPE="user"
;;
esac
fi
# Check write permissions and configure sudo if needed
SUDO=""
if [ -d "$INSTALL_DIR" ]; then
if [ ! -w "$INSTALL_DIR" ]; then
if command -v sudo >/dev/null 2>&1; then
SUDO="sudo"
echo "${INFO} ${BOLD}Note: Installation to ${INSTALL_DIR} requires sudo privileges.${RESET}"
else
echo "${CROSS} ${BOLD}${RED}Error: ${INSTALL_DIR} is not writable and sudo is not available.${RESET}" >&2
exit 1
fi
fi
else
# Directory doesn't exist, check parent permissions
PARENT_DIR=$(dirname "$INSTALL_DIR")
if [ -d "$PARENT_DIR" ] && [ ! -w "$PARENT_DIR" ]; then
if command -v sudo >/dev/null 2>&1; then
SUDO="sudo"
echo "${INFO} ${BOLD}Note: Creating ${INSTALL_DIR} requires sudo privileges.${RESET}"
else
echo "${CROSS} ${BOLD}${RED}Error: Cannot create ${INSTALL_DIR} (permission denied) and sudo is not available.${RESET}" >&2
exit 1
fi
fi
fi
BINARY_PATH="${INSTALL_DIR}/${BINARY_NAME}"
# Print header
echo ""
if [ "$HAS_COLORS" = "1" ]; then
echo "${BOLD}${BLUE}ββββββββββββββββββββββββββββββββββββββββββ${RESET}"
echo "${BOLD}${BLUE}β${RESET} ${BOLD}${NEST_ICON} Nest CLI Installer${RESET} ${BOLD}${BLUE}β${RESET}"
echo "${BOLD}${BLUE}ββββββββββββββββββββββββββββββββββββββββββ${RESET}"
else
echo "${BOLD}${NEST_ICON} Nest CLI Installer${RESET}"
echo "========================================"
fi
echo ""
# Print system information
echo "${INFO} ${BOLD}Detected system:${RESET}"
echo " ${ARROW} Platform: ${BOLD}${PLATFORM}-${ARCHITECTURE}${RESET}"
if [ "${PLATFORM}" = "linux" ] && [ "${ARCHITECTURE}" = "x86_64" ]; then
if [ "${PLATFORM_ARCHIVE}" = "linux-musl" ]; then
echo " ${ARROW} Libc: ${BOLD}musl (static)${RESET}"
else
echo " ${ARROW} Libc: ${BOLD}glibc${RESET}"
fi
fi
echo " ${ARROW} Install scope: ${BOLD}${INSTALL_SCOPE}${RESET}"
echo " ${ARROW} Install directory: ${BOLD}${INSTALL_DIR}${RESET}"
echo ""
# Create install directory if it doesn't exist
echo "${INFO} ${BOLD}Preparing installation...${RESET}"
$SUDO mkdir -p "${INSTALL_DIR}"
echo " ${CHECK} Created install directory"
# Download binary
if [ "$VERSION" = "latest" ]; then
URL="https://github.com/${REPO}/releases/latest/download/nest-${PLATFORM_ARCHIVE}-${ARCHITECTURE}.tar.gz"
else
URL="https://github.com/${REPO}/releases/download/v${VERSION}/nest-${PLATFORM_ARCHIVE}-${ARCHITECTURE}.tar.gz"
fi
# Download with curl or wget
TEMP_DIR=$(mktemp -d)
TEMP_FILE="${TEMP_DIR}/nest-${PLATFORM_ARCHIVE}-${ARCHITECTURE}.tar.gz"
echo ""
echo "${INFO} ${BOLD}Downloading Nest CLI...${RESET}"
echo " ${ARROW} ${URL}"
# Download and check for errors
if command -v curl > /dev/null 2>&1; then
HTTP_CODE=$(curl -L -w "%{http_code}" -o "${TEMP_FILE}" "${URL}" -s -S --show-error)
if [ "$HTTP_CODE" != "200" ]; then
echo ""
echo "${CROSS} ${BOLD}${RED}Error: Failed to download binary (HTTP $HTTP_CODE)${RESET}" >&2
echo " ${WARN} The release may not exist yet. Please check:" >&2
echo " https://github.com/${REPO}/releases" >&2
rm -rf "${TEMP_DIR}"
exit 1
fi
echo " ${CHECK} Download completed"
elif command -v wget > /dev/null 2>&1; then
if ! wget -O "${TEMP_FILE}" "${URL}" 2>&1 | grep -q "200 OK"; then
echo ""
echo "${CROSS} ${BOLD}${RED}Error: Failed to download binary${RESET}" >&2
echo " ${WARN} The release may not exist yet. Please check:" >&2
echo " https://github.com/${REPO}/releases" >&2
rm -rf "${TEMP_DIR}"
exit 1
fi
echo " ${CHECK} Download completed"
else
echo ""
echo "${CROSS} ${BOLD}${RED}Error: Neither curl nor wget found${RESET}" >&2
echo " ${WARN} Please install curl or wget to continue" >&2
exit 1
fi
# Verify downloaded file is a valid archive
echo "${INFO} ${BOLD}Verifying download...${RESET}"
# Check file size (should be greater than 0)
if [ ! -s "${TEMP_FILE}" ]; then
echo ""
echo "${CROSS} ${BOLD}${RED}Error: Downloaded file is empty${RESET}" >&2
echo " ${WARN} The release may not exist yet. Please check:" >&2
echo " https://github.com/${REPO}/releases" >&2
rm -rf "${TEMP_DIR}"
exit 1
fi
# Try to verify it's a valid gzip archive by checking magic bytes or testing extraction
# Check for gzip magic bytes (1f 8b) at the start of the file
if command -v od > /dev/null 2>&1; then
# Use od to check first two bytes
MAGIC_BYTES=$(od -An -tx1 -N2 "${TEMP_FILE}" 2>/dev/null | tr -d ' \n')
if [ "$MAGIC_BYTES" != "1f8b" ]; then
echo ""
echo "${CROSS} ${BOLD}${RED}Error: Downloaded file is not a valid gzip archive${RESET}" >&2
echo " ${WARN} The release may not exist yet. Please check:" >&2
echo " https://github.com/${REPO}/releases" >&2
rm -rf "${TEMP_DIR}"
exit 1
fi
elif command -v file > /dev/null 2>&1; then
# Fallback to file command if available
if ! file "${TEMP_FILE}" | grep -q "gzip\|archive"; then
echo ""
echo "${CROSS} ${BOLD}${RED}Error: Downloaded file is not a valid archive${RESET}" >&2
echo " ${WARN} The release may not exist yet. Please check:" >&2
echo " https://github.com/${REPO}/releases" >&2
rm -rf "${TEMP_DIR}"
exit 1
fi
fi
# If neither od nor file is available, we'll rely on tar extraction to catch errors
echo " ${CHECK} Archive verified"
# Extract archive
echo "${INFO} ${BOLD}Extracting archive...${RESET}"
cd "${TEMP_DIR}"
if ! tar -xzf "${TEMP_FILE}" 2>/dev/null; then
echo ""
echo "${CROSS} ${BOLD}${RED}Error: Failed to extract archive${RESET}" >&2
echo " ${WARN} The downloaded file may be corrupted" >&2
rm -rf "${TEMP_DIR}"
exit 1
fi
echo " ${CHECK} Archive extracted"
# Check if binary exists
if [ ! -f "${BINARY_NAME}" ]; then
echo ""
echo "${CROSS} ${BOLD}${RED}Error: Binary '${BINARY_NAME}' not found in archive${RESET}" >&2
echo " ${WARN} Archive contents:" >&2
ls -la "${TEMP_DIR}" >&2
rm -rf "${TEMP_DIR}"
exit 1
fi
# Install binary
echo "${INFO} ${BOLD}Installing binary...${RESET}"
$SUDO mv "${BINARY_NAME}" "${BINARY_PATH}"
$SUDO chmod +x "${BINARY_PATH}"
echo " ${CHECK} Binary installed to ${BINARY_PATH}"
if [ "$INSTALL_TUI" = "1" ]; then
if [ -f "nestui" ]; then
NESTUI_PATH="${INSTALL_DIR}/nestui"
$SUDO mv "nestui" "${NESTUI_PATH}"
$SUDO chmod +x "${NESTUI_PATH}"
echo " ${CHECK} Nest UI installed to ${NESTUI_PATH}"
else
echo " ${WARN} 'nestui' binary not found in the archive. Skipping TUI installation."
echo " ${WARN} This release might not include the TUI component."
fi
fi
if [ "$VERSION" != "latest" ]; then
echo " ${CHECK} Installed version: ${BOLD}${VERSION}${RESET}"
fi
# Cleanup
rm -rf "${TEMP_DIR}"
# Check if ~/.local/bin is in PATH and add to all existing shell configs
echo ""
PATH_EXPORT="export PATH=\"\${HOME}/.local/bin:\${PATH}\""
if ! echo "${PATH}" | grep -q "${HOME}/.local/bin"; then
echo "${INFO} ${BOLD}Configuring PATH...${RESET}"
# Add to current session
export PATH="${HOME}/.local/bin:${PATH}"
echo " ${CHECK} Added to PATH for current session"
# Add to all existing shell configuration files
ADDED_TO_CONFIG=0
CONFIG_FILES_ADDED=()
RELOAD_CMDS=()
# Check and add to .zshrc
if [ -f "${HOME}/.zshrc" ]; then
if ! grep -q "${HOME}/.local/bin" "${HOME}/.zshrc" 2>/dev/null; then
echo "" >> "${HOME}/.zshrc"
echo "# Added by Nest CLI installer" >> "${HOME}/.zshrc"
echo "${PATH_EXPORT}" >> "${HOME}/.zshrc"
echo " ${CHECK} Added to ~/.zshrc"
CONFIG_FILES_ADDED+=("~/.zshrc")
RELOAD_CMDS+=("source ~/.zshrc")
ADDED_TO_CONFIG=1
else
echo " ${CHECK} Already in ~/.zshrc"
ADDED_TO_CONFIG=1
fi
fi
# Check and add to .bashrc
if [ -f "${HOME}/.bashrc" ]; then
if ! grep -q "${HOME}/.local/bin" "${HOME}/.bashrc" 2>/dev/null; then
echo "" >> "${HOME}/.bashrc"
echo "# Added by Nest CLI installer" >> "${HOME}/.bashrc"
echo "${PATH_EXPORT}" >> "${HOME}/.bashrc"
echo " ${CHECK} Added to ~/.bashrc"
CONFIG_FILES_ADDED+=("~/.bashrc")
RELOAD_CMDS+=("source ~/.bashrc")
ADDED_TO_CONFIG=1
else
echo " ${CHECK} Already in ~/.bashrc"
ADDED_TO_CONFIG=1
fi
fi
# Check and add to .bash_profile (macOS sometimes uses this)
if [ -f "${HOME}/.bash_profile" ]; then
if ! grep -q "${HOME}/.local/bin" "${HOME}/.bash_profile" 2>/dev/null; then
echo "" >> "${HOME}/.bash_profile"
echo "# Added by Nest CLI installer" >> "${HOME}/.bash_profile"
echo "${PATH_EXPORT}" >> "${HOME}/.bash_profile"
echo " ${CHECK} Added to ~/.bash_profile"
CONFIG_FILES_ADDED+=("~/.bash_profile")
RELOAD_CMDS+=("source ~/.bash_profile")
ADDED_TO_CONFIG=1
else
echo " ${CHECK} Already in ~/.bash_profile"
ADDED_TO_CONFIG=1
fi
fi
# Check and add to fish config
if command -v fish > /dev/null 2>&1; then
FISH_CONFIG_DIR="${HOME}/.config/fish"
FISH_CONFIG_FILE="${FISH_CONFIG_DIR}/config.fish"
if [ -d "${FISH_CONFIG_DIR}" ] || mkdir -p "${FISH_CONFIG_DIR}" 2>/dev/null; then
if [ ! -f "${FISH_CONFIG_FILE}" ]; then
touch "${FISH_CONFIG_FILE}"
fi
if ! grep -q "${HOME}/.local/bin" "${FISH_CONFIG_FILE}" 2>/dev/null; then
echo "" >> "${FISH_CONFIG_FILE}"
echo "# Added by Nest CLI installer" >> "${FISH_CONFIG_FILE}"
echo "set -gx PATH \"\${HOME}/.local/bin\" \$PATH" >> "${FISH_CONFIG_FILE}"
echo " ${CHECK} Added to ~/.config/fish/config.fish"
CONFIG_FILES_ADDED+=("~/.config/fish/config.fish")
RELOAD_CMDS+=("source ~/.config/fish/config.fish")
ADDED_TO_CONFIG=1
else
echo " ${CHECK} Already in ~/.config/fish/config.fish"
ADDED_TO_CONFIG=1
fi
fi
fi
# Check and add to .profile as fallback (if no other configs found)
if [ $ADDED_TO_CONFIG -eq 0 ]; then
PROFILE_FILE="${HOME}/.profile"
if [ -f "${PROFILE_FILE}" ]; then
if ! grep -q "${HOME}/.local/bin" "${PROFILE_FILE}" 2>/dev/null; then
echo "" >> "${PROFILE_FILE}"
echo "# Added by Nest CLI installer" >> "${PROFILE_FILE}"
echo "${PATH_EXPORT}" >> "${PROFILE_FILE}"
echo " ${CHECK} Added to ~/.profile"
CONFIG_FILES_ADDED+=("~/.profile")
RELOAD_CMDS+=("source ~/.profile")
ADDED_TO_CONFIG=1
else
echo " ${CHECK} Already in ~/.profile"
ADDED_TO_CONFIG=1
fi
else
# Create .profile if it doesn't exist and no other configs were found
echo "${PATH_EXPORT}" > "${PROFILE_FILE}"
chmod 644 "${PROFILE_FILE}"
echo " ${CHECK} Created ~/.profile with PATH"
CONFIG_FILES_ADDED+=("~/.profile")
RELOAD_CMDS+=("source ~/.profile")
ADDED_TO_CONFIG=1
fi
fi
if [ $ADDED_TO_CONFIG -eq 1 ]; then
echo ""
if [ ${#CONFIG_FILES_ADDED[@]} -gt 0 ]; then
echo " ${INFO} PATH has been added to:"
for config_file in "${CONFIG_FILES_ADDED[@]}"; do
echo " ${BOLD}${config_file}${RESET}"
done
fi
echo ""
echo " ${INFO} Run one of these commands to reload your shell configuration:"
for reload_cmd in "${RELOAD_CMDS[@]}"; do
echo " ${BOLD}${reload_cmd}${RESET}"
done
echo " ${INFO} Or simply restart your terminal."
else
echo ""
echo " ${WARN} Could not automatically add to shell config."
echo " ${WARN} Please add this line manually to your shell configuration:"
echo " ${BOLD}${GREEN}${PATH_EXPORT}${RESET}"
fi
echo ""
else
echo "${CHECK} ${BOLD}${GREEN}Already in PATH${RESET}"
echo ""
fi
# Success message
echo ""
if [ "$HAS_COLORS" = "1" ]; then
echo "${BOLD}${GREEN}ββββββββββββββββββββββββββββββββββββββββββ${RESET}"
echo "${BOLD}${GREEN}β${RESET} ${CHECK} ${BOLD}Nest CLI installed successfully!${RESET} ${BOLD}${GREEN}β${RESET}"
echo "${BOLD}${GREEN}ββββββββββββββββββββββββββββββββββββββββββ${RESET}"
else
echo "${CHECK} ${BOLD}Nest CLI installed successfully!${RESET}"
echo "========================================"
fi
echo ""
echo " Run ${BOLD}nest --version${RESET} to verify installation."
echo ""