4743f3efdd
CRLF line endings broke manage.sh on Ubuntu (set -e and function syntax errors). Add .gitattributes to keep *.sh on LF in git. Co-authored-by: Cursor <cursoragent@cursor.com>
80 lines
1.9 KiB
Bash
80 lines
1.9 KiB
Bash
#!/usr/bin/env bash
|
||
# deploy/lib/install.sh — 一键部署 market_intel(Docker Compose)
|
||
set -e
|
||
set -u
|
||
if [ -n "${BASH_VERSION:-}" ]; then
|
||
set -o pipefail
|
||
fi
|
||
|
||
LIB_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||
# shellcheck source=common.sh
|
||
source "${LIB_DIR}/common.sh"
|
||
|
||
run_pipeline() {
|
||
local root="$1"
|
||
REPO_ROOT="${root}"
|
||
ensure_dotenv "${root}"
|
||
compose_up_build
|
||
verify_health || true
|
||
print_post_install_guide
|
||
}
|
||
|
||
install_fresh() {
|
||
require_root
|
||
step "一键部署 — Docker 环境检测"
|
||
ensure_docker
|
||
# 基础包
|
||
if ! command -v git >/dev/null 2>&1 || ! command -v curl >/dev/null 2>&1; then
|
||
export DEBIAN_FRONTEND=noninteractive
|
||
apt_update
|
||
apt_install ca-certificates git curl
|
||
fi
|
||
step "克隆仓库 → ${INSTALL_ROOT}"
|
||
if [[ -d "${INSTALL_ROOT}" ]]; then
|
||
die "目录已存在: ${INSTALL_ROOT},请先卸载或选修复"
|
||
fi
|
||
mkdir -p "$(dirname "${INSTALL_ROOT}")"
|
||
git clone -b "${GIT_BRANCH}" "${GIT_URL}" "${INSTALL_ROOT}"
|
||
run_pipeline "${INSTALL_ROOT}"
|
||
}
|
||
|
||
install_repair() {
|
||
require_root
|
||
step "修复部署 — Docker 环境检测"
|
||
ensure_docker
|
||
if ! REPO_ROOT="$(resolve_repo_root)"; then
|
||
die "未找到安装目录 ${INSTALL_ROOT}"
|
||
fi
|
||
step "修复环境(保留 .env 与 data volume)"
|
||
if [[ -d "${REPO_ROOT}/.git" ]]; then
|
||
git -C "${REPO_ROOT}" pull --ff-only origin "${GIT_BRANCH}" 2>/dev/null \
|
||
|| git -C "${REPO_ROOT}" pull --ff-only 2>/dev/null \
|
||
|| true
|
||
fi
|
||
run_pipeline "${REPO_ROOT}"
|
||
}
|
||
|
||
handle_existing() {
|
||
echo ""
|
||
echo "检测到已部署: ${INSTALL_ROOT}"
|
||
echo " a) 取消"
|
||
echo " b) 修复/重装环境(保留 .env 与数据 volume)"
|
||
local choice=""
|
||
cm_read choice "请选择 [a/b]: "
|
||
case "${choice}" in
|
||
b|B) install_repair ;;
|
||
*) log "已取消" ;;
|
||
esac
|
||
}
|
||
|
||
main_install() {
|
||
require_root
|
||
if repo_ready "${INSTALL_ROOT}"; then
|
||
handle_existing
|
||
else
|
||
install_fresh
|
||
fi
|
||
}
|
||
|
||
main_install "$@"
|