93 lines
2.6 KiB
Bash
Executable File
93 lines
2.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
||
# 真机一键验收入口:可选铺栈 + 矩阵全量验收(verify.sh full)。
|
||
# 默认:只做验收(不强制重装/重铺栈),避免误伤现有环境。
|
||
#
|
||
# 开关(环境变量):
|
||
# ACCEPT_DEPLOY=1 先执行 deploy-lab(默认 0)
|
||
# ACCEPT_DEPLOY_K3S=1 部署/复验 K3s(默认 1;仅在 ACCEPT_DEPLOY=1 时生效)
|
||
# ACCEPT_DEPLOY_LONGHORN=1 部署 Longhorn(默认 0)
|
||
# ACCEPT_DEPLOY_NGINX_MATRIX=1 部署 nginx 矩阵(默认 0)
|
||
# ACCEPT_DEPLOY_NGINX_MATRIX_TLS=1 部署 TLS nginx 矩阵(默认 0)
|
||
# VERIFY_TEARDOWN=1 验收后清理临时资源(沿用 verify.sh 默认;可设 0 保留现场)
|
||
set -euo pipefail
|
||
|
||
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||
|
||
load_env() {
|
||
if [[ -f "${ROOT}/scripts/.env.verify" ]]; then
|
||
set -a
|
||
# shellcheck disable=SC1091
|
||
source "${ROOT}/scripts/.env.verify"
|
||
set +a
|
||
echo "[OK] 已加载 scripts/.env.verify"
|
||
fi
|
||
}
|
||
|
||
usage() {
|
||
cat <<'EOF'
|
||
用法:scripts/acceptance.sh
|
||
|
||
说明:
|
||
- 真机「一键验收」:可选先铺栈(deploy-lab),再跑矩阵全量验收(verify.sh full)
|
||
- 默认不铺栈(避免误改现网);只执行 ./scripts/verify.sh full
|
||
|
||
常用示例:
|
||
# 只验收(推荐默认)
|
||
./scripts/acceptance.sh
|
||
|
||
# 先复验/安装 K3s,再全量验收
|
||
ACCEPT_DEPLOY=1 ./scripts/acceptance.sh
|
||
|
||
# 铺栈(K3s + Longhorn + nginx-matrix),然后全量验收
|
||
ACCEPT_DEPLOY=1 ACCEPT_DEPLOY_LONGHORN=1 ACCEPT_DEPLOY_NGINX_MATRIX=1 ./scripts/acceptance.sh
|
||
|
||
# 验收不清理(保留现场排障)
|
||
VERIFY_TEARDOWN=0 ./scripts/acceptance.sh
|
||
EOF
|
||
}
|
||
|
||
need_cmd() {
|
||
if ! command -v "$1" >/dev/null 2>&1; then
|
||
echo "[ERR] 未找到命令:$1" >&2
|
||
exit 1
|
||
fi
|
||
}
|
||
|
||
main() {
|
||
load_env
|
||
|
||
local cmd="${1:-}"
|
||
case "$cmd" in
|
||
"" ) ;;
|
||
-h|--help|help) usage; exit 0 ;;
|
||
*) echo "[ERR] unknown arg: $cmd" >&2; usage; exit 1 ;;
|
||
esac
|
||
|
||
need_cmd bash
|
||
need_cmd python3
|
||
need_cmd ansible-playbook
|
||
|
||
if [[ "${ACCEPT_DEPLOY:-0}" == "1" ]]; then
|
||
echo "########################################## deploy (optional)"
|
||
if [[ "${ACCEPT_DEPLOY_K3S:-1}" == "1" ]]; then
|
||
./scripts/deploy-lab.sh k3s
|
||
fi
|
||
if [[ "${ACCEPT_DEPLOY_LONGHORN:-0}" == "1" ]]; then
|
||
./scripts/deploy-lab.sh longhorn
|
||
fi
|
||
if [[ "${ACCEPT_DEPLOY_NGINX_MATRIX:-0}" == "1" ]]; then
|
||
./scripts/deploy-lab.sh nginx-matrix
|
||
fi
|
||
if [[ "${ACCEPT_DEPLOY_NGINX_MATRIX_TLS:-0}" == "1" ]]; then
|
||
./scripts/deploy-lab.sh nginx-matrix-tls
|
||
fi
|
||
fi
|
||
|
||
echo ""
|
||
echo "########################################## verify full (matrix)"
|
||
./scripts/verify.sh full
|
||
}
|
||
|
||
main "$@"
|
||
|