#!/bin/bash
# Deploy codex-acct on this machine (MacBook or mac mini). Run locally, or copy the
# skill tools to the mini and run there. On the mini, `refresh` will prompt for the
# sudo password (tokens live under the omniroute_svc user).
set -e
SKILL_DIR="$(cd "$(dirname "$0")" && pwd)"
NODE=/opt/homebrew/bin/node

mkdir -p ~/.codex/accounts
cp "$SKILL_DIR/codex-acct.mjs" ~/.codex/codex-acct.mjs
chmod +x ~/.codex/codex-acct.mjs

cat > /opt/homebrew/bin/codex-acct <<EOF
#!/bin/bash
export NODE_NO_WARNINGS=1
exec $NODE "\$HOME/.codex/codex-acct.mjs" "\$@"
EOF
chmod +x /opt/homebrew/bin/codex-acct

DESK="$HOME/Desktop/Codex — переключить аккаунт.command"
cp "$SKILL_DIR/codex-switch.command" "$DESK"
chmod +x "$DESK"

echo "installed: ~/.codex/codex-acct.mjs, /opt/homebrew/bin/codex-acct, Desktop launcher"
echo "building pool from OmniRoute…"
export NODE_NO_WARNINGS=1
codex-acct refresh
codex-acct whoami
echo "done. Switch with: codex-acct rotate  (or double-click the Desktop launcher)"
