Skip to content

Commit bea7639

Browse files
committed
fix: resolve mcp-hermit cleanup path expansion issue
Signed-off-by: sheikhlimon <[email protected]>
1 parent 5d53643 commit bea7639

File tree

3 files changed

+41
-41
lines changed

3 files changed

+41
-41
lines changed

ui/desktop/src/bin/node

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ set -euo pipefail
77
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
88

99
# Source the common setup script
10-
source "$SCRIPT_DIR/node-setup-common.sh"
10+
source "${SCRIPT_DIR}/node-setup-common.sh"
1111

1212
# Final step: Execute node with passed arguments
13-
log "Executing 'node' command with arguments: $*"
14-
node "$@" || log "Failed to execute 'node' with arguments: $*"
13+
log "Executing 'node' command with arguments: ${*}"
14+
node "${@}" || log "Failed to execute 'node' with arguments: ${*}"
1515

1616
log "node script completed successfully."

ui/desktop/src/bin/node-setup-common.sh

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ set -euo pipefail
1010
LOG_FILE="/tmp/mcp.log"
1111

1212
# Clear the log file at the start
13-
> "$LOG_FILE"
13+
> "${LOG_FILE}"
1414

1515
# Function for logging
1616
log() {
17-
local MESSAGE="$1"
18-
echo "$(date +'%Y-%m-%d %H:%M:%S') - $MESSAGE" | tee -a "$LOG_FILE" >&2
17+
local MESSAGE="${1}"
18+
echo "$(date +'%Y-%m-%d %H:%M:%S') - ${MESSAGE}" | tee -a "${LOG_FILE}" >&2
1919
}
2020

2121
# Trap errors and log them before exiting
@@ -24,74 +24,74 @@ trap 'log "An error occurred. Exiting with status $?."' ERR
2424
log "Starting node setup (common)."
2525

2626
# One-time cleanup for existing Linux users to fix locking issues
27-
CLEANUP_MARKER=${HOME}/.config/goose/.mcp-hermit-cleanup-v1
28-
if [[ "$(uname -s)" == "Linux" ]] && [ ! -f "$CLEANUP_MARKER" ]; then
27+
CLEANUP_MARKER="${HOME}/.config/goose/.mcp-hermit-cleanup-v1"
28+
if [[ "$(uname -s)" == "Linux" ]] && [ ! -f "${CLEANUP_MARKER}" ]; then
2929
log "Performing one-time cleanup of old mcp-hermit directory to fix locking issues."
30-
if [ -d ${HOME}/.config/goose/mcp-hermit ]; then
31-
rm -rf ${HOME}/.config/goose/mcp-hermit
30+
if [ -d "${HOME}/.config/goose/mcp-hermit" ]; then
31+
rm -rf "${HOME}/.config/goose/mcp-hermit"
3232
log "Removed old mcp-hermit directory."
3333
fi
34-
touch "$CLEANUP_MARKER"
34+
touch "${CLEANUP_MARKER}"
3535
log "Cleanup completed. Marker file created."
3636
fi
3737

3838
# Ensure ${HOME}/.config/goose/mcp-hermit/bin exists
3939
log "Creating directory ${HOME}/.config/goose/mcp-hermit/bin if it does not exist."
40-
mkdir -p ${HOME}/.config/goose/mcp-hermit/bin
40+
mkdir -p "${HOME}/.config/goose/mcp-hermit/bin"
4141

4242
# Change to the ${HOME}/.config/goose/mcp-hermit directory
4343
log "Changing to directory ${HOME}/.config/goose/mcp-hermit."
44-
cd ${HOME}/.config/goose/mcp-hermit
44+
cd "${HOME}/.config/goose/mcp-hermit"
4545

4646

4747
# Check if hermit binary exists and download if not
48-
if [ ! -f ${HOME}/.config/goose/mcp-hermit/bin/hermit ]; then
48+
if [ ! -f "${HOME}/.config/goose/mcp-hermit/bin/hermit" ]; then
4949
log "Hermit binary not found. Downloading hermit binary."
5050
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" \
51-
| gzip -dc > ${HOME}/.config/goose/mcp-hermit/bin/hermit && chmod +x ${HOME}/.config/goose/mcp-hermit/bin/hermit
51+
| gzip -dc > "${HOME}/.config/goose/mcp-hermit/bin/hermit" && chmod +x "${HOME}/.config/goose/mcp-hermit/bin/hermit"
5252
log "Hermit binary downloaded and made executable."
5353
else
5454
log "Hermit binary already exists. Skipping download."
5555
fi
5656

5757

5858
log "setting hermit cache to be local for MCP servers"
59-
mkdir -p ${HOME}/.config/goose/mcp-hermit/cache
60-
export HERMIT_STATE_DIR=${HOME}/.config/goose/mcp-hermit/cache
59+
mkdir -p "${HOME}/.config/goose/mcp-hermit/cache"
60+
export HERMIT_STATE_DIR="${HOME}/.config/goose/mcp-hermit/cache"
6161

6262

6363
# Update PATH
64-
export PATH=${HOME}/.config/goose/mcp-hermit/bin:$PATH
64+
export PATH="${HOME}/.config/goose/mcp-hermit/bin:$PATH"
6565
log "Updated PATH to include ${HOME}/.config/goose/mcp-hermit/bin."
6666

6767

6868
# Verify hermit installation
6969
log "Checking for hermit in PATH."
70-
which hermit >> "$LOG_FILE"
70+
which hermit >> "${LOG_FILE}"
7171

7272
# Check if hermit environment is already initialized (only run init on first setup)
73-
if [ ! -f bin/activate-hermit ]; then
73+
if [ ! -f "bin/activate-hermit" ]; then
7474
log "Hermit environment not yet initialized. Setting up hermit."
7575

