28 lines
905 B
Bash
28 lines
905 B
Bash
|
|
#!/bin/sh
|
||
|
|
# Seed OmniRoute auth for headless OpenCode, then start serve/web.
|
||
|
|
set -eu
|
||
|
|
|
||
|
|
CONFIG_HOME="${XDG_CONFIG_HOME:-${HOME:-/data}/.config}"
|
||
|
|
DATA_HOME="${XDG_DATA_HOME:-${HOME:-/data}/.local/share}"
|
||
|
|
mkdir -p "$CONFIG_HOME/opencode" "$DATA_HOME/opencode" /data/bin
|
||
|
|
|
||
|
|
# Container has no desktop — stub xdg-open so `opencode web` does not exit.
|
||
|
|
if [ ! -x /data/bin/xdg-open ]; then
|
||
|
|
printf '#!/bin/sh\nexit 0\n' > /data/bin/xdg-open
|
||
|
|
chmod +x /data/bin/xdg-open
|
||
|
|
fi
|
||
|
|
export PATH="/data/bin:${PATH}"
|
||
|
|
|
||
|
|
if [ -f /config/opencode.json ]; then
|
||
|
|
cp /config/opencode.json "$CONFIG_HOME/opencode/opencode.json"
|
||
|
|
fi
|
||
|
|
|
||
|
|
if [ -n "${OMNIROUTE_API_KEY:-}" ]; then
|
||
|
|
# Keys must not contain double-quotes; OmniRoute keys are hex/base64-safe.
|
||
|
|
printf '{"omniroute":{"type":"api","key":"%s"}}\n' "$OMNIROUTE_API_KEY" \
|
||
|
|
> "$DATA_HOME/opencode/auth.json"
|
||
|
|
chmod 600 "$DATA_HOME/opencode/auth.json" || true
|
||
|
|
fi
|
||
|
|
|
||
|
|
exec "$@"
|