Files
ARTEX-chixuweihu/install.sh
T
ji ruo 659e43e91e release(v0.3.35): sandbox upgrade guard, shell timezone i18n, and release notes
- Add validate_sandbox_compose check and compose snapshot backup/restore in deploy-lib.sh
- Show both git clone and non-git sync upgrade commands in sandbox page and settings card
- Gate standalone-to-sandbox warning in update modal to Docker non-sandbox mode only
- Add timezone-based zh/en auto-switching (with ARTEX_LANG override) across shell scripts
- Extract CHANGELOG.md section into GitHub Release notes and add v0.3.35 release notes
2026-12-04 16:45:32 +08:00

189 lines
7.6 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# ARTEX 安装脚本:
# 1) Docker 部署(推荐:独立沙箱容器 + 全流量透明网关 + 出口代理控制)
# 2) 本地编译运行(Go 编译)
#
# 非交互用法示例:
# ./install.sh --docker --yes
# ./install.sh --docker --tag v0.3.33 --yes
# ./install.sh --local
set -euo pipefail
cd "$(cd "$(dirname "$0")" && pwd)"
# shellcheck source=scripts/deploy-lib.sh
. ./scripts/deploy-lib.sh
# ── docker 环境检测 / 自动安装 ───────────────────
ensure_docker(){
if command -v docker >/dev/null 2>&1 && docker compose version >/dev/null 2>&1; then
ok_l "已检测到 docker 与 docker compose" "Detected docker and docker compose"; return
fi
warn_l "未检测到 docker / docker compose" "docker / docker compose not found"
case "$(uname -s)" in
Linux)
if is_yes "$(ask_l '自动安装 Docker? (y/n)' 'Install Docker automatically? (y/n)' y)"; then
curl -fsSL https://get.docker.com | sh
sudo usermod -aG docker "$USER" || true
ok_l "Docker 安装完成(用户组变更需重新登录后免 sudo)" \
"Docker installed (re-login for docker group membership to take effect without sudo)"
else
die_l "请自行安装 docker 后重试" "Please install Docker manually and retry"
fi ;;
Darwin) die_l "macOS 请安装 Docker Desktop:https://www.docker.com/products/docker-desktop/" \
"On macOS, please install Docker Desktop: https://www.docker.com/products/docker-desktop/" ;;
*) die_l "请自行安装 docker 后重试" "Please install Docker manually and retry" ;;
esac
}
# ── ① Docker 部署 ───────────────────────────────────────────────
install_docker(){
local tag="${1:-}"
ensure_docker
preflight_docker
validate_sandbox_compose "$COMPOSE_FILE" "$tag"
umask 077
local is_fresh=0
[ -f .env ] || is_fresh=1
prepare_env_for_docker "$tag" .env
if [ "$is_fresh" -eq 1 ] && [ "${ARTEX_NONINTERACTIVE:-0}" != "1" ]; then
local key
key="$(ask_l 'ANTHROPIC_API_KEY(可留空,后续在 UI 配)' 'ANTHROPIC_API_KEY (optional, can be set later in UI)' '')"
[ -n "$key" ] && env_set ANTHROPIC_API_KEY "$key" .env
fi
pull_docker_images
info_l "启动服务(${COMPOSE_FILE})…" "Starting services (${COMPOSE_FILE})..."
docker compose -f "$COMPOSE_FILE" up -d --remove-orphans
wait_for_health "$COMPOSE_FILE" || warn_l "服务仍在启动中,请执行 docker compose -f ${COMPOSE_FILE} logs -f artex 观察" \
"Service is still starting; watch logs with: docker compose -f ${COMPOSE_FILE} logs -f artex"
ok_l "启动完成 → http://localhost:8787" "Started -> http://localhost:8787"
info_l "查看日志:docker compose -f ${COMPOSE_FILE} logs -f artex" "View logs: docker compose -f ${COMPOSE_FILE} logs -f artex"
info_l "后续升级 / 回滚:./update.sh" "Future upgrades / rollbacks: ./update.sh"
}
# ── ② 本地编译运行 ──────────────────────────────
install_local(){
echo "$(msg '数据库安装方式:' 'PostgreSQL setup:')"
echo "$(msg ' 1) 连接已有 PostgreSQL' ' 1) Connect to an existing PostgreSQL')"
echo "$(msg ' 2) 用 Docker 起一个 PostgreSQL(需要 docker)' ' 2) Start a PostgreSQL container via Docker (requires docker)')"
case "$(ask_l '选择' 'Select' 1)" in
2)
ensure_docker
local pw; pw="$(ask_l 'Postgres 密码(回车随机)' 'Postgres password (Enter to auto-generate)' "$(rand)")"
docker run -d --name artex-pg -p 5432:5432 \
-e POSTGRES_USER=artex -e POSTGRES_PASSWORD="$pw" -e POSTGRES_DB=artex \
-v artex-pg:/var/lib/postgresql/data postgres:16-alpine
DB_HOST=127.0.0.1 DB_PORT=5432 DB_USER=artex DB_PASS="$pw" DB_NAME=artex DB_SSL=disable ;;
*)
DB_HOST="$(ask_l '数据库地址' 'Database host' 127.0.0.1)"
DB_PORT="$(ask_l '端口' 'Port' 5432)"
DB_USER="$(ask_l '账号' 'Username' artex)"
DB_PASS="$(ask_l '密码' 'Password' '')"
DB_NAME="$(ask_l '数据库名' 'Database name' artex)"
DB_SSL="$(ask_l 'sslmode (disable/require)' 'sslmode (disable/require)' disable)" ;;
esac
cat > config.json <<JSON
{
"database": {
"host": "${DB_HOST}",
"port": ${DB_PORT},
"user": "${DB_USER}",
"password": "${DB_PASS}",
"dbname": "${DB_NAME}",
"sslmode": "${DB_SSL}"
}
}
JSON
ok_l "已生成 config.json" "Generated config.json"
command -v go >/dev/null 2>&1 || die_l "未检测到 Go,请先安装 Go(>=1.26):https://go.dev/dl/" \
"Go not found; please install Go (>=1.26): https://go.dev/dl/"
ok "Go: $(go version)"
if command -v npm >/dev/null 2>&1; then
info_l "构建前端静态产物…" "Building static frontend assets..."
( cd web && npm ci && npm run build:static )
rm -rf server/webui/dist && cp -r web/out server/webui/dist
info_l "编译内嵌单二进制…" "Building embedded single binary..."
CGO_ENABLED=0 go build -tags embedui -trimpath -o artex ./cmd/artex
else
warn_l "未检测到 npm:将编译**不内嵌前端**的后端(前端需另跑 npm run dev)" \
"npm not found: building backend WITHOUT embedded frontend (run npm run dev separately)"
CGO_ENABLED=0 go build -o artex ./cmd/artex
fi
ok_l "编译完成 → ./artex" "Build complete -> ./artex"
info_l "启动…(Ctrl-C 退出)" "Starting... (Ctrl-C to exit)"
./start.sh
}
usage(){
if [ "$ARTEX_SCRIPT_LANG" = "zh" ]; then
cat <<'USAGE'
用法: ./install.sh [选项]
选项:
--docker 直接执行 Docker 部署(docker-compose.yml)
--tag <TAG> 指定镜像版本 tag(如 v0.3.34 / latest)
--local 使用本地 Go 编译运行
--skip-pull 跳过镜像拉取(适用于本地已构建镜像)
-y, --yes 非交互模式(自动填充默认值)
-h, --help 显示本帮助
USAGE
else
cat <<'USAGE'
Usage: ./install.sh [options]
Options:
--docker Deploy with Docker (docker-compose.yml)
--tag <TAG> Target image tag (e.g. v0.3.34 / latest)
--local Build and run locally with Go
--skip-pull Skip pulling images (for locally built images)
-y, --yes Non-interactive mode (use default values)
-h, --help Show this help
USAGE
fi
}
OPT_DOCKER=0
OPT_TAG=""
OPT_LOCAL=0
while [ "$#" -gt 0 ]; do
case "$1" in
--docker) OPT_DOCKER=1 ;;
--tag) shift; [ "$#" -gt 0 ] || die_l "--tag 需要参数" "--tag requires a value"; OPT_TAG="$1" ;;
--local) OPT_LOCAL=1 ;;
--skip-pull) export ARTEX_SKIP_PULL=1 ;;
-y|--yes) export ARTEX_NONINTERACTIVE=1 ;;
-h|--help) usage; exit 0 ;;
*) die_l "未知参数:$1(使用 --help 查看帮助)" "Unknown option: $1 (use --help for usage)" ;;
esac
shift
done
if [ "$OPT_LOCAL" -eq 1 ]; then
install_local
exit 0
fi
if [ "$OPT_DOCKER" -eq 1 ]; then
install_docker "$OPT_TAG"
exit 0
fi
echo "=========================================="
echo "$(msg ' ARTEX 安装部署' ' ARTEX Installer')"
echo "$(msg ' 1) Docker 部署(推荐:独立沙箱 + 全流量网关)' ' 1) Docker deployment (recommended: isolated sandbox + transparent gateway)')"
echo "$(msg ' 2) 本地运行(Go 编译)' ' 2) Local run (build with Go)')"
echo "=========================================="
case "$(ask_l '选择' 'Select' 1)" in
1) install_docker "$OPT_TAG" ;;
2) install_local ;;
*) die_l "无效选择" "Invalid selection" ;;
esac