aosp_build_agent/scripts/uninstall.sh
2026-09-08 11:34:01 +08:00

122 lines
3.2 KiB
Bash
Executable File
Raw 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
#
# AOSP 编译错误分析 Agent — 卸载脚本
#
# 清理 install.sh 安装的三处内容:
# 1. 二进制 ($INSTALL_DIR/analyze,默认 /usr/local/bin)
# 2. 配置文件 (~/.aosp-analyzer.env)
# 3. Shell RC 中的自动加载行
#
# 用法:
# ./uninstall.sh # 交互式卸载(默认安装路径)
# ./uninstall.sh --dir ~/.local/bin # 自定义安装路径
# ./uninstall.sh --yes # 跳过确认
#
set -e
# ── 默认配置 ──
INSTALL_DIR="/usr/local/bin"
BINARY_NAME="analyze"
CONFIG_FILE="$HOME/.aosp-analyzer.env"
# 颜色
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
# ── 参数解析 ──
ASSUME_YES=false
while [[ $# -gt 0 ]]; do
case $1 in
--dir) INSTALL_DIR="$2"; shift 2 ;;
--yes|-y) ASSUME_YES=true; shift ;;
-h|--help)
echo "用法: uninstall.sh [选项]"
echo ""
echo "选项:"
echo " --dir <path> 二进制安装目录 (默认: /usr/local/bin)"
echo " --yes, -y 跳过确认"
echo " -h, --help 显示帮助"
exit 0
;;
*) echo "未知参数: $1"; exit 1 ;;
esac
done
# ── 辅助函数 ──
info() { echo -e "${BLUE}ℹ${NC} $1"; }
ok() { echo -e "${GREEN}✅${NC} $1"; }
warn() { echo -e "${YELLOW}⚠${NC} $1"; }
err() { echo -e "${RED}❌${NC} $1"; exit 1; }
remove_rc_lines() {
local rc="$1"
[[ -f "$rc" ]] || return 0
# 删除 install.sh 追加的两行: 注释行 + source 行(存在才删)
if grep -qF "source ${CONFIG_FILE}" "$rc" 2>/dev/null; then
# macOS sed 与 GNU sed 兼容写法: 先备份再删行
sed -i.bak-analyzer \
-e "\|# AOSP 编译错误分析 Agent|d" \
-e "\|source ${CONFIG_FILE}|d" \
"$rc"
rm -f "${rc}.bak-analyzer"
ok "已移除 ${rc} 中的自动加载配置"
fi
}
# ── 卸载流程 ──
TARGET="${INSTALL_DIR}/${BINARY_NAME}"
echo ""
echo "========================================"
echo " AOSP 编译错误分析 Agent — 卸载"
echo "========================================"
echo ""
info "将删除以下内容:"
echo " 1. 二进制: ${TARGET}"
echo " 2. 配置文件: ${CONFIG_FILE}"
echo " 3. Shell RC 中的自动加载行 (~/.zshrc / ~/.bashrc)"
echo ""
if [[ "$ASSUME_YES" != true ]]; then
read -p " 确认卸载? (y/N) " -n 1 -r < /dev/tty
echo ""
[[ $REPLY =~ ^[Yy]$ ]] || err "卸载中止"
fi
# 1. 删除二进制
if [[ -f "$TARGET" ]]; then
rm -f "$TARGET" || err "无权限删除 ${TARGET}(尝试: sudo rm -f ${TARGET})"
ok "已删除二进制: ${TARGET}"
else
warn "二进制不存在: ${TARGET}(跳过)"
fi
# 2. 删除配置文件
if [[ -f "$CONFIG_FILE" ]]; then
rm -f "$CONFIG_FILE"
ok "已删除配置文件: ${CONFIG_FILE}"
else
warn "配置文件不存在: ${CONFIG_FILE}(跳过)"
fi
# 3. 清理 Shell RC
remove_rc_lines "$HOME/.zshrc"
remove_rc_lines "$HOME/.bashrc"
echo ""
echo "========================================"
echo " 卸载完成"
echo "========================================"
echo ""
echo " 当前 Shell 中的环境变量仍残留,新开终端即可清除;或执行:"
echo " unset ARK_API_KEY"
echo ""