73 lines
2.0 KiB
Bash
73 lines
2.0 KiB
Bash
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
# ── Git config defaults ──────────────────────────────────────────────
|
|
if [ -n "${GIT_USER_NAME:-}" ] && ! git config --global user.name &>/dev/null; then
|
|
git config --global user.name "$GIT_USER_NAME"
|
|
fi
|
|
if [ -n "${GIT_USER_EMAIL:-}" ] && ! git config --global user.email &>/dev/null; then
|
|
git config --global user.email "$GIT_USER_EMAIL"
|
|
fi
|
|
|
|
# ── Generate opencode config from env vars if no config mounted ──────
|
|
CONFIG_DIR="$HOME/.config/opencode"
|
|
CONFIG_FILE="$CONFIG_DIR/opencode.json"
|
|
|
|
if [ ! -f "$CONFIG_FILE" ] && [ -n "${OPENCODE_PROVIDER:-}" ]; then
|
|
echo "Generating opencode config for provider: $OPENCODE_PROVIDER"
|
|
mkdir -p "$CONFIG_DIR"
|
|
|
|
case "$OPENCODE_PROVIDER" in
|
|
anthropic)
|
|
cat > "$CONFIG_FILE" <<EOF
|
|
{
|
|
"\$schema": "https://opencode.ai/config.json",
|
|
"model": "${OPENCODE_MODEL:-anthropic/claude-sonnet-4-5}",
|
|
"share": "disabled",
|
|
"autoupdate": false
|
|
}
|
|
EOF
|
|
;;
|
|
openai)
|
|
cat > "$CONFIG_FILE" <<EOF
|
|
{
|
|
"\$schema": "https://opencode.ai/config.json",
|
|
"model": "${OPENCODE_MODEL:-openai/gpt-4o}",
|
|
"share": "disabled",
|
|
"autoupdate": false
|
|
}
|
|
EOF
|
|
;;
|
|
amazon-bedrock)
|
|
cat > "$CONFIG_FILE" <<EOF
|
|
{
|
|
"\$schema": "https://opencode.ai/config.json",
|
|
"model": "${OPENCODE_MODEL:-amazon-bedrock/anthropic.claude-sonnet-4-5-v1}",
|
|
"share": "disabled",
|
|
"autoupdate": false,
|
|
"provider": {
|
|
"amazon-bedrock": {
|
|
"options": {
|
|
"region": "${AWS_REGION:-us-east-1}"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
EOF
|
|
;;
|
|
*)
|
|
cat > "$CONFIG_FILE" <<EOF
|
|
{
|
|
"\$schema": "https://opencode.ai/config.json",
|
|
"model": "${OPENCODE_MODEL:-anthropic/claude-sonnet-4-5}",
|
|
"share": "disabled",
|
|
"autoupdate": false
|
|
}
|
|
EOF
|
|
;;
|
|
esac
|
|
fi
|
|
|
|
# ── Execute command ──────────────────────────────────────────────────
|
|
exec "$@"
|