Files
Deploy-Laboratory/ansible/tools/armv7-docker-verify-install.sh
2026-03-29 09:08:01 +08:00

49 lines
1.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
# 在 armv7/arm32 等远程主机上:若 docker info 已成功则跳过安装;否则拉取并执行官方 get.docker.com 脚本后再校验。
# 用法:
# ARMV7_SSH='ssh -o BatchMode=yes user@arm-host' ./ansible/tools/armv7-docker-verify-install.sh
# ./ansible/tools/armv7-docker-verify-install.sh 'ssh -o BatchMode=yes user@arm-host'
# 参考https://github.com/docker/docker-install get.docker.com
set -euo pipefail
SSH_CMD="${1:-${ARMV7_SSH:-}}"
if [[ -z "${SSH_CMD}" ]]; then
echo "[ERR] 未指定 SSH请设置 ARMV7_SSH 或传入参数例如ARMV7_SSH='ssh -o BatchMode=yes user@host' $0" >&2
exit 2
fi
# shellcheck disable=SC2086
remote() {
$SSH_CMD "$@"
}
echo "[INFO] 探测远程 docker info …"
if remote docker info >/dev/null 2>&1; then
echo "[OK] docker info 可用,跳过安装(与 docs/01-03 验收一致)"
remote docker info
echo "[OC] doc_id=01-03 result=verified assertion=docker_info skip_install=1"
exit 0
fi
echo "[INFO] docker info 不可用,使用官方脚本安装 Docker CEget.docker.com…"
# 远程 stdin 脚本root 直接 sh非 root 用 sudo需免密或已交互配置
remote bash -s <<'REMOTE_INSTALL'
set -euo pipefail
curl -fsSL https://get.docker.com -o /tmp/get-docker.sh
if [[ "$(id -u)" -eq 0 ]]; then
sh /tmp/get-docker.sh
else
sudo sh /tmp/get-docker.sh
fi
REMOTE_INSTALL
echo "[INFO] 安装后再次校验 docker info …"
if ! remote docker info; then
echo "[ERR] 安装后 docker info 仍失败" >&2
exit 1
fi
echo "[OK] Docker 已就绪"
echo "[OC] doc_id=01-03 result=verified assertion=docker_info skip_install=0"
exit 0