#!/usr/bin/env bash # deploy/lib/update.sh — crypto_okx 更新 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" require_installed() { if ! repo_ready "${REPO_ROOT}"; then die "未找到安装,请先执行「1) 一键部署」" fi } update_quick() { step "快速更新" bash "${REPO_ROOT}/deploy/pull_and_restart.sh" # git pull 后重新加载,避免菜单进程仍用旧的 verify_deployment # shellcheck source=common.sh source "${LIB_DIR}/common.sh" verify_deployment "$(detect_server_ip)" || true } update_deps() { step "依赖更新" if [[ -x "${REPO_ROOT}/.venv/bin/pip" ]]; then pip_install_requirements "${REPO_ROOT}/.venv/bin/pip" "${REPO_ROOT}/requirements.txt" "crypto_okx 依赖" else bash "${REPO_ROOT}/deploy/setup_env.sh" --install-system-deps fi update_quick } show_update_menu() { while true; do echo "" echo " 更新选项:" echo " 3-1) 快速更新(git pull + pm2 restart)" echo " 3-2) 依赖更新(含 pip install)" echo " 0) 返回主菜单" local choice="" cm_read choice "请选择 [0/3-1/3-2]: " case "${choice}" in 3-1|31|1) update_quick; break ;; 3-2|32|2) update_deps; break ;; 0) break ;; *) echo "无效选项" ;; esac done } main_update() { require_root if ! REPO_ROOT="$(resolve_repo_root)"; then die "未找到安装目录 ${INSTALL_ROOT},请先执行「1) 一键部署」" fi require_installed show_update_menu } main_update "$@"