#!/bin/bash
# Generic wrapper template: run a CLI that hardcodes state at $HOME/.<tool>
# on a host where $HOME is read-only. Copy, set the three vars, deploy the
# copy somewhere persistent (e.g. /root/.hermes/bin/<tool>).
#
# How it works: runs the CLI inside a private user+mount namespace where
# $HOME is a tmp dir whose .<tool> is a bind mount of a persistent dir.
# State survives reboots; zero writes to the read-only fs.
# Requires: unshare -rm usable (works as root on this VPS).

TOOL=composio                                   # tool name
PERSIST_DIR=/root/.hermes/${TOOL}-home          # persistent state dir
BIN=/root/.hermes/${TOOL}/${TOOL}               # the real binary

mkdir -p "$PERSIST_DIR"

exec unshare -rm bash -c "
  mkdir -p /tmp/${TOOL}-fakehome/.${TOOL}
  mount --bind '$PERSIST_DIR' /tmp/${TOOL}-fakehome/.${TOOL}
  export HOME=/tmp/${TOOL}-fakehome
  export PATH=$(dirname "$BIN"):\$PATH
  exec '$BIN' \"\$@\"
" -- "$@"
