Skip to content

Commit cc12d71

Browse files
committed
Make gum install mostly silent by default, try to handle all the exit points somewhat gracefully.
1 parent a423df5 commit cc12d71

File tree

1 file changed

+62
-8
lines changed

1 file changed

+62
-8
lines changed

install.sh

Lines changed: 62 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,26 @@
11
#!/bin/bash
22

3+
# Initialize verbose flag
4+
VERBOSE=false
5+
6+
# Process command line arguments
7+
while getopts "v" opt; do
8+
case $opt in
9+
v) VERBOSE=true ;;
10+
*) echo "Usage: $0 [-v]" >&2
11+
exit 1 ;;
12+
esac
13+
done
14+
15+
# Helper function for verbose logging
16+
log() {
17+
if [ "$VERBOSE" = true ]; then
18+
echo "$1"
19+
fi
20+
}
21+
322
check_prerequisites() {
4-
echo "Checking prerequisites..."
23+
log "Checking prerequisites..."
524

625
# Check if Docker is installed
726
if ! command -v docker &> /dev/null; then
@@ -18,15 +37,15 @@ check_prerequisites() {
1837
exit 1
1938
fi
2039

21-
echo "Prerequisites check passed. Docker and Docker Compose are installed."
40+
log "Prerequisites check passed. Docker and Docker Compose are installed."
2241
}
2342

2443
install_gum() {
25-
echo "Installing gum..."
44+
log "Installing gum..."
2645

2746
# Check if gum is already installed
2847
if command -v gum &> /dev/null; then
29-
echo "gum is already installed."
48+
log "gum is already installed."
3049
return
3150
fi
3251

@@ -72,17 +91,17 @@ gpgkey=https://repo.charm.sh/yum/gpg.key' | sudo tee /etc/zypp/repos.d/charm.rep
7291
# Arch Linux
7392
sudo pacman -S gum
7493
else
75-
echo "Unsupported Linux distribution. Attempting to install using Go..."
94+
log "Unsupported Linux distribution. Attempting to install using Go..."
7695
install_using_go
7796
fi
7897
else
79-
echo "Unsupported operating system. Attempting to install using Go..."
98+
log "Unsupported operating system. Attempting to install using Go..."
8099
install_using_go
81100
fi
82101

83102
# Verify installation
84103
if command -v gum &> /dev/null; then
85-
echo "gum has been successfully installed."
104+
log "gum has been successfully installed."
86105
else
87106
echo "Failed to install gum. Please try manual installation."
88107
exit 1
@@ -191,7 +210,8 @@ setup_ai_provider() {
191210
[ "$is_password" = "true" ] && input_args+=(--password)
192211

193212
# Only return the actual input value
194-
gum input "${input_args[@]}"
213+
LOCAL_OUT=`gum input "${input_args[@]}"`
214+
echo "$LOCAL_OUT"
195215
}
196216

197217
# Reusable function to write to .env
@@ -217,6 +237,8 @@ setup_ai_provider() {
217237
if gum confirm "Use existing $provider API key?"; then
218238
SELECTED_ENV_VARS="$SELECTED_ENV_VARS $env_var=${!env_var}"
219239
gum style --foreground="#00FF00" "✓ Using existing $provider configuration"
240+
elif test $? -eq 130; then
241+
exit 0
220242
fi
221243
fi
222244
done
@@ -227,6 +249,10 @@ setup_ai_provider() {
227249
style_header "Provider Selection"
228250
ACTION=$(gum choose "Add provider" "Complete setup")
229251

252+
[ "$ACTION" = "" ] && exit 0
253+
254+
echo "$ACTION"
255+
230256
[ "$ACTION" = "Complete setup" ] && break
231257

232258
# Filter available providers
@@ -245,9 +271,22 @@ setup_ai_provider() {
245271

246272
# Get provider selection and API key
247273
SELECTED_PROVIDER=$(gum choose --height 10 "${AVAILABLE_PROVIDERS[@]}")
274+
# Handle cancel/ctl-c
275+
[ "$SELECTED_PROVIDER" = "" ] && exit 0
248276
ENV_VAR=$(get_env_var_name "$SELECTED_PROVIDER")
249277
API_KEY=$(get_input "Enter your $SELECTED_PROVIDER API key" "" "true" "Enter API key")
250278

279+
# Handle empty API key by asking if they want to exit
280+
if [ -z "$API_KEY" ]; then
281+
if gum confirm "API key is empty. Do you want to exit?"; then
282+
exit 0
283+
elif test $? -eq 130; then
284+
exit 0
285+
else
286+
continue
287+
fi
288+
fi
289+
251290
SELECTED_ENV_VARS="$SELECTED_ENV_VARS $ENV_VAR=$API_KEY"
252291
gum style --foreground="#00FF00" "✓ Added $SELECTED_PROVIDER configuration"
253292
done
@@ -258,6 +297,17 @@ setup_ai_provider() {
258297
echo "You can use the default value or set a custom value. Press Enter to use the default value of 'p@55wOrd'."
259298
# Get Auth Secret
260299
AUTH_SECRET=$(get_input "Set your Auth Secret" "p@55wOrd" "true" "Enter Auth Secret")
300+
301+
# Handle empty Auth Secret by asking if they want to exit
302+
if [ -z "$AUTH_SECRET" ]; then
303+
if gum confirm "Auth Secret is empty. Do you want to exit?"; then
304+
exit 0
305+
elif test $? -eq 130; then
306+
exit 0
307+
else
308+
AUTH_SECRET="p@55wOrd"
309+
fi
310+
fi
261311

262312
# Save configuration
263313
echo "$SELECTED_ENV_VARS" | tr ' ' '\n' | while read -r env_setting; do
@@ -313,6 +363,8 @@ setup_ai_provider() {
313363
gum style --foreground="#FF0000" "Error: Could not find agent-comfy/install.sh"
314364
exit 1
315365
fi
366+
elif test $? -eq 130; then
367+
exit 0
316368
fi
317369

318370
# Open browser based on OS
@@ -323,6 +375,8 @@ setup_ai_provider() {
323375
else
324376
gum style --foreground="#CCCCCC" "Please open http://localhost:5006 in your browser"
325377
fi
378+
elif test $? -eq 130; then
379+
exit 0
326380
else
327381
gum style --foreground="#CCCCCC" "AI Server not started. Run later with 'docker compose up -d'"
328382
fi

0 commit comments

Comments
 (0)