Files
trial-command/Mac/17X/17.3.7.sh
jianglong 9bf5174285 chore(scripts): 新增 17.3.7.sh 脚本
- 添加新的 shell 脚本文件 17.3.7.sh,用于执行相关任务
- 不影响现有功能,仅作为维护/辅助脚本
2026-01-08 21:33:11 +08:00

72 lines
3.7 KiB
Bash
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 -uo pipefail # 启用严格错误处理 / Enable strict error handling
# ---------- 定义变量 / Define variables ----------
APP_NAME="Navicat Premium"
APP_SUPPORT_DIR="$HOME/Library/Application Support/PremiumSoft CyberTech/Navicat CC/Navicat Premium"
PLIST_FILE="$HOME/Library/Preferences/com.navicat.NavicatPremium.plist"
KEYCHAIN_SERVICE="com.navicat.NavicatPremium"
# ---------- 终止 Navicat 进程 / Terminate Navicat process ----------
echo "正在终止 $APP_NAME 进程... / Terminating $APP_NAME process..."
if pkill -9 "$APP_NAME" 2>/dev/null; then
echo "已成功终止正在运行的 $APP_NAME 进程。/ Successfully terminated running $APP_NAME process."
else
echo "$APP_NAME 进程未在运行,跳过终止。/ $APP_NAME process not running, skipping termination."
fi
# ---------- 清理应用支持目录的哈希文件 / Cleaning hash files in app support directory ----------
echo "清理应用支持目录的哈希文件... / Cleaning hash files in app support directory..."
find "$APP_SUPPORT_DIR" -maxdepth 1 -type f -name '.[0-9A-F][0-9A-F]*' 2>/dev/null | \
while IFS= read -r file; do
filename=$(basename "$file")
# 基础正则表达式匹配 32 位哈希 / Basic regex to match 32-character hash
if echo "$filename" | grep -Eq '^\.([0-9A-F]{32})$'; then
echo "删除哈希文件: $filename / Deleting hash file: $filename"
rm -f "$file"
fi
done
# ---------- 处理偏好设置文件 / Handling preferences plist file ----------
echo "处理偏好设置文件... / Processing preferences plist file..."
if [[ -f "$PLIST_FILE" ]]; then
# 获取所有符合32位哈希格式的顶级键 / Get all top-level keys matching 32-character hash
keys_to_delete=$(/usr/libexec/PlistBuddy -c "Print" "$PLIST_FILE" | grep -Eoa "^\s{4}[0-9A-F]{32}" | tr -d ' ')
if [[ -n "$keys_to_delete" ]]; then
while IFS= read -r key; do
echo "正在删除密钥: $key / Deleting key: $key"
/usr/libexec/PlistBuddy -c "Delete :$key" "$PLIST_FILE" 2>/dev/null || true
done <<< "$keys_to_delete"
else
echo "未找到需要删除的32位哈希密钥。/ No 32-character hash keys found to delete."
fi
else
echo "偏好设置文件不存在: $PLIST_FILE / Preferences plist file not found: $PLIST_FILE"
fi
# ---------- 清理钥匙串中的试用期追踪条目 / Clean trial tracking entries in Keychain ----------
echo "清理钥匙串中的试用期追踪条目... / Cleaning trial tracking entries in Keychain..."
# 获取所有 Navicat 钥匙串条目的账户名 / Get all Navicat keychain entry account names
# 使用 awk 提取紧跟在服务名后的账户名 / Use awk to extract account names following service name
keychain_accounts=$(security dump-keychain ~/Library/Keychains/login.keychain-db 2>/dev/null | \
awk '/0x00000007.*'"$KEYCHAIN_SERVICE"'/{found=1} found && /"acct"/{print; found=0}' | \
sed 's/.*<blob>="\([^"]*\)".*/\1/')
deleted_count=0
if [[ -n "$keychain_accounts" ]]; then
while IFS= read -r account; do
# 只删除32位哈希格式的账户试用期追踪保留用户的连接密码
# Only delete 32-character hash accounts (trial tracking), preserve user connection passwords
if echo "$account" | grep -Eq '^[0-9A-F]{32}$'; then
echo "删除钥匙串条目: $account / Deleting keychain entry: $account"
security delete-generic-password -s "$KEYCHAIN_SERVICE" -a "$account" >/dev/null 2>&1 || true
((deleted_count++))
fi
done <<< "$keychain_accounts"
fi
if [[ $deleted_count -eq 0 ]]; then
echo "未找到需要删除的钥匙串条目。/ No keychain entries found to delete."
else
echo "已删除 $deleted_count 个钥匙串条目。/ Deleted $deleted_count keychain entries."
fi