#!/bin/sh # bolt 卸载脚本(POSIX sh,需 root;Linux 使用 systemd,macOS 使用 launchd) # # 用法(在目标设备上): # IPv4: curl -fsSL https://git.jocayn.qzz.io/jocay/bolt/raw/branch/main/deploy/uninstall.sh | sudo sh # IPv6: curl -fsSL https://git.draws.qzz.io/jocay/bolt/raw/branch/main/deploy/uninstall.sh | sudo sh # 保留配置: ... | sudo sh -s -- --keep-config # # 选项: # --keep-config 保留配置(Linux: /etc/bolt.env;macOS: /Library/Application Support/bolt 与 /var/log/bolt) # # 注意:如果是通过 bolt 自己执行本脚本,最后停止服务时连接会断开,这是正常现象。 set -eu BIN_PATH=/usr/local/bin/bolt LABEL=io.jocay.bolt KEEP_CONFIG=0 while [ $# -gt 0 ]; do case "$1" in --keep-config) KEEP_CONFIG=1; shift ;; *) echo "未知参数: $1"; echo "用法见脚本头部注释"; exit 1 ;; esac done say() { printf '\033[1;32m[bolt]\033[0m %s\n' "$*"; } die() { printf '\033[1;31m[bolt] 错误:\033[0m %s\n' "$*"; exit 1; } [ "$(id -u)" -eq 0 ] || die "需要 root 权限(请用 sudo 运行)" # 二进制及更新脚本留下的备份(正在运行的进程不受影响,最后再停服务) rm_bins() { for f in "$BIN_PATH" "$BIN_PATH.bak" "$BIN_PATH.new" "$BIN_PATH.rollback" "$BIN_PATH".v*.bak; do if [ -e "$f" ]; then rm -f "$f" say "已删除 $f" fi done rm -rf /tmp/bolt-update.* /tmp/bolt-upgrade 2>/dev/null || true } case "$(uname -s)" in Linux) UNIT=/etc/systemd/system/bolt.service HAS_SYSTEMD=0 command -v systemctl >/dev/null 2>&1 && HAS_SYSTEMD=1 if [ "$HAS_SYSTEMD" -eq 1 ]; then systemctl disable bolt >/dev/null 2>&1 && say "已取消开机自启" || true fi rm_bins if [ -e "$UNIT" ] || [ -d "$UNIT.d" ]; then rm -rf "$UNIT" "$UNIT.d" say "已删除服务单元 $UNIT" fi if [ "$KEEP_CONFIG" -eq 0 ]; then if [ -e /etc/bolt.env ]; then rm -f /etc/bolt.env say "已删除配置 /etc/bolt.env" fi else [ -e /etc/bolt.env ] && say "保留配置 /etc/bolt.env" fi say "卸载完成,正在停止服务…" if [ "$HAS_SYSTEMD" -eq 1 ]; then systemctl daemon-reload || true systemctl stop bolt >/dev/null 2>&1 || true systemctl reset-failed bolt >/dev/null 2>&1 || true fi pkill -x bolt 2>/dev/null || true ;; Darwin) AUTO_PLIST="/Library/LaunchDaemons/$LABEL.plist" PLIST_DIR="/Library/Application Support/bolt" rm_bins if [ -e "$AUTO_PLIST" ]; then rm -f "$AUTO_PLIST" say "已删除开机配置 $AUTO_PLIST" fi if [ "$KEEP_CONFIG" -eq 0 ]; then for d in "$PLIST_DIR" /var/log/bolt; do if [ -e "$d" ]; then rm -rf "$d" say "已删除 $d" fi done else say "保留配置 $PLIST_DIR 与日志 /var/log/bolt" fi say "卸载完成,正在停止服务…" launchctl bootout "system/$LABEL" 2>/dev/null || true launchctl disable "system/$LABEL" 2>/dev/null || true ;; *) die "不支持的操作系统: $(uname -s)" ;; esac