Files
supermarket/bin/supermarket
T
davidandClaude Opus 5.5 7a857c7346 Phase 9, part 1: editions and their settings
SUPERMARKET_MODE picks local (the default), server or multi. internal/config
reads and checks every setting the editions need (database, secret key,
storage, the app's own mail, an https address), reporting all problems at
once. supermarket config prints them without passwords; supermarket
secret-key makes a key. Settings -> About shows the edition. Server and
multi-tenant are checked but refuse to start until they're built.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 06:55:30 -07:00

107 lines
3.3 KiB
Bash
Executable File

#!/bin/bash
#
# Purpose : Open and manage Supermarket's container.
DATA="${XDG_DATA_HOME:-$HOME/.local/share}/supermarket"
COMPOSE_ENV="$DATA/compose.env"
URL="http://localhost:8470"
usage() {
cat << EOF
Usage: supermarket [command]
open Open Supermarket in the browser (the default)
status Is it running, and which version
start Start the container
stop Stop it; it stays stopped, even after a reboot, until you start it
restart Restart it, e.g. to retry an import
logs Follow its log (Ctrl-C to stop)
hermes Set up, or repair, Hermes' connection to your Core's MCP hub
token Print the token agents use to reach Supermarket's MCP endpoint
data Print where its data is kept
config Show its edition and settings, and any problems with them
backup [note] Back up the database now (it also backs up daily)
backup --with-secrets The same, with your keys and tokens, for moving
to another computer (keep the file safe)
backups List the backups
restore <backup or file> Put a backup back (a name from \`backups\`, or
a file), after backing up what's there now; then restarts
Updates come with CoreDesktop's \`update\`.
EOF
}
if [ ! -f "$COMPOSE_ENV" ]; then
echo "Supermarket isn't installed: run its install.sh (or \`sibling add <url>\`)."
exit 1
fi
REPO="$(sed -n 's/^SUPERMARKET_REPO=//p' "$COMPOSE_ENV")"
compose() {
docker compose --project-directory "$REPO" -f "$REPO/compose.yaml" --env-file "$COMPOSE_ENV" "$@"
}
case "${1:-open}" in
open)
if ! curl -sf -o /dev/null "$URL/healthz"; then
echo "Supermarket isn't running; starting it..."
compose up -d || exit 1
sleep 2
fi
xdg-open "$URL" > /dev/null 2>&1 &
;;
status)
if curl -sf -o /dev/null "$URL/healthz"; then
echo "Running at $URL ($(docker exec supermarket supermarket version 2> /dev/null))"
else
echo "Not running."
compose ps
fi
;;
start) compose up -d ;;
stop) compose stop ;;
restart) compose restart ;;
logs) compose logs -f --tail 200 ;;
hermes) shift; bash "$REPO/hermes/setup.sh" "$@" ;;
token) cat "$DATA/mcp-token" ;;
backup|backups|config)
if ! docker exec supermarket true 2> /dev/null; then
echo "Supermarket isn't running: start it first (supermarket start)."
exit 1
fi
docker exec supermarket supermarket "$@"
;;
restore)
if [ -z "$2" ]; then
echo "Usage: supermarket restore <backup name or file>"
exit 1
fi
if ! docker exec supermarket true 2> /dev/null; then
echo "Supermarket isn't running: start it first (supermarket start)."
exit 1
fi
target="$2"
staged=""
if [ -f "$target" ]; then
# A file on this computer: the container only sees the data folder.
case "$target" in
*.tar.gz|*.tgz) staged="$DATA/restore-upload.tar.gz" ;;
*) staged="$DATA/restore-upload.db" ;;
esac
install -m 600 "$target" "$staged" || exit 1
target="/data/$(basename "$staged")"
fi
if docker exec supermarket supermarket restore "$target"; then
[ -n "$staged" ] && rm -f "$staged"
echo "Restarting Supermarket to apply it..."
compose restart
else
[ -n "$staged" ] && rm -f "$staged"
exit 1
fi
;;
data) echo "$DATA" ;;
-h|--help|help) usage ;;
*) usage; exit 1 ;;
esac