Files
dock/dock安装cf
2025-12-26 19:04:49 +08:00

159 lines
5.3 KiB
Plaintext
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.
cat > /data/install_docker_online.sh << 'EOF'
#!/bin/bash
# ================= 配置区域 =================
# 主线路 (Cloudflare R2 - 通常速度快且稳定)
URL_PRIMARY="https://pub-b69a7194f4ea42fba6aa990c49bded91.r2.dev/xui/dockde12.zip"
# 备用线路 (个人VPS - 兜底用)
URL_BACKUP="https://freeyx.vps3344.dpdns.org/xui/dockde12.zip"
INSTALL_DIR="/data/docker_install_temp"
ZIP_FILE="$INSTALL_DIR/dockde12.zip"
TARGET_VER="29.1.3"
# ===========================================
# 颜色定义
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
echo -e "${BLUE}====================================================${NC}"
echo -e "${BLUE} Docker 全自动在线安装脚本 V4.0 (双线路版) ${NC}"
echo -e "${BLUE}====================================================${NC}"
# 1.【权限与架构检查】
if [ "$(id -u)" -ne 0 ]; then
echo -e "${RED}❌ 错误: 请使用 root 权限运行!${NC}"; exit 1
fi
if [ "$(uname -m)" != "x86_64" ]; then
echo -e "${RED}❌ 错误: 此安装包仅支持 x86_64 (AMD64) 架构。${NC}"; exit 1
fi
# 2.【彻底清理冲突与残留】
echo -e "${YELLOW}🧹 步骤1/5: 清理旧版本与冲突配置...${NC}"
systemctl stop docker >/dev/null 2>&1
systemctl stop containerd >/dev/null 2>&1
# 关键:移除可能导致服务启动失败的 containerd 配置文件
if [ -f /etc/containerd/config.toml ]; then
echo " -> 备份并移除旧的 containerd 配置 (防止冲突)..."
mv /etc/containerd/config.toml /etc/containerd/config.toml.bak.$(date +%s)
fi
# 卸载冲突软件
PKGS="docker.io docker-doc docker-compose podman-docker containerd runc docker-ce docker-ce-cli containerd.io"
for pkg in $PKGS; do
if dpkg -l | grep -q "$pkg"; then
apt-get remove -y "$pkg" >/dev/null 2>&1
apt-get purge -y "$pkg" >/dev/null 2>&1
fi
done
apt-get autoremove -y >/dev/null 2>&1
# 3.【智能下载】(双线路切换)
echo -e "${YELLOW}📥 步骤2/5: 开始下载安装包...${NC}"
rm -rf "$INSTALL_DIR"
mkdir -p "$INSTALL_DIR"
download_success=0
# 检查工具
if command -v curl >/dev/null 2>&1; then
DL_CMD="curl -L -k --retry 3 --connect-timeout 10 -o"
elif command -v wget >/dev/null 2>&1; then
DL_CMD="wget --no-check-certificate -t 3 -T 10 -O"
else
echo -e "${RED}❌ 错误: 系统缺少 curl 或 wget无法下载。${NC}"
echo "尝试运行: apt-get update && apt-get install curl -y"
exit 1
fi
# 尝试线路 1
echo " -> 正在尝试主线路 (R2 Storage)..."
$DL_CMD "$ZIP_FILE" "$URL_PRIMARY"
if [ $? -eq 0 ] && [ -s "$ZIP_FILE" ]; then
echo -e "${GREEN} -> 主线路下载成功!${NC}"
download_success=1
else
echo -e "${RED} -> 主线路下载失败或文件为空,切换备用线路...${NC}"
# 尝试线路 2
echo " -> 正在尝试备用线路 (VPS)..."
$DL_CMD "$ZIP_FILE" "$URL_BACKUP"
if [ $? -eq 0 ] && [ -s "$ZIP_FILE" ]; then
echo -e "${GREEN} -> 备用线路下载成功!${NC}"
download_success=1
fi
fi
if [ $download_success -eq 0 ]; then
echo -e "${RED}❌ 错误: 所有下载线路均失败,请检查网络连接。${NC}"; exit 1
fi
# 4.【智能解压】
echo -e "${YELLOW}📦 步骤3/5: 解压安装包...${NC}"
cd "$INSTALL_DIR" || exit
# 优先用 unzip失败用 python
if command -v unzip >/dev/null 2>&1; then
unzip -o "$ZIP_FILE" >/dev/null 2>&1
else
echo " -> 未找到 unzip使用 Python 解压..."
python3 -c "import zipfile; zipfile.ZipFile('$ZIP_FILE', 'r').extractall('.')"
fi
# 整理文件 (防止套娃目录)
find . -name "*.deb" -exec mv {} . \; 2>/dev/null
DEB_COUNT=$(ls *.deb 2>/dev/null | wc -l)
if [ "$DEB_COUNT" -eq 0 ]; then
echo -e "${RED}❌ 错误: 压缩包已下载但未找到 .deb 文件,可能文件已损坏。${NC}"; exit 1
fi
# 5.【强力安装】
echo -e "${YELLOW}🚀 步骤4/5: 执行安装...${NC}"
dpkg -i --force-overwrite *.deb >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo -e "${RED}⚠ 首次安装依赖不足,正在尝试自动修复...${NC}"
apt-get update --allow-insecure-repositories >/dev/null 2>&1
apt-get install -f -y
echo " -> 修复完成,重试安装..."
dpkg -i --force-overwrite *.deb
fi
# 6.【启动与验证】
echo -e "${YELLOW}⚙ 步骤5/5: 配置并启动服务...${NC}"
systemctl daemon-reload
systemctl unmask docker >/dev/null 2>&1
systemctl enable docker
systemctl restart docker
# 检查 Docker 状态
echo "----------------------------------------------------"
FINAL_VER=$(docker --version 2>/dev/null)
if [[ "$FINAL_VER" == *"$TARGET_VER"* ]]; then
echo -e "${GREEN}✅ 安装成功!${NC}"
echo -e " Docker 版本: $FINAL_VER"
echo -e " Compose版本: $(docker compose version 2>/dev/null)"
# 检查进程是否存活
if systemctl is-active --quiet docker; then
echo -e " 服务状态: ${GREEN}运行正常 (Active)${NC}"
else
echo -e " 服务状态: ${RED}启动失败 (Failed)${NC}"
echo -e " 建议查看日志: journalctl -xeu docker.service"
fi
else
echo -e "${RED}❌ 安装失败或版本不匹配。${NC}"
fi
# 清理临时文件
rm -rf "$INSTALL_DIR"
echo -e "${BLUE}====================================================${NC}"
EOF
# 赋予执行权限并运行
chmod +x /data/install_docker_online.sh
bash /data/install_docker_online.sh