mirror of
https://github.com/yuaotian/go-cursor-help.git
synced 2026-03-07 22:33:39 +00:00
chore: remove CHANGELOG.md and update README with proxy download instructions for domestic users
- Deleted the CHANGELOG.md file as it is no longer needed for project documentation. - Updated the README.md to include proxy download instructions for Linux and macOS users in China. - Added similar instructions for Windows users to facilitate easier access to installation scripts.
This commit is contained in:
241
scripts/run/cursor_linux_id_modifier.sh
Normal file
241
scripts/run/cursor_linux_id_modifier.sh
Normal file
@@ -0,0 +1,241 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 设置错误处理
|
||||
set -e
|
||||
|
||||
# 颜色定义
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# 日志函数
|
||||
log_info() {
|
||||
echo -e "${GREEN}[INFO]${NC} $1"
|
||||
}
|
||||
|
||||
log_warn() {
|
||||
echo -e "${YELLOW}[WARN]${NC} $1"
|
||||
}
|
||||
|
||||
log_error() {
|
||||
echo -e "${RED}[ERROR]${NC} $1"
|
||||
}
|
||||
|
||||
log_debug() {
|
||||
echo -e "${BLUE}[DEBUG]${NC} $1"
|
||||
}
|
||||
|
||||
# 获取当前用户
|
||||
get_current_user() {
|
||||
if [ "$EUID" -eq 0 ]; then
|
||||
echo "$SUDO_USER"
|
||||
else
|
||||
echo "$USER"
|
||||
fi
|
||||
}
|
||||
|
||||
CURRENT_USER=$(get_current_user)
|
||||
if [ -z "$CURRENT_USER" ]; then
|
||||
log_error "无法获取用户名"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 定义配置文件路径 (Linux 路径)
|
||||
STORAGE_FILE="/home/$CURRENT_USER/.config/Cursor/User/globalStorage/storage.json"
|
||||
BACKUP_DIR="/home/$CURRENT_USER/.config/Cursor/User/globalStorage/backups"
|
||||
|
||||
# 检查权限
|
||||
check_permissions() {
|
||||
if [ "$EUID" -ne 0 ]; then
|
||||
log_error "请使用 sudo 运行此脚本"
|
||||
echo "示例: sudo $0"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# 检查并关闭 Cursor 进程
|
||||
check_and_kill_cursor() {
|
||||
log_info "检查 Cursor 进程..."
|
||||
|
||||
local attempt=1
|
||||
local max_attempts=5
|
||||
|
||||
# 函数:获取进程详细信息
|
||||
get_process_details() {
|
||||
local process_name="$1"
|
||||
log_debug "正在获取 $process_name 进程详细信息:"
|
||||
ps aux | grep -i "$process_name" | grep -v grep
|
||||
}
|
||||
|
||||
while [ $attempt -le $max_attempts ]; do
|
||||
CURSOR_PIDS=$(pgrep -i "cursor" || true)
|
||||
|
||||
if [ -z "$CURSOR_PIDS" ]; then
|
||||
log_info "未发现运行中的 Cursor 进程"
|
||||
return 0
|
||||
fi
|
||||
|
||||
log_warn "发现 Cursor 进程正在运行"
|
||||
get_process_details "cursor"
|
||||
|
||||
log_warn "尝试关闭 Cursor 进程..."
|
||||
|
||||
if [ $attempt -eq $max_attempts ]; then
|
||||
log_warn "尝试强制终止进程..."
|
||||
kill -9 $CURSOR_PIDS 2>/dev/null || true
|
||||
else
|
||||
kill $CURSOR_PIDS 2>/dev/null || true
|
||||
fi
|
||||
|
||||
sleep 1
|
||||
|
||||
if ! pgrep -i "cursor" > /dev/null; then
|
||||
log_info "Cursor 进程已成功关闭"
|
||||
return 0
|
||||
fi
|
||||
|
||||
log_warn "等待进程关闭,尝试 $attempt/$max_attempts..."
|
||||
((attempt++))
|
||||
done
|
||||
|
||||
log_error "在 $max_attempts 次尝试后仍无法关闭 Cursor 进程"
|
||||
get_process_details "cursor"
|
||||
log_error "请手动关闭进程后重试"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# 备份配置文件
|
||||
backup_config() {
|
||||
if [ ! -f "$STORAGE_FILE" ]; then
|
||||
log_warn "配置文件不存在,跳过备份"
|
||||
return 0
|
||||
fi
|
||||
|
||||
mkdir -p "$BACKUP_DIR"
|
||||
local backup_file="$BACKUP_DIR/storage.json.backup_$(date +%Y%m%d_%H%M%S)"
|
||||
|
||||
if cp "$STORAGE_FILE" "$backup_file"; then
|
||||
chmod 644 "$backup_file"
|
||||
chown "$CURRENT_USER:$CURRENT_USER" "$backup_file"
|
||||
log_info "配置已备份到: $backup_file"
|
||||
else
|
||||
log_error "备份失败"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# 生成随机 ID
|
||||
generate_random_id() {
|
||||
# Linux 可以使用 /dev/urandom
|
||||
head -c 32 /dev/urandom | xxd -p
|
||||
}
|
||||
|
||||
# 生成随机 UUID
|
||||
generate_uuid() {
|
||||
# Linux 使用 uuidgen 命令
|
||||
uuidgen | tr '[:upper:]' '[:lower:]'
|
||||
}
|
||||
|
||||
# 生成新的配置
|
||||
generate_new_config() {
|
||||
local machine_id="auth0|user_$(generate_random_id)"
|
||||
local mac_machine_id=$(generate_random_id)
|
||||
local device_id=$(generate_uuid | tr '[:upper:]' '[:lower:]')
|
||||
local sqm_id="{$(generate_uuid | tr '[:lower:]' '[:upper:]')}"
|
||||
|
||||
if [ -f "$STORAGE_FILE" ]; then
|
||||
# 直接修改现有文件 (Linux sed 不需要 '')
|
||||
sed -i "s/\"telemetry\.machineId\":[[:space:]]*\"[^\"]*\"/\"telemetry.machineId\": \"$machine_id\"/" "$STORAGE_FILE"
|
||||
sed -i "s/\"telemetry\.macMachineId\":[[:space:]]*\"[^\"]*\"/\"telemetry.macMachineId\": \"$mac_machine_id\"/" "$STORAGE_FILE"
|
||||
sed -i "s/\"telemetry\.devDeviceId\":[[:space:]]*\"[^\"]*\"/\"telemetry.devDeviceId\": \"$device_id\"/" "$STORAGE_FILE"
|
||||
sed -i "s/\"telemetry\.sqmId\":[[:space:]]*\"[^\"]*\"/\"telemetry.sqmId\": \"$sqm_id\"/" "$STORAGE_FILE"
|
||||
else
|
||||
# 创建新文件
|
||||
echo "{" > "$STORAGE_FILE"
|
||||
echo " \"telemetry.machineId\": \"$machine_id\"," >> "$STORAGE_FILE"
|
||||
echo " \"telemetry.macMachineId\": \"$mac_machine_id\"," >> "$STORAGE_FILE"
|
||||
echo " \"telemetry.devDeviceId\": \"$device_id\"," >> "$STORAGE_FILE"
|
||||
echo " \"telemetry.sqmId\": \"$sqm_id\"" >> "$STORAGE_FILE"
|
||||
echo "}" >> "$STORAGE_FILE"
|
||||
fi
|
||||
|
||||
chmod 644 "$STORAGE_FILE"
|
||||
chown "$CURRENT_USER:$CURRENT_USER" "$STORAGE_FILE"
|
||||
|
||||
echo
|
||||
log_info "已更新配置:"
|
||||
log_debug "machineId: $machine_id"
|
||||
log_debug "macMachineId: $mac_machine_id"
|
||||
log_debug "devDeviceId: $device_id"
|
||||
log_debug "sqmId: $sqm_id"
|
||||
}
|
||||
|
||||
# 显示文件树结构
|
||||
show_file_tree() {
|
||||
local base_dir=$(dirname "$STORAGE_FILE")
|
||||
echo
|
||||
log_info "文件结构:"
|
||||
echo -e "${BLUE}$base_dir${NC}"
|
||||
echo "├── globalStorage"
|
||||
echo "│ ├── storage.json (已修改)"
|
||||
echo "│ └── backups"
|
||||
|
||||
# 列出备份文件
|
||||
if [ -d "$BACKUP_DIR" ]; then
|
||||
local backup_files=("$BACKUP_DIR"/*)
|
||||
if [ ${#backup_files[@]} -gt 0 ]; then
|
||||
for file in "${backup_files[@]}"; do
|
||||
if [ -f "$file" ]; then
|
||||
echo "│ └── $(basename "$file")"
|
||||
fi
|
||||
done
|
||||
else
|
||||
echo "│ └── (空)"
|
||||
fi
|
||||
fi
|
||||
echo
|
||||
}
|
||||
|
||||
# 显示公众号信息
|
||||
show_follow_info() {
|
||||
echo
|
||||
echo -e "${GREEN}================================${NC}"
|
||||
echo -e "${YELLOW} 关注公众号【煎饼果子AI】一起交流更多Cursor技巧和AI知识 ${NC}"
|
||||
echo -e "${GREEN}================================${NC}"
|
||||
echo
|
||||
}
|
||||
|
||||
# 主函数
|
||||
main() {
|
||||
clear
|
||||
# 显示 CURSOR Logo
|
||||
echo -e "
|
||||
██████╗██╗ ██╗██████╗ ███████╗ ██████╗ ██████╗
|
||||
██╔════╝██║ ██║██╔══██╗██╔════╝██╔═══██╗██╔══██╗
|
||||
██║ ██║ ██║██████╔╝███████╗██║ ██║██████╔╝
|
||||
██║ ██║ ██║██╔══██╗╚════██║██║ ██║██╔══██╗
|
||||
╚██████╗╚██████╔╝██║ ██║███████║╚██████╔╝██║ ██║
|
||||
╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝ ╚═════╝ ╚═╝ ╚═╝
|
||||
"
|
||||
echo -e "${BLUE}================================${NC}"
|
||||
echo -e "${GREEN} Cursor ID 修改工具${NC}"
|
||||
echo -e "${BLUE}================================${NC}"
|
||||
echo
|
||||
|
||||
check_permissions
|
||||
check_and_kill_cursor
|
||||
backup_config
|
||||
generate_new_config
|
||||
|
||||
echo
|
||||
log_info "操作完成!"
|
||||
show_follow_info
|
||||
show_file_tree
|
||||
log_info "请重启 Cursor 以应用新的配置"
|
||||
echo
|
||||
}
|
||||
|
||||
# 执行主函数
|
||||
main
|
||||
Reference in New Issue
Block a user