Skip to content

Commit 19befb6

Browse files
authored
added jbang back (aaif-goose#3076)
accidentally deleted restore
1 parent 85f284b commit 19befb6

1 file changed

Lines changed: 89 additions & 0 deletions

File tree

ui/desktop/src/bin/jbang

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#!/bin/bash
2+
3+
# Enable strict mode to exit on errors and unset variables
4+
set -euo pipefail
5+
6+
# Set log file
7+
LOG_FILE="/tmp/mcp.log"
8+
9+
# Clear the log file at the start
10+
> "$LOG_FILE"
11+
12+
# Function for logging
13+
log() {
14+
local MESSAGE="$1"
15+
echo "$(date +'%Y-%m-%d %H:%M:%S') - $MESSAGE" | tee -a "$LOG_FILE"
16+
}
17+
18+
# Trap errors and log them before exiting
19+
trap 'log "An error occurred. Exiting with status $?."' ERR
20+
21+
log "Starting jbang setup script."
22+
23+
# Ensure ~/.config/goose/mcp-hermit/bin exists
24+
log "Creating directory ~/.config/goose/mcp-hermit/bin if it does not exist."
25+
mkdir -p ~/.config/goose/mcp-hermit/bin
26+
27+
# Change to the ~/.config/goose/mcp-hermit directory
28+
log "Changing to directory ~/.config/goose/mcp-hermit."
29+
cd ~/.config/goose/mcp-hermit
30+
31+
# Check if hermit binary exists and download if not
32+
if [ ! -f ~/.config/goose/mcp-hermit/bin/hermit ]; then
33+
log "Hermit binary not found. Downloading hermit binary."
34+
curl -fsSL "https://github.com/cashapp/hermit/releases/download/stable/hermit-$(uname -s | tr '[:upper:]' '[:lower:]')-$(uname -m | sed 's/x86_64/amd64/' | sed 's/aarch64/arm64/').gz" \
35+
| gzip -dc > ~/.config/goose/mcp-hermit/bin/hermit && chmod +x ~/.config/goose/mcp-hermit/bin/hermit
36+
log "Hermit binary downloaded and made executable."
37+
else
38+
log "Hermit binary already exists. Skipping download."
39+
fi
40+
41+
log "setting hermit cache to be local for MCP servers"
42+
mkdir -p ~/.config/goose/mcp-hermit/cache
43+
export HERMIT_STATE_DIR=~/.config/goose/mcp-hermit/cache
44+
45+
# Update PATH
46+
export PATH=~/.config/goose/mcp-hermit/bin:$PATH
47+
log "Updated PATH to include ~/.config/goose/mcp-hermit/bin."
48+
49+
# Initialize hermit
50+
log "Initializing hermit."
51+
hermit init >> "$LOG_FILE"
52+
53+
# Install OpenJDK using hermit
54+
log "Installing OpenJDK with hermit."
55+
hermit install openjdk@17 >> "$LOG_FILE"
56+
57+
# Download and install jbang if not present
58+
if [ ! -f ~/.config/goose/mcp-hermit/bin/jbang ]; then
59+
log "Downloading and installing jbang."
60+
curl -Ls https://sh.jbang.dev | bash -s - app setup
61+
cp ~/.jbang/bin/jbang ~/.config/goose/mcp-hermit/bin/
62+
fi
63+
64+
# Verify installations
65+
log "Verifying installation locations:"
66+
log "hermit: $(which hermit)"
67+
log "java: $(which java)"
68+
log "jbang: $(which jbang)"
69+
70+
# Check for custom registry settings
71+
log "Checking for GOOSE_JBANG_REGISTRY environment variable for custom jbang registry setup..."
72+
if [ -n "${GOOSE_JBANG_REGISTRY:-}" ] && curl -s --head --fail "$GOOSE_JBANG_REGISTRY" > /dev/null; then
73+
log "Checking custom goose registry availability: $GOOSE_JBANG_REGISTRY"
74+
log "$GOOSE_JBANG_REGISTRY is accessible. Setting it as JBANG_REPO."
75+
export JBANG_REPO="$GOOSE_JBANG_REGISTRY"
76+
else
77+
log "GOOSE_JBANG_REGISTRY is not set or not accessible. Using default jbang repository."
78+
fi
79+
80+
# Trust all jbang scripts that a user might install. Without this, Jbang will attempt to
81+
# prompt the user to trust each script. However, Goose does not surfact this modal and without
82+
# user input, the addExtension method will timeout and fail.
83+
jbang --quiet trust add *
84+
85+
# Final step: Execute jbang with passed arguments, always including --fresh and --quiet
86+
log "Executing 'jbang' command with arguments: $*"
87+
jbang --fresh --quiet "$@" || log "Failed to execute 'jbang' with arguments: $*"
88+
89+
log "jbang setup script completed successfully."

0 commit comments

Comments
 (0)