Files
Linux/surge-teardown-all.sh

36 lines
1.2 KiB
Bash
Executable File
Raw Permalink 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.
#!/bin/bash
#-------------------------------------------------------------------------------------------------------------
# 使用方法:
# export SURGE_TOKEN="你的 Surge Token"
# 使用“进程替换”方式运行脚本: 这种方式不会占用 stdin脚本可以正常进行交互
# URL="https://git.1-h.cc/Scripts/Linux/raw/branch/2026/surge-teardown-all.sh"; bash <(curl -fsSL "$URL")
#-------------------------------------------------------------------------------------------------------------
echo "正在获取 Surge 部署列表..."
domains=$(bunx surge list | sed 's/\x1b\[[0-9;]*m//g' | grep -E '\.surge\.sh' | awk '{print $1}')
if [ -z "$domains" ]; then
echo "未找到 Surge 部署。"
exit 0
fi
echo "发现以下需要撤销的部署:"
echo "$domains"
echo ""
read -p "确定要撤销所有部署吗?(y/N): " confirm
if [[ $confirm != [yY] && $confirm != [yY][eE][sS] ]]; then
echo "操作已取消。"
exit 0
fi
echo "正在撤销所有部署..."
echo "$domains" | while read -r domain; do
if [ -n "$domain" ]; then
echo "正在撤销: $domain"
bunx surge teardown "$domain"
fi
done
echo "所有部署已撤销。"