fix: resolve mcp-hermit cleanup path expansion issue (#5953)
Signed-off-by: sheikhlimon <sheikhlimon404@gmail.com>
This commit is contained in:
@@ -7,10 +7,10 @@ set -euo pipefail
|
|||||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
|
||||||
# Source the common setup script
|
# Source the common setup script
|
||||||
source "$SCRIPT_DIR/node-setup-common.sh"
|
source "${SCRIPT_DIR}/node-setup-common.sh"
|
||||||
|
|
||||||
# Final step: Execute node with passed arguments
|
# Final step: Execute node with passed arguments
|
||||||
log "Executing 'node' command with arguments: $*"
|
log "Executing 'node' command with arguments: ${*}"
|
||||||
node "$@" || log "Failed to execute 'node' with arguments: $*"
|
node "${@}" || log "Failed to execute 'node' with arguments: ${*}"
|
||||||
|
|
||||||
log "node script completed successfully."
|
log "node script completed successfully."
|
||||||
|
|||||||
@@ -10,12 +10,12 @@ set -euo pipefail
|
|||||||
LOG_FILE="/tmp/mcp.log"
|
LOG_FILE="/tmp/mcp.log"
|
||||||
|
|
||||||
# Clear the log file at the start
|
# Clear the log file at the start
|
||||||
> "$LOG_FILE"
|
> "${LOG_FILE}"
|
||||||
|
|
||||||
# Function for logging
|
# Function for logging
|
||||||
log() {
|
log() {
|
||||||
local MESSAGE="$1"
|
local MESSAGE="${1}"
|
||||||
echo "$(date +'%Y-%m-%d %H:%M:%S') - $MESSAGE" | tee -a "$LOG_FILE" >&2
|
echo "$(date +'%Y-%m-%d %H:%M:%S') - ${MESSAGE}" | tee -a "${LOG_FILE}" >&2
|
||||||
}
|
}
|
||||||
|
|
||||||
# Trap errors and log them before exiting
|
# Trap errors and log them before exiting
|
||||||
@@ -24,31 +24,31 @@ trap 'log "An error occurred. Exiting with status $?."' ERR
|
|||||||
log "Starting node setup (common)."
|
log "Starting node setup (common)."
|
||||||
|
|
||||||
# One-time cleanup for existing Linux users to fix locking issues
|
# One-time cleanup for existing Linux users to fix locking issues
|
||||||
CLEANUP_MARKER=${HOME}/.config/goose/.mcp-hermit-cleanup-v1
|
CLEANUP_MARKER="${HOME}/.config/goose/.mcp-hermit-cleanup-v1"
|
||||||
if [[ "$(uname -s)" == "Linux" ]] && [ ! -f "$CLEANUP_MARKER" ]; then
|
if [[ "$(uname -s)" == "Linux" ]] && [ ! -f "${CLEANUP_MARKER}" ]; then
|
||||||
log "Performing one-time cleanup of old mcp-hermit directory to fix locking issues."
|
log "Performing one-time cleanup of old mcp-hermit directory to fix locking issues."
|
||||||
if [ -d ${HOME}/.config/goose/mcp-hermit ]; then
|
if [ -d "${HOME}/.config/goose/mcp-hermit" ]; then
|
||||||
rm -rf ${HOME}/.config/goose/mcp-hermit
|
rm -rf "${HOME}/.config/goose/mcp-hermit"
|
||||||
log "Removed old mcp-hermit directory."
|
log "Removed old mcp-hermit directory."
|
||||||
fi
|
fi
|
||||||
touch "$CLEANUP_MARKER"
|
touch "${CLEANUP_MARKER}"
|
||||||
log "Cleanup completed. Marker file created."
|
log "Cleanup completed. Marker file created."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Ensure ${HOME}/.config/goose/mcp-hermit/bin exists
|
# Ensure ${HOME}/.config/goose/mcp-hermit/bin exists
|
||||||
log "Creating directory ${HOME}/.config/goose/mcp-hermit/bin if it does not exist."
|
log "Creating directory ${HOME}/.config/goose/mcp-hermit/bin if it does not exist."
|
||||||
mkdir -p ${HOME}/.config/goose/mcp-hermit/bin
|
mkdir -p "${HOME}/.config/goose/mcp-hermit/bin"
|
||||||
|
|
||||||
# Change to the ${HOME}/.config/goose/mcp-hermit directory
|
# Change to the ${HOME}/.config/goose/mcp-hermit directory
|
||||||
log "Changing to directory ${HOME}/.config/goose/mcp-hermit."
|
log "Changing to directory ${HOME}/.config/goose/mcp-hermit."
|
||||||
cd ${HOME}/.config/goose/mcp-hermit
|
cd "${HOME}/.config/goose/mcp-hermit"
|
||||||
|
|
||||||
|
|
||||||
# Check if hermit binary exists and download if not
|
# Check if hermit binary exists and download if not
|
||||||
if [ ! -f ${HOME}/.config/goose/mcp-hermit/bin/hermit ]; then
|
if [ ! -f "${HOME}/.config/goose/mcp-hermit/bin/hermit" ]; then
|
||||||
log "Hermit binary not found. Downloading hermit binary."
|
log "Hermit binary not found. Downloading hermit binary."
|
||||||
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" \
|
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" \
|
||||||
| gzip -dc > ${HOME}/.config/goose/mcp-hermit/bin/hermit && chmod +x ${HOME}/.config/goose/mcp-hermit/bin/hermit
|
| gzip -dc > "${HOME}/.config/goose/mcp-hermit/bin/hermit" && chmod +x "${HOME}/.config/goose/mcp-hermit/bin/hermit"
|
||||||
log "Hermit binary downloaded and made executable."
|
log "Hermit binary downloaded and made executable."
|
||||||
else
|
else
|
||||||
log "Hermit binary already exists. Skipping download."
|
log "Hermit binary already exists. Skipping download."
|
||||||
@@ -56,42 +56,42 @@ fi
|
|||||||
|
|
||||||
|
|
||||||
log "setting hermit cache to be local for MCP servers"
|
log "setting hermit cache to be local for MCP servers"
|
||||||
mkdir -p ${HOME}/.config/goose/mcp-hermit/cache
|
mkdir -p "${HOME}/.config/goose/mcp-hermit/cache"
|
||||||
export HERMIT_STATE_DIR=${HOME}/.config/goose/mcp-hermit/cache
|
export HERMIT_STATE_DIR="${HOME}/.config/goose/mcp-hermit/cache"
|
||||||
|
|
||||||
|
|
||||||
# Update PATH
|
# Update PATH
|
||||||
export PATH=${HOME}/.config/goose/mcp-hermit/bin:$PATH
|
export PATH="${HOME}/.config/goose/mcp-hermit/bin:${PATH}"
|
||||||
log "Updated PATH to include ${HOME}/.config/goose/mcp-hermit/bin."
|
log "Updated PATH to include ${HOME}/.config/goose/mcp-hermit/bin."
|
||||||
|
|
||||||
|
|
||||||
# Verify hermit installation
|
# Verify hermit installation
|
||||||
log "Checking for hermit in PATH."
|
log "Checking for hermit in PATH."
|
||||||
which hermit >> "$LOG_FILE"
|
which hermit >> "${LOG_FILE}"
|
||||||
|
|
||||||
# Check if hermit environment is already initialized (only run init on first setup)
|
# Check if hermit environment is already initialized (only run init on first setup)
|
||||||
if [ ! -f bin/activate-hermit ]; then
|
if [ ! -f "bin/activate-hermit" ]; then
|
||||||
log "Hermit environment not yet initialized. Setting up hermit."
|
log "Hermit environment not yet initialized. Setting up hermit."
|
||||||
|
|
||||||
# Fix hermit self-update lock issues on Linux by using temp binary for init only
|
# Fix hermit self-update lock issues on Linux by using temp binary for init only
|
||||||
if [[ "$(uname -s)" == "Linux" ]]; then
|
if [[ "$(uname -s)" == "Linux" ]]; then
|
||||||
log "Creating temp dir with bin subdirectory for hermit copy to avoid self-update locks."
|
log "Creating temp dir with bin subdirectory for hermit copy to avoid self-update locks."
|
||||||
HERMIT_TMP_DIR="/tmp/hermit_tmp_$$/bin"
|
HERMIT_TMP_DIR="/tmp/hermit_tmp_$$/bin"
|
||||||
mkdir -p "$HERMIT_TMP_DIR"
|
mkdir -p "${HERMIT_TMP_DIR}"
|
||||||
cp ${HOME}/.config/goose/mcp-hermit/bin/hermit "$HERMIT_TMP_DIR/hermit"
|
cp "${HOME}/.config/goose/mcp-hermit/bin/hermit" "${HERMIT_TMP_DIR}/hermit"
|
||||||
chmod +x "$HERMIT_TMP_DIR/hermit"
|
chmod +x "${HERMIT_TMP_DIR}/hermit"
|
||||||
export PATH="$HERMIT_TMP_DIR:$PATH"
|
export PATH="${HERMIT_TMP_DIR}:${PATH}"
|
||||||
HERMIT_CLEANUP_DIR="/tmp/hermit_tmp_$$"
|
HERMIT_CLEANUP_DIR="/tmp/hermit_tmp_$$"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Initialize hermit
|
# Initialize hermit
|
||||||
log "Initializing hermit."
|
log "Initializing hermit."
|
||||||
hermit init >> "$LOG_FILE"
|
hermit init >> "${LOG_FILE}"
|
||||||
|
|
||||||
# Clean up temp dir if it was created
|
# Clean up temp dir if it was created
|
||||||
if [[ -n "${HERMIT_CLEANUP_DIR:-}" ]]; then
|
if [[ -n "${HERMIT_CLEANUP_DIR:-}" ]]; then
|
||||||
log "Cleaning up temporary hermit binary directory."
|
log "Cleaning up temporary hermit binary directory."
|
||||||
rm -rf "$HERMIT_CLEANUP_DIR"
|
rm -rf "${HERMIT_CLEANUP_DIR}"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
log "Hermit environment already initialized. Skipping init."
|
log "Hermit environment already initialized. Skipping init."
|
||||||
@@ -100,12 +100,12 @@ fi
|
|||||||
# Activate the environment with output redirected to log
|
# Activate the environment with output redirected to log
|
||||||
if [[ "$(uname -s)" == "Linux" ]]; then
|
if [[ "$(uname -s)" == "Linux" ]]; then
|
||||||
log "Activating hermit environment."
|
log "Activating hermit environment."
|
||||||
{ . bin/activate-hermit; } >> "$LOG_FILE" 2>&1
|
{ . "bin/activate-hermit"; } >> "${LOG_FILE}" 2>&1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Install Node.js using hermit
|
# Install Node.js using hermit
|
||||||
log "Installing Node.js with hermit."
|
log "Installing Node.js with hermit."
|
||||||
hermit install node >> "$LOG_FILE"
|
hermit install node >> "${LOG_FILE}"
|
||||||
|
|
||||||
# Verify installations
|
# Verify installations
|
||||||
log "Verifying installation locations:"
|
log "Verifying installation locations:"
|
||||||
@@ -116,18 +116,18 @@ log "npx: $(which npx)"
|
|||||||
|
|
||||||
log "Checking for GOOSE_NPM_REGISTRY and GOOSE_NPM_CERT environment variables for custom npm registry setup..."
|
log "Checking for GOOSE_NPM_REGISTRY and GOOSE_NPM_CERT environment variables for custom npm registry setup..."
|
||||||
# Check if GOOSE_NPM_REGISTRY is set and accessible
|
# Check if GOOSE_NPM_REGISTRY is set and accessible
|
||||||
if [ -n "${GOOSE_NPM_REGISTRY:-}" ] && curl -s --head --fail "$GOOSE_NPM_REGISTRY" > /dev/null; then
|
if [ -n "${GOOSE_NPM_REGISTRY:-}" ] && curl -s --head --fail "${GOOSE_NPM_REGISTRY}" > /dev/null; then
|
||||||
log "Checking custom goose registry availability: $GOOSE_NPM_REGISTRY"
|
log "Checking custom goose registry availability: ${GOOSE_NPM_REGISTRY}"
|
||||||
log "$GOOSE_NPM_REGISTRY is accessible. Using it for npm registry."
|
log "${GOOSE_NPM_REGISTRY} is accessible. Using it for npm registry."
|
||||||
export NPM_CONFIG_REGISTRY="$GOOSE_NPM_REGISTRY"
|
export NPM_CONFIG_REGISTRY="${GOOSE_NPM_REGISTRY}"
|
||||||
|
|
||||||
# Check if GOOSE_NPM_CERT is set and accessible
|
# Check if GOOSE_NPM_CERT is set and accessible
|
||||||
if [ -n "${GOOSE_NPM_CERT:-}" ] && curl -s --head --fail "$GOOSE_NPM_CERT" > /dev/null; then
|
if [ -n "${GOOSE_NPM_CERT:-}" ] && curl -s --head --fail "${GOOSE_NPM_CERT}" > /dev/null; then
|
||||||
log "Downloading certificate from: $GOOSE_NPM_CERT"
|
log "Downloading certificate from: ${GOOSE_NPM_CERT}"
|
||||||
curl -sSL -o ${HOME}/.config/goose/mcp-hermit/cert.pem "$GOOSE_NPM_CERT"
|
curl -sSL -o "${HOME}/.config/goose/mcp-hermit/cert.pem" "${GOOSE_NPM_CERT}"
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
log "Certificate downloaded successfully."
|
log "Certificate downloaded successfully."
|
||||||
export NODE_EXTRA_CA_CERTS=${HOME}/.config/goose/mcp-hermit/cert.pem
|
export NODE_EXTRA_CA_CERTS="${HOME}/.config/goose/mcp-hermit/cert.pem"
|
||||||
else
|
else
|
||||||
log "Unable to download the certificate. Skipping certificate setup."
|
log "Unable to download the certificate. Skipping certificate setup."
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -7,10 +7,10 @@ set -euo pipefail
|
|||||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
|
||||||
# Source the common setup script
|
# Source the common setup script
|
||||||
source "$SCRIPT_DIR/node-setup-common.sh"
|
source "${SCRIPT_DIR}/node-setup-common.sh"
|
||||||
|
|
||||||
# Final step: Execute npx with passed arguments
|
# Final step: Execute npx with passed arguments
|
||||||
log "Executing 'npx' command with arguments: $*"
|
log "Executing 'npx' command with arguments: ${*}"
|
||||||
npx "$@" || log "Failed to execute 'npx' with arguments: $*"
|
npx "${@}" || log "Failed to execute 'npx' with arguments: ${*}"
|
||||||
|
|
||||||
log "npx script completed successfully."
|
log "npx script completed successfully."
|
||||||
|
|||||||
Reference in New Issue
Block a user