7676
# Fix hermit self-update lock issues on Linux by using temp binary for init only
7777
if [[ "$(uname -s)" == "Linux" ]]; then
7878
log "Creating temp dir with bin subdirectory for hermit copy to avoid self-update locks."
79-
HERMIT_TMP_DIR="/tmp/hermit_tmp_$$/bin"
80-
mkdir -p "$HERMIT_TMP_DIR"
81-
cp ${HOME}/.config/goose/mcp-hermit/bin/hermit "$HERMIT_TMP_DIR/hermit"
82-
chmod +x "$HERMIT_TMP_DIR/hermit"
83-
export PATH="$HERMIT_TMP_DIR:$PATH"
84-
HERMIT_CLEANUP_DIR="/tmp/hermit_tmp_$$"
79+
HERMIT_TMP_DIR="/tmp/hermit_tmp_${$}/bin"
80+
mkdir -p "${HERMIT_TMP_DIR}"
81+
cp "${HOME}/.config/goose/mcp-hermit/bin/hermit" "${HERMIT_TMP_DIR}/hermit"
82+
chmod +x "${HERMIT_TMP_DIR}/hermit"
83+
export PATH="${HERMIT_TMP_DIR}:${PATH}"
84+
HERMIT_CLEANUP_DIR="/tmp/hermit_tmp_${$}"
8585
fi
8686

8787
# Initialize hermit
8888
log "Initializing hermit."
89-
hermit init >> "$LOG_FILE"
89+
hermit init >> "${LOG_FILE}"
9090

9191
# Clean up temp dir if it was created
9292
if [[ -n "${HERMIT_CLEANUP_DIR:-}" ]]; then
9393
log "Cleaning up temporary hermit binary directory."
94-
rm -rf "$HERMIT_CLEANUP_DIR"
94+
rm -rf "${HERMIT_CLEANUP_DIR}"
9595
fi
9696
else
9797
log "Hermit environment already initialized. Skipping init."
@@ -100,12 +100,12 @@ fi
100100
# Activate the environment with output redirected to log
101101
if [[ "$(uname -s)" == "Linux" ]]; then
102102
log "Activating hermit environment."
103-
{ . bin/activate-hermit; } >> "$LOG_FILE" 2>&1
103+
{ . "bin/activate-hermit"; } >> "${LOG_FILE}" 2>&1
104104
fi
105105

106106
# Install Node.js using hermit
107107
log "Installing Node.js with hermit."
108-
hermit install node >> "$LOG_FILE"
108+
hermit install node >> "${LOG_FILE}"
109109

110110
# Verify installations
111111
log "Verifying installation locations:"
@@ -116,18 +116,18 @@ log "npx: $(which npx)"
116116

117117
log "Checking for GOOSE_NPM_REGISTRY and GOOSE_NPM_CERT environment variables for custom npm registry setup..."
118118
# Check if GOOSE_NPM_REGISTRY is set and accessible
119-
if [ -n "${GOOSE_NPM_REGISTRY:-}" ] && curl -s --head --fail "$GOOSE_NPM_REGISTRY" > /dev/null; then
120-
log "Checking custom goose registry availability: $GOOSE_NPM_REGISTRY"
121-
log "$GOOSE_NPM_REGISTRY is accessible. Using it for npm registry."
122-
export NPM_CONFIG_REGISTRY="$GOOSE_NPM_REGISTRY"
119+
if [ -n "${GOOSE_NPM_REGISTRY:-}" ] && curl -s --head --fail "${GOOSE_NPM_REGISTRY}" > "/dev/null"; then
120+
log "Checking custom goose registry availability: ${GOOSE_NPM_REGISTRY}"
121+
log "${GOOSE_NPM_REGISTRY} is accessible. Using it for npm registry."
122+
export NPM_CONFIG_REGISTRY="${GOOSE_NPM_REGISTRY}"
123123

124124
# Check if GOOSE_NPM_CERT is set and accessible
125-
if [ -n "${GOOSE_NPM_CERT:-}" ] && curl -s --head --fail "$GOOSE_NPM_CERT" > /dev/null; then
126-
log "Downloading certificate from: $GOOSE_NPM_CERT"
127-
curl -sSL -o ${HOME}/.config/goose/mcp-hermit/cert.pem "$GOOSE_NPM_CERT"
125+
if [ -n "${GOOSE_NPM_CERT:-}" ] && curl -s --head --fail "${GOOSE_NPM_CERT}" > "/dev/null"; then
126+
log "Downloading certificate from: ${GOOSE_NPM_CERT}"
127+
curl -sSL -o "${HOME}/.config/goose/mcp-hermit/cert.pem" "${GOOSE_NPM_CERT}"
128128
if [ $? -eq 0 ]; then
129129
log "Certificate downloaded successfully."
130-
export NODE_EXTRA_CA_CERTS=${HOME}/.config/goose/mcp-hermit/cert.pem
130+
export NODE_EXTRA_CA_CERTS="${HOME}/.config/goose/mcp-hermit/cert.pem"
131131
else
132132
log "Unable to download the certificate. Skipping certificate setup."
133133
fi

ui/desktop/src/bin/npx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ set -euo pipefail
77
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
88

99
# Source the common setup script
10-
source "$SCRIPT_DIR/node-setup-common.sh"
10+
source "${SCRIPT_DIR}/node-setup-common.sh"
1111

1212
# Final step: Execute npx with passed arguments
13-
log "Executing 'npx' command with arguments: $*"
14-
npx "$@" || log "Failed to execute 'npx' with arguments: $*"
13+
log "Executing 'npx' command with arguments: ${*}"
14+
npx "${@}" || log "Failed to execute 'npx' with arguments: ${*}"
1515

1616
log "npx script completed successfully."

0 commit comments

Comments
 (0)