#!/bin/bash
# Mount-namespace wrapper for tools that hardcode config paths under $HOME,
# for use on hosts where $HOME is a read-only mount (verified on the Hostinger
# VPS with /root read-only). Runs the tool in a private mount namespace where
# a fake $HOME's config dir is bind-mounted to persistent storage.
#
# Verified with: Composio CLI v0.2.32 (hardcodes $HOME/.composio).
#
# Usage: copy to /root/.hermes/bin/<tool>, chmod +x, edit the three vars below.
# Install the wrapper AT THE TOOL'S NAME so all callers get it transparently.

PERSIST_DIR=/root/.hermes/TOOLNAME-home          # persistent config storage
BIN=/root/.hermes/TOOLNAME/TOOLNAME              # real binary location
CONFIG_SUBDIR=.TOOLNAME                          # dir the tool creates under $HOME

mkdir -p "$PERSIST_DIR"

exec unshare -rm bash -c "
  mkdir -p /tmp/TOOLNAME-fakehome/'$CONFIG_SUBDIR'
  mount --bind '$PERSIST_DIR' /tmp/TOOLNAME-fakehome/'$CONFIG_SUBDIR'
  export HOME=/tmp/TOOLNAME-fakehome
  exec '$BIN' \"\$@\"
" -- "$@"
