bash_agant_install/uninstall.sh

56 lines
1.6 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
set -e
# 检查 root 权限
if [[ $EUID -ne 0 ]]; then
echo "❌ 必须以 root 用户运行"
exit 1
fi
INSTALL_DIR="/etc/exec_hook"
# 删除后端服务和拦截库
rm -rf "$INSTALL_DIR"
# 删除 profile 启动脚本
rm -f /etc/profile.d/exec_hook.sh
# 修改所有用户的 .bashrc 文件(跳过无效 home
HOOK_CODE=$(cat <<'EOF'
# ========== exec_hook 注入 ==========
if [[ -z "$EXEC_HOOK_DONE" && -z "$SSH_ORIGINAL_COMMAND" && "$-" == *i* ]]; then
export EXEC_HOOK_DONE=1
/etc/exec_hook/backend_service
export LD_PRELOAD=/etc/exec_hook/intercept.so
exec "$SHELL" --login
fi
# ========== exec_hook 结束 ==========
EOF
)
for USER_HOME in /root $(awk -F: '$3>=1000{print $6}' /etc/passwd); do
BASHRC="$USER_HOME/.bashrc"
if [[ -d "$USER_HOME" && -f "$BASHRC" ]]; then
if grep -q "$HOOK_CODE" "$BASHRC"; then
sed -i "/$HOOK_CODE/d" "$BASHRC"
echo "✅ 从 $BASHRC 中移除 exec_hook 注入"
else
echo "🔁 $BASHRC 中没有 exec_hook 注入,跳过"
fi
else
echo "⚠️ 跳过无效 home 目录:$USER_HOME 或没有 .bashrc 文件"
fi
done
# === 执行卸载 install_product_id_generator.sh ===
if [[ -x ./script/uninstall_product_id_generator.sh ]]; then
echo "🚀 执行 uninstall_product_id_generator.sh..."
./script/uninstall_product_id_generator.sh || { echo "❌ uninstall_product_id_generator.sh 执行失败"; exit 1; }
echo "✅ uninstall_product_id_generator.sh 执行完成"
else
echo "❌ 找不到或无法执行 ./script/uninstall_product_id_generator.sh"
fi
echo "✅ 卸载完成"