#!/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 "$HOME" # 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 # Git identity + Forgejo HTTPS auth for clone/push from agent sessions. if command -v git >/dev/null 2>&1; then git config --global --add safe.directory '*' if [ -n "${GIT_AUTHOR_NAME:-}" ]; then git config --global user.name "$GIT_AUTHOR_NAME" else git config --global user.name "${GIT_USER_NAME:-opencode}" fi if [ -n "${GIT_AUTHOR_EMAIL:-}" ]; then git config --global user.email "$GIT_AUTHOR_EMAIL" else git config --global user.email "${GIT_USER_EMAIL:-opencode@stillwell.cloud}" fi if [ -n "${FORGEJO_TOKEN:-}" ]; then git config --global credential.helper store # oauth2: is Forgejo's HTTPS token username convention. printf 'https://oauth2:%s@forgejo.stillwell.cloud\n' "$FORGEJO_TOKEN" \ > "$HOME/.git-credentials" chmod 600 "$HOME/.git-credentials" fi fi exec "$@"