#!/bin/bash # 在真机 Debian 上用沙箱模式验证 deploy.sh(不碰现有中转) set -u echo "════════ 1. 从发布 zip 里解出脚本(模拟用户真实流程)════════" cd /root rm -rf /root/deploytest mkdir -p /root/deploytest if [ -f /root/lanremote-relay/downloads/ykxmz-server-1.8.2.zip ]; then cd /root/deploytest python3 -c " import zipfile z = zipfile.ZipFile('/root/lanremote-relay/downloads/ykxmz-server-1.8.2.zip') z.extractall('.') print(' 解出', len(z.namelist()), '个文件') " else echo " ! 设备上没有服务端 zip" exit 1 fi D=$(ls -d /root/deploytest/ykxmz-server-* 2>/dev/null | head -1) echo " 目录: $D" echo " 内容:" ls -1 "$D" | sed 's/^/ /' echo " 有没有 deploy.sh: $([ -f "$D/deploy.sh" ] && echo 有 || echo **没有**)" echo " 有没有 site_shots/: $([ -d "$D/site_shots" ] && echo '有 ('$(ls -1 "$D/site_shots" | wc -l)' 张)' || echo **没有**)" echo echo "════════ 2. 语法和格式 ════════" bash -n "$D/deploy.sh" && echo " ✓ deploy.sh 语法通过" || echo " ✗ 语法错误" bash -n "$D/deploy-tune.sh" 2>/dev/null && echo " ✓ deploy-tune.sh 语法通过" || echo " (deploy-tune.sh 不存在或语法错)" python3 -c " from pathlib import Path for n in ['deploy.sh','deploy-tune.sh']: p = Path('$D') / n if not p.is_file(): continue raw = p.read_bytes() crlf = raw.count(b'\r\n') bom = raw.startswith(b'\xef\xbb\xbf') print(f' {n}: CRLF={crlf} BOM={bom} ' + ('✓' if crlf==0 and not bom else '✗')) " echo echo "════════ 3. --help(必须无副作用)════════" before=$(md5sum /etc/systemd/system/lanremote-relay.service 2>/dev/null | awk '{print $1}') out=$(bash "$D/deploy.sh" --help 2>&1) echo "$out" | head -22 | sed 's/^/ /' after=$(md5sum /etc/systemd/system/lanremote-relay.service 2>/dev/null | awk '{print $1}') echo " ----" [ "$before" = "$after" ] && echo " ✓ --help 没动现有服务" || echo " ✗ --help 改了现有服务!" echo " --help 退出码: $(bash "$D/deploy.sh" --help > /dev/null 2>&1; echo $?)" echo echo "════════ 4. 未知参数要被挡 ════════" bash "$D/deploy.sh" --这是一个不存在的参数 > /dev/null 2>&1 echo " 退出码: $? (应该是 2)" echo echo "════════ 5. 沙箱跑一遍(--prefix,不碰真实 /root/lanremote-relay)════════" echo " 跑之前的真实服务状态:" for s in lanremote-relay lanremote-tunnel lanremote-tunnel-h2; do printf " %-24s %s\n" "$s" "$(systemctl is-active $s)" done echo " ---" rm -rf /root/sandbox bash "$D/deploy.sh" --prefix /root/sandbox --skip-tunnel > /tmp/dep.log 2>&1 echo " 退出码: $?" echo " 最后 25 行输出:" tail -25 /tmp/dep.log | sed 's/^/ /' echo " ---" echo " 沙箱里生成了什么:" find /root/sandbox -maxdepth 3 2>/dev/null | head -25 | sed 's/^/ /' echo echo "════════ 6. 幂等:再跑一遍 ════════" # 放个哨兵,看会不会被冲掉 echo "SENTINEL-$(date +%s)" > /root/sandbox/root/lanremote-relay/data/sentinel.txt 2>/dev/null \ || mkdir -p /root/sandbox/root/lanremote-relay/data && echo "SENTINEL" > /root/sandbox/root/lanremote-relay/data/sentinel.txt bash "$D/deploy.sh" --prefix /root/sandbox --skip-tunnel > /tmp/dep2.log 2>&1 echo " 第二次退出码: $?" echo " 哨兵还在吗: $([ -f /root/sandbox/root/lanremote-relay/data/sentinel.txt ] && echo 在 || echo **被冲掉了**)" echo " 第二次最后 8 行:" tail -8 /tmp/dep2.log | sed 's/^/ /' echo echo "════════ 7. 现有真实服务有没有被影响 ════════" for s in lanremote-relay lanremote-tunnel lanremote-tunnel-h2; do printf " %-24s %s\n" "$s" "$(systemctl is-active $s)" done echo " 自检: $(curl -s --max-time 10 http://127.0.0.1:8080/v1/health | head -c 60)" echo echo "════════ 8. 清理沙箱 ════════" rm -rf /root/sandbox /root/deploytest echo " ✓ 已清理" df -h / | sed 's/^/ /'