Files
release-factory/opencode-workstation-builder/image/scripts/start-opencode-runtime.sh
T
okxlinandWorkstation Dev 7d0161bbcb fix: opencode workstation runtime sync improvements (#22)
* fix: update opencode workstation runtime

* fix: harden opencode multi-arch workflow

---------

Co-authored-by: Workstation Dev <dev@workstation>
2026-06-19 00:27:55 +08:00

58 lines
1.7 KiB
Bash

#!/usr/bin/env bash
set -euo pipefail
if [[ -z "${HOME:-}" ]]; then
runtime_home="$(getent passwd "$(id -u)" | cut -d: -f6 2>/dev/null || true)"
export HOME="${runtime_home}"
fi
: "${OPENCODE_NPM_BIN_DIR:=$HOME/.local/bin}"
export PATH="/opt/bun/bin:/usr/local/go/bin:${HOME}/.cargo/bin:${OPENCODE_NPM_BIN_DIR}:${HOME}/.local/bin:${PATH:-/usr/local/bin:/usr/bin:/bin}"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
: "${OPENCODE_RUNTIME_MODE:=acp}"
: "${ACP_PORT:=8765}"
: "${ACP_HOST:=0.0.0.0}"
: "${SERVE_PORT:=4096}"
: "${SERVE_HOST:=0.0.0.0}"
: "${OPENCODE_BOOTSTRAP:=1}"
: "${OPENCODE_INSTALL_PLUGINS:=1}"
: "${OPENCODE_CONFIG_DIR:=$HOME/.config/opencode}"
if [[ "${OPENCODE_BOOTSTRAP}" == "1" ]]; then
"${SCRIPT_DIR}/bootstrap-opencode-userland.sh"
fi
if [[ "${OPENCODE_INSTALL_PLUGINS}" == "1" ]]; then
"${SCRIPT_DIR}/install-opencode-plugins.sh"
fi
if command -v python3 >/dev/null 2>&1; then
python3 "${SCRIPT_DIR}/update_opencode_config.py" sync-model
python3 "${SCRIPT_DIR}/update_oh_my_openagent_config.py"
fi
case "${OPENCODE_RUNTIME_MODE}" in
acp)
runtime_label="ACP"
runtime_command=(opencode acp --hostname "${ACP_HOST}" --port "${ACP_PORT}")
;;
serve)
runtime_label="serve"
runtime_command=(opencode serve --hostname "${SERVE_HOST}" --port "${SERVE_PORT}")
;;
*)
echo "[runtime] unsupported OPENCODE_RUNTIME_MODE: ${OPENCODE_RUNTIME_MODE} (expected acp or serve)" >&2
exit 1
;;
esac
if ! command -v opencode >/dev/null 2>&1; then
echo "[runtime] opencode is required before starting runtime" >&2
exit 1
fi
echo "[runtime] starting ${runtime_label}: ${runtime_command[*]}"
exec "${runtime_command[@]}"