#!/usr/bin/env bash set -euo pipefail deploy_dir="${1:-$(pwd)}" env_file="${deploy_dir}/.env" password_file="${deploy_dir}/.agentdock-initial-password" if [[ ! -f "${env_file}" ]]; then cp "${deploy_dir}/.env.example" "${env_file}" fi chmod 600 "${env_file}" has_key() { grep -q "^${1}=" "${env_file}" } append_value() { local key="$1" local value="$2" if ! has_key "${key}"; then printf '\n%s=%s\n' "${key}" "${value}" >> "${env_file}" fi } if ! has_key "ADMIN_PASSWORD"; then admin_password="AgentDock-$(openssl rand -hex 12)" append_value "ADMIN_PASSWORD" "${admin_password}" printf '%s\n' "${admin_password}" > "${password_file}" chmod 600 "${password_file}" fi append_value "RUNNER_TOKEN" "$(openssl rand -base64 48 | tr -d '\n')" append_value "CONFIG_ENCRYPTION_KEY" "$(openssl rand -base64 48 | tr -d '\n')" append_value "CONSOLE_HTTPS_PORT" "8443" append_value "CONSOLE_DATA_PATH" "${deploy_dir}/console-data" append_value "AI_TOOLS_IMAGE_TAG" "0.2.0" append_value "CONSOLE_IMAGE_TAG" "0.1.0" append_value "AI_TOOLS_MEMORY_LIMIT" "6g" append_value "AI_TOOLS_CPU_LIMIT" "4.0" append_value "CONSOLE_MEMORY_LIMIT" "512m" append_value "CONSOLE_CPU_LIMIT" "1.0" mkdir -p "${deploy_dir}/console-data" chmod 700 "${deploy_dir}/console-data" printf 'AgentDock console environment is ready.\n' if [[ -f "${password_file}" ]]; then printf 'Initial password file: %s\n' "${password_file}" fi