Add curl|bash manage.sh with deploy/uninstall/update menu.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Executable
+67
@@ -0,0 +1,67 @@
|
||||
#!/usr/bin/env bash
|
||||
# deploy/lib/install.sh — 一键部署
|
||||
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}"
|
||||
step "构建并启动 (pull_and_restart.sh)"
|
||||
bash "${REPO_ROOT}/deploy/pull_and_restart.sh"
|
||||
pm2_save_startup
|
||||
verify_health || true
|
||||
print_post_install_guide
|
||||
}
|
||||
|
||||
install_fresh() {
|
||||
require_root
|
||||
ensure_system_deps
|
||||
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
|
||||
ensure_system_deps
|
||||
if ! REPO_ROOT="$(resolve_repo_root)"; then
|
||||
die "未找到安装目录 ${INSTALL_ROOT}"
|
||||
fi
|
||||
step "修复环境(保留 .env 与数据库)"
|
||||
run_pipeline "${REPO_ROOT}"
|
||||
}
|
||||
|
||||
handle_existing() {
|
||||
echo ""
|
||||
echo "检测到已部署: ${INSTALL_ROOT}"
|
||||
echo " a) 取消"
|
||||
echo " b) 修复/重装环境(保留 .env 与 SQLite)"
|
||||
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 "$@"
|
||||
Reference in New Issue
Block a user