#!/bin/bash # 检查设备上能不能往 Gitee 推代码。 set -u echo "===== 1. git 有没有 =====" if command -v git >/dev/null 2>&1; then echo " git $(git --version | awk '{print $3}')" else echo " ✗ 没有 git" exit 0 fi echo echo "===== 2. 有没有 SSH 密钥 =====" if [ -f ~/.ssh/id_ed25519.pub ]; then echo " 已有 ed25519 公钥:" cat ~/.ssh/id_ed25519.pub | sed 's/^/ /' elif [ -f ~/.ssh/id_rsa.pub ]; then echo " 已有 rsa 公钥:" cat ~/.ssh/id_rsa.pub | sed 's/^/ /' else echo " 没有密钥(需要生成一个,再把公钥加到 Gitee)" fi echo echo "===== 3. 能不能连上 Gitee =====" echo -n " DNS: " getent hosts gitee.com | head -1 || echo "解析不了" echo -n " SSH 22 端口: " timeout 8 bash -c 'exec 3<>/dev/tcp/gitee.com/22' 2>/dev/null && echo "通" || echo "不通" echo -n " HTTPS 443: " timeout 8 bash -c 'exec 3<>/dev/tcp/gitee.com/443' 2>/dev/null && echo "通" || echo "不通" echo echo "===== 4. SSH 认证测试 =====" timeout 20 ssh -o StrictHostKeyChecking=no -o BatchMode=yes \ -T git@gitee.com 2>&1 | head -3 | sed 's/^/ /' echo echo "===== 5. 磁盘空间 =====" df -h /root | tail -1 | sed 's/^/ /'