feat: Add alternative script installation methods for Linux/macOS and Windows

- Introduced platform-specific scripts (`cursor_modifier.sh` for Linux/macOS and `cursor_modifier.bat` for Windows) to streamline the installation process.
- Scripts automate system language detection, close running Cursor instances, generate new IDs, and update configuration files with a user-friendly interface.
- Updated README.md to include detailed instructions for using the new scripts, enhancing user experience and accessibility.

These changes improve the installation process by providing users with flexible options for setup across different operating systems.
This commit is contained in:
Xx 2024-12-13 16:01:06 +08:00
parent 24287ac575
commit 1a4e5c737f
3 changed files with 357 additions and 0 deletions

View File

@ -66,6 +66,32 @@ Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManage
```
5. Save the file and restart Cursor
#### Script Method (Alternative)
If you prefer using scripts directly, you can use these platform-specific scripts:
**For Linux/macOS:**
1. Download the [cursor_modifier.sh](scripts/cursor_modifier.sh)
2. Make it executable:
```bash
chmod +x cursor_modifier.sh
```
3. Run with sudo:
```bash
sudo ./cursor_modifier.sh
```
**For Windows:**
1. Download the [cursor_modifier.bat](scripts/cursor_modifier.bat)
2. Right-click and "Run as administrator"
These scripts will:
- Automatically detect system language (English/Chinese)
- Check for and close any running Cursor instances
- Generate new random IDs
- Update the configuration file
- Show the results with a nice UI
### 🔧 Technical Details
The program modifies Cursor's `storage.json` config file:
@ -135,6 +161,32 @@ Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManage
```
5. 保存文件并重启 Cursor
#### 脚本方法(替代方法)
如果您喜欢直接使用脚本,可以使用这些特定平台的脚本:
**适用于 Linux/macOS**
1. 下载 [cursor_modifier.sh](scripts/cursor_modifier.sh)
2. 使其可执行:
```bash
chmod +x cursor_modifier.sh
```
3. 用 sudo 运行
```bash
sudo ./cursor_modifier.sh
```
**适用于 Windows**
1. 下载 [cursor_modifier.bat](脚本/cursor_modifier.bat
2. 右键单击并 “以管理员身份运行”。
这些脚本将
- 自动检测系统语言(英语/中文)
- 检查并关闭任何正在运行的光标实例
- 生成新的随机 ID
- 更新配置文件
- 以漂亮的用户界面显示结果
### 🔧 技术细节
程序修改Cursor的`storage.json`配置文件:

141
cursor_modifier.bat Normal file
View File

@ -0,0 +1,141 @@
@echo off
chcp 65001 >nul
setlocal EnableDelayedExpansion
:: 版本号
set "VERSION=1.0.1"
:: 检测语言
for /f "tokens=2 delims==" %%a in ('wmic os get OSLanguage /value') do set OSLanguage=%%a
if "%OSLanguage%"=="2052" (
set "LANG=cn"
) else (
set "LANG=en"
)
:: 多语言文本
if "%LANG%"=="cn" (
set "SUCCESS_MSG=[√] 配置文件已成功更新!"
set "RESTART_MSG=[!] 请手动重启 Cursor 以使更新生效"
set "READING_CONFIG=正在读取配置文件..."
set "GENERATING_IDS=正在生成新的标识符..."
set "CHECKING_PROCESSES=正在检查运行中的 Cursor 实例..."
set "CLOSING_PROCESSES=正在关闭 Cursor 实例..."
set "PROCESSES_CLOSED=所有 Cursor 实例已关闭"
set "PLEASE_WAIT=请稍候..."
) else (
set "SUCCESS_MSG=[√] Configuration file updated successfully!"
set "RESTART_MSG=[!] Please restart Cursor manually for changes to take effect"
set "READING_CONFIG=Reading configuration file..."
set "GENERATING_IDS=Generating new identifiers..."
set "CHECKING_PROCESSES=Checking for running Cursor instances..."
set "CLOSING_PROCESSES=Closing Cursor instances..."
set "PROCESSES_CLOSED=All Cursor instances have been closed"
set "PLEASE_WAIT=Please wait..."
)
:: 检查管理员权限
net session >nul 2>&1
if %errorLevel% neq 0 (
echo 请以管理员身份运行此脚本
echo Please run this script as administrator
pause
exit /b 1
)
:: 生成随机ID
:generateId
set "id="
for /L %%i in (1,1,32) do (
set /a "r=!random! %% 16"
set "hex=0123456789abcdef"
for %%j in (!r!) do set "id=!id!!hex:~%%j,1!"
)
exit /b
:: 生成UUID
:generateUUID
set "uuid="
for /L %%i in (1,1,32) do (
set /a "r=!random! %% 16"
set "hex=0123456789abcdef"
for %%j in (!r!) do set "uuid=!uuid!!hex:~%%j,1!"
if %%i==8 set "uuid=!uuid!-"
if %%i==12 set "uuid=!uuid!-"
if %%i==16 set "uuid=!uuid!-"
if %%i==20 set "uuid=!uuid!-"
)
exit /b
:: 主程序
:main
cls
call :printBanner
echo %CHECKING_PROCESSES%
tasklist | find /i "Cursor.exe" >nul
if %errorLevel% equ 0 (
echo %CLOSING_PROCESSES%
taskkill /F /IM "Cursor.exe" >nul 2>&1
timeout /t 2 >nul
echo %PROCESSES_CLOSED%
)
set "CONFIG_PATH=%APPDATA%\Cursor\User\globalStorage\storage.json"
echo %READING_CONFIG%
echo %GENERATING_IDS%
call :generateId
set "machineId=!id!"
call :generateId
set "macMachineId=!id!"
call :generateUUID
set "devDeviceId=!uuid!"
call :generateId
set "sqmId=!id!"
:: 创建配置目录
if not exist "%APPDATA%\Cursor\User\globalStorage" (
mkdir "%APPDATA%\Cursor\User\globalStorage"
)
:: 生成配置文件
(
echo {
echo "telemetry.macMachineId": "%macMachineId%",
echo "telemetry.machineId": "%machineId%",
echo "telemetry.devDeviceId": "%devDeviceId%",
echo "telemetry.sqmId": "%sqmId%",
echo "lastModified": "%date:~10,4%-%date:~4,2%-%date:~7,2%T%time:~0,2%:%time:~3,2%:%time:~6,2%Z",
echo "version": "%VERSION%"
echo }
) > "%CONFIG_PATH%"
echo.
echo ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
echo %SUCCESS_MSG%
echo %RESTART_MSG%
echo ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
echo.
echo Config file location:
echo %CONFIG_PATH%
echo.
pause
exit /b
:: 打印banner
:printBanner
echo.
echo ██████╗██╗ ██╗██████╗ ███████╗ ██████╗ ██████╗
echo ██╔════╝██║ ██║██╔══██╗██╔════╝██╔ ══██╗██╔══██╗
echo ██║ ██║ ██║██████╔╝███████╗██║ ██║██████╔╝
echo ██║ ██║ ██║██╔══██╗╚════██║██║ ██║██╔══██╗
echo ╚██████╗╚██████╔╝██║ ██║███████║╚██████╔╝██║ ██║
echo ╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝ ╚═════╝ ╚═╝ ╚═╝
echo.
echo ^>^> Cursor ID Modifier v1.0 ^<^<
echo [ By Pancake Fruit Rolled Shark Chili ]
echo.
exit /b
endlocal

164
cursor_modifier.sh Normal file
View File

@ -0,0 +1,164 @@
#!/bin/bash
# 版本号
VERSION="1.0.1"
# 颜色定义
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
CYAN='\033[0;36m'
NC='\033[0m'
# 语言检测
detect_language() {
local lang=$(locale | grep "LANG=" | cut -d= -f2)
if [[ $lang == *"zh"* ]]; then
echo "cn"
else
echo "en"
fi
}
LANG=$(detect_language)
# 多语言文本
if [ "$LANG" == "cn" ]; then
SUCCESS_MSG="[√] 配置文件已成功更新!"
RESTART_MSG="[!] 请手动重启 Cursor 以使更新生效"
READING_CONFIG="正在读取配置文件..."
GENERATING_IDS="正在生成新的标识符..."
CHECKING_PROCESSES="正在检查运行中的 Cursor 实例..."
CLOSING_PROCESSES="正在关闭 Cursor 实例..."
PROCESSES_CLOSED="所有 Cursor 实例已关闭"
PLEASE_WAIT="请稍候..."
else
SUCCESS_MSG="[√] Configuration file updated successfully!"
RESTART_MSG="[!] Please restart Cursor manually for changes to take effect"
READING_CONFIG="Reading configuration file..."
GENERATING_IDS="Generating new identifiers..."
CHECKING_PROCESSES="Checking for running Cursor instances..."
CLOSING_PROCESSES="Closing Cursor instances..."
PROCESSES_CLOSED="All Cursor instances have been closed"
PLEASE_WAIT="Please wait..."
fi
# 生成随机ID
generate_machine_id() {
openssl rand -hex 32
}
generate_dev_device_id() {
printf '%04x%04x-%04x-%04x-%04x-%04x%04x%04x' \
$RANDOM $RANDOM \
$RANDOM \
$(($RANDOM & 0x0fff | 0x4000)) \
$(($RANDOM & 0x3fff | 0x8000)) \
$RANDOM $RANDOM $RANDOM
}
# 获取配置文件路径
get_config_path() {
local username=$1
case "$(uname)" in
"Darwin")
echo "/Users/$username/Library/Application Support/Cursor/User/globalStorage/storage.json"
;;
"Linux")
echo "/home/$username/.config/Cursor/User/globalStorage/storage.json"
;;
*)
echo "Unsupported operating system"
exit 1
;;
esac
}
# 检查Cursor进程
check_cursor_running() {
pgrep -f "Cursor|AppRun" >/dev/null
}
# 关闭Cursor进程
kill_cursor_processes() {
echo -e "${CYAN}$CLOSING_PROCESSES${NC}"
pkill -f "Cursor|AppRun"
sleep 2
if check_cursor_running; then
pkill -9 -f "Cursor|AppRun"
fi
echo -e "${GREEN}$PROCESSES_CLOSED${NC}"
}
# 打印赛博朋克风格banner
print_banner() {
echo -e "${CYAN}"
echo ' ██████╗██╗ ██╗██████╗ ███████╗ ██████╗ ██████╗ '
echo ' ██╔════╝██║ ██║██╔══██╗██╔════╝██╔═══██╗██╔══██╗'
echo ' ██║ ██║ ██║██████╔╝███████╗██║ ██║██████╔╝'
echo ' ██║ ██║ ██║██╔══██╗╚════██║██║ ██║██╔══██╗'
echo ' ╚██████╗╚██████╔╝██║ ██║███████║╚██████╔╝██║ ██║'
echo ' ╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝ ╚═════╝ ╚═╝ ╚═╝'
echo -e "${NC}"
echo -e "${YELLOW}\t\t>> Cursor ID Modifier v1.0 <<${NC}"
echo -e "${CYAN}\t\t [ By Pancake Fruit Rolled Shark Chili ]${NC}"
echo
}
# 主函数
main() {
# 检查root权限
if [ "$EUID" -ne 0 ]; then
echo "Please run as root"
exit 1
fi
# 获取实际用户名
REAL_USER=${SUDO_USER:-$USER}
clear
print_banner
# 确保Cursor已关闭
if check_cursor_running; then
kill_cursor_processes
fi
CONFIG_PATH=$(get_config_path "$REAL_USER")
echo -e "${CYAN}$READING_CONFIG${NC}"
# 生成新配置
echo -e "${CYAN}$GENERATING_IDS${NC}"
NEW_CONFIG=$(cat <<EOF
{
"telemetry.macMachineId": "$(generate_machine_id)",
"telemetry.machineId": "$(generate_machine_id)",
"telemetry.devDeviceId": "$(generate_dev_device_id)",
"telemetry.sqmId": "$(generate_machine_id)",
"lastModified": "$(date -u +"%Y-%m-%dT%H:%M:%SZ")",
"version": "$VERSION"
}
EOF
)
# 创建目录(如果不存在)
mkdir -p "$(dirname "$CONFIG_PATH")"
# 保存配置
echo "$NEW_CONFIG" > "$CONFIG_PATH"
chown "$REAL_USER" "$CONFIG_PATH"
chmod 644 "$CONFIG_PATH"
# 显示成功消息
echo -e "\n${GREEN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e "${GREEN}$SUCCESS_MSG${NC}"
echo -e "${YELLOW}$RESTART_MSG${NC}"
echo -e "${GREEN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e "\n<><6E><EFBFBD>置文件位置/Config file location:"
echo -e "${CYAN}$CONFIG_PATH${NC}\n"
read -p "Press Enter to exit..."
}
main "$@"