vps部署优化

This commit is contained in:
2026-08-05 17:12:18 +08:00
parent 2afc2cade6
commit 5195986fc4
11 changed files with 989 additions and 96 deletions
+35 -5
View File
@@ -83,11 +83,33 @@ else
fi
systemctl disable xray 2>/dev/null || true
# 每日重启 timer(旧版部署可能残留)
if [ -f /etc/systemd/system/xray-restart.timer ]; then
systemctl disable --now xray-restart.timer 2>/dev/null || true
rm -f /etc/systemd/system/xray-restart.timer \
/etc/systemd/system/xray-restart.service
log "已移除每日重启 timer"
fi
# ===== 2. 卸载 Xray =====
log "正在卸载 Xray..."
if [ -f /usr/local/bin/xray ]; then
# 使用官方卸载方式
bash <(curl -fsSL https://raw.githubusercontent.com/XTLS/Xray-install/main/install-release.sh) --remove 2>/dev/null || true
# 官方卸载:下载到临时文件再执行。
# 不能用 bash <(curl ...)——curl 缺失时进程替换只产生空脚本,
# 外层 bash 仍返回 0,卸载会被静默跳过
if command -v curl &>/dev/null; then
installer="$(mktemp)"
if curl -fsSL --max-time 60 \
https://raw.githubusercontent.com/XTLS/Xray-install/main/install-release.sh \
-o "$installer" && [ -s "$installer" ]; then
bash "$installer" remove --purge || warn "官方卸载脚本执行失败,改为手动清理"
else
warn "无法下载官方卸载脚本,改为手动清理"
fi
rm -f "$installer"
else
warn "未安装 curl,跳过官方卸载脚本,改为手动清理"
fi
# 手动清理残留
rm -f /usr/local/bin/xray
rm -rf /usr/local/etc/xray
@@ -128,9 +150,17 @@ fi
echo ""
read -r -p "是否删除部署目录 ${SCRIPT_DIR}(y/N): " del_deploy
if [[ "$del_deploy" =~ ^[Yy]$ ]]; then
cd /opt
rm -rf "$SCRIPT_DIR"
log "已删除部署目录"
# 删除前做路径断言,避免 SCRIPT_DIR 异常时误删根目录或系统目录
case "$SCRIPT_DIR" in
/|/root|/etc|/usr|/var|/home|/opt|"")
error "拒绝删除高危路径: '${SCRIPT_DIR}',请手动处理"
;;
*)
cd /
rm -rf "$SCRIPT_DIR"
log "已删除部署目录: ${SCRIPT_DIR}"
;;
esac
else
warn "保留部署目录: ${SCRIPT_DIR}"
fi