mirror of
https://github.com/yuaotian/go-cursor-help.git
synced 2025-06-08 12:32:06 +08:00
feat: lean automated releases
This commit is contained in:
parent
0d03e6c462
commit
f89aa17acf
37
.github/workflows/release.yml
vendored
Normal file
37
.github/workflows/release.yml
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
name: Release
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- 'v*'
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
jobs:
|
||||
goreleaser:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
check-latest: true
|
||||
|
||||
- name: Set Repository Variables
|
||||
run: |
|
||||
echo "GITHUB_REPOSITORY_OWNER=$(echo ${{ github.repository }} | cut -d '/' -f 1)" >> $GITHUB_ENV
|
||||
echo "GITHUB_REPOSITORY_NAME=$(echo ${{ github.repository }} | cut -d '/' -f 2)" >> $GITHUB_ENV
|
||||
|
||||
- name: Run GoReleaser
|
||||
uses: goreleaser/goreleaser-action@v5
|
||||
with:
|
||||
distribution: goreleaser
|
||||
version: latest
|
||||
args: release --clean
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
2
.gitignore
vendored
2
.gitignore
vendored
@ -18,3 +18,5 @@ go.sum
|
||||
# System files
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
|
||||
.vscode
|
||||
|
56
.goreleaser.yml
Normal file
56
.goreleaser.yml
Normal file
@ -0,0 +1,56 @@
|
||||
project_name: cursor-id-modifier
|
||||
|
||||
before:
|
||||
hooks:
|
||||
- go mod tidy
|
||||
|
||||
builds:
|
||||
- env:
|
||||
- CGO_ENABLED=0
|
||||
ldflags:
|
||||
- -s -w -X main.version={{.Version}}
|
||||
goos:
|
||||
- linux
|
||||
- windows
|
||||
- darwin
|
||||
goarch:
|
||||
- amd64
|
||||
- arm64
|
||||
mod_timestamp: '{{ .CommitTimestamp }}'
|
||||
flags:
|
||||
- -trimpath
|
||||
binary: cursor_id_modifier_{{ .Version }}_{{ .Os }}_{{ .Arch }}
|
||||
|
||||
archives:
|
||||
- format: binary
|
||||
name_template: "{{ .Binary }}"
|
||||
allow_different_binary_count: true
|
||||
|
||||
changelog:
|
||||
use: github
|
||||
sort: asc
|
||||
groups:
|
||||
- title: Features
|
||||
regexp: "^.*feat[(\\w)]*:+.*$"
|
||||
order: 0
|
||||
- title: 'Bug Fixes'
|
||||
regexp: "^.*fix[(\\w)]*:+.*$"
|
||||
order: 1
|
||||
- title: Others
|
||||
order: 999
|
||||
filters:
|
||||
exclude:
|
||||
- '^docs:'
|
||||
- '^test:'
|
||||
- '^ci:'
|
||||
- '^chore:'
|
||||
- Merge pull request
|
||||
- Merge branch
|
||||
|
||||
release:
|
||||
github:
|
||||
owner: '{{ .Env.GITHUB_REPOSITORY_OWNER }}'
|
||||
name: '{{ .Env.GITHUB_REPOSITORY_NAME }}'
|
||||
draft: false
|
||||
prerelease: auto
|
||||
mode: replace
|
31
.vscode/settings.json
vendored
31
.vscode/settings.json
vendored
@ -1,31 +0,0 @@
|
||||
{
|
||||
"cSpell.words": [
|
||||
"apprun",
|
||||
"buildmode",
|
||||
"certutil",
|
||||
"dylib",
|
||||
"enabledelayedexpansion",
|
||||
"endlocal",
|
||||
"errorlevel",
|
||||
"fatih",
|
||||
"gcflags",
|
||||
"GOARCH",
|
||||
"hashfile",
|
||||
"IMAGENAME",
|
||||
"killall",
|
||||
"ldflags",
|
||||
"LOCALAPPDATA",
|
||||
"mktemp",
|
||||
"msys",
|
||||
"pgrep",
|
||||
"pkill",
|
||||
"runas",
|
||||
"setlocal",
|
||||
"taskkill",
|
||||
"tasklist",
|
||||
"trimpath",
|
||||
"urandom",
|
||||
"uuidgen",
|
||||
"xattr"
|
||||
]
|
||||
}
|
125
README.md
125
README.md
@ -27,69 +27,22 @@ this is a mistake.
|
||||
|
||||
### 💻 System Support
|
||||
|
||||
**Windows** ✅ x64
|
||||
**macOS** ✅ Intel & M-series
|
||||
**Linux** ✅ x64 & ARM64
|
||||
**Windows** ✅ AMD64 & ARM64
|
||||
**macOS** ✅ AMD64 & ARM64
|
||||
**Linux** ✅ AMD64 & ARM64
|
||||
|
||||
### 📥 Installation
|
||||
|
||||
#### Automatic Installation
|
||||
|
||||
**Linux/macOS**
|
||||
```bash
|
||||
curl -fsSL https://raw.githubusercontent.com/yuaotian/go-cursor-help/refs/heads/master/install.sh | bash -s -- --auto-sudo && rm -f /tmp/cursor_id_modifier_*
|
||||
curl -fsSL https://raw.githubusercontent.com/yuaotian/go-cursor-help/master/install.sh | bash
|
||||
```
|
||||
|
||||
**Windows** (Run in PowerShell as Admin)
|
||||
```powershell
|
||||
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://raw.githubusercontent.com/yuaotian/go-cursor-help/refs/heads/master/bin/cursor_id_modifier_v2.5.0_windows_amd64.exe')); Remove-Item -Path "$env:TEMP\cursor-id-modifier.exe" -ErrorAction SilentlyContinue
|
||||
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; $arch = if ([Environment]::Is64BitOperatingSystem) { if ([System.Runtime.InteropServices.RuntimeInformation]::ProcessArchitecture -eq 'Arm64') { 'arm64' } else { 'amd64' } } else { 'amd64' }; $ver = (irm https://api.github.com/repos/yuaotian/go-cursor-help/releases/latest).tag_name.TrimStart('v'); $outfile = "$env:TEMP\cursor_id_modifier.exe"; irm "https://github.com/yuaotian/go-cursor-help/releases/download/v${ver}/cursor_id_modifier_${ver}_windows_${arch}.exe" -OutFile $outfile; & $outfile; Remove-Item -Path $outfile -ErrorAction SilentlyContinue
|
||||
```
|
||||
|
||||
#### Manual Method
|
||||
|
||||
1. Close Cursor completely
|
||||
2. Navigate to the configuration file location:
|
||||
- Windows: `%APPDATA%\Cursor\User\globalStorage\storage.json`
|
||||
- macOS: `~/Library/Application Support/Cursor/User/globalStorage/storage.json`
|
||||
- Linux: `~/.config/Cursor/User/globalStorage/storage.json`
|
||||
3. Create a backup of `storage.json`
|
||||
4. Edit `storage.json` and update these fields with new random UUIDs:
|
||||
```json
|
||||
{
|
||||
"telemetry.machineId": "generate-new-uuid",
|
||||
"telemetry.macMachineId": "generate-new-uuid",
|
||||
"telemetry.devDeviceId": "generate-new-uuid",
|
||||
"telemetry.sqmId": "generate-new-uuid"
|
||||
}
|
||||
```
|
||||
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](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](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:
|
||||
@ -120,69 +73,22 @@ this is a mistake.
|
||||
|
||||
### 💻 系统支持
|
||||
|
||||
**Windows** ✅ x64
|
||||
**macOS** ✅ Intel和M系列
|
||||
**Linux** ✅ x64和ARM64
|
||||
**Windows** ✅ AMD64和ARM64
|
||||
**macOS** ✅ AMD64和ARM64
|
||||
**Linux** ✅ AMD64和ARM64
|
||||
|
||||
### 📥 安装方法
|
||||
|
||||
#### 自动安装
|
||||
|
||||
**Linux/macOS**
|
||||
```bash
|
||||
curl -fsSL https://raw.githubusercontent.com/yuaotian/go-cursor-help/refs/heads/master/install.sh | bash -s -- --auto-sudo && rm -f /tmp/cursor_id_modifier_*
|
||||
curl -fsSL https://raw.githubusercontent.com/yuaotian/go-cursor-help/master/install.sh | bash
|
||||
```
|
||||
|
||||
**Windows** (以管理员身份运行PowerShell)
|
||||
```powershell
|
||||
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://raw.githubusercontent.com/yuaotian/go-cursor-help/refs/heads/master/bin/cursor_id_modifier_v2.5.0_windows_amd64.exe')); Remove-Item -Path "$env:TEMP\cursor-id-modifier.exe" -ErrorAction SilentlyContinue
|
||||
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; $arch = if ([Environment]::Is64BitOperatingSystem) { if ([System.Runtime.InteropServices.RuntimeInformation]::ProcessArchitecture -eq 'Arm64') { 'arm64' } else { 'amd64' } } else { 'amd64' }; $ver = (irm https://api.github.com/repos/yuaotian/go-cursor-help/releases/latest).tag_name.TrimStart('v'); $outfile = "$env:TEMP\cursor_id_modifier.exe"; irm "https://github.com/yuaotian/go-cursor-help/releases/download/v${ver}/cursor_id_modifier_${ver}_windows_${arch}.exe" -OutFile $outfile; & $outfile; Remove-Item -Path $outfile -ErrorAction SilentlyContinue
|
||||
```
|
||||
|
||||
#### 手动方法
|
||||
|
||||
1. 完全关闭 Cursor
|
||||
2. 找到配置文件位置:
|
||||
- Windows: `%APPDATA%\Cursor\User\globalStorage\storage.json`
|
||||
- macOS: `~/Library/Application Support/Cursor/User/globalStorage/storage.json`
|
||||
- Linux: `~/.config/Cursor/User/globalStorage/storage.json`
|
||||
3. 备份 `storage.json`
|
||||
4. 编辑 `storage.json` 并更新以下字段(使用新的随机UUID):
|
||||
```json
|
||||
{
|
||||
"telemetry.machineId": "生成新的uuid",
|
||||
"telemetry.macMachineId": "生成新的uuid",
|
||||
"telemetry.devDeviceId": "生成新的uuid",
|
||||
"telemetry.sqmId": "生成新的uuid"
|
||||
}
|
||||
```
|
||||
5. 保存文件并重启 Cursor
|
||||
|
||||
#### 脚本方法(替代方法)
|
||||
|
||||
如果您喜欢直接使用脚本,可以使用这些特定平台的脚本:
|
||||
|
||||
**适用于 Linux/macOS:**
|
||||
1. 下载 [cursor_modifier.sh](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`配置文件:
|
||||
@ -201,14 +107,3 @@ Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManage
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2024
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,7 +0,0 @@
|
||||
MD5 Checksums
|
||||
=============
|
||||
|
||||
c3f03388afd01cd2d9f6c58348abf8e1 cursor_id_modifier_v2.5.0_windows_amd64.exe
|
||||
b2caec6c3bede8f51245e5b74b11b96c cursor_id_modifier_v2.5.0_darwin_amd64_intel
|
||||
8e93f913d653e26bf522bde78b51a26a cursor_id_modifier_v2.5.0_darwin_arm64_m1
|
||||
73db2eb340c0f5878a206ddc63693f77 cursor_id_modifier_v2.5.0_linux_amd64
|
@ -1,139 +0,0 @@
|
||||
@echo off
|
||||
chcp 65001 >nul
|
||||
setlocal EnableDelayedExpansion
|
||||
|
||||
:: 版本号
|
||||
set "VERSION=2.5.0"
|
||||
|
||||
:: 检测语言
|
||||
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
|
||||
)
|
||||
|
||||
:: 主程序
|
||||
: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%
|
||||
:: 生成随机ID
|
||||
set "machineId="
|
||||
set "macMachineId="
|
||||
set "devDeviceId="
|
||||
set "sqmId="
|
||||
|
||||
:: 生成32位随机ID
|
||||
for /L %%i in (1,1,32) do (
|
||||
set /a "r=!random! %% 16"
|
||||
set "hex=0123456789abcdef"
|
||||
for %%j in (!r!) do set "machineId=!machineId!!hex:~%%j,1!"
|
||||
)
|
||||
|
||||
for /L %%i in (1,1,32) do (
|
||||
set /a "r=!random! %% 16"
|
||||
for %%j in (!r!) do set "macMachineId=!macMachineId!!hex:~%%j,1!"
|
||||
)
|
||||
|
||||
:: 生成UUID格式的devDeviceId
|
||||
for /L %%i in (1,1,32) do (
|
||||
set /a "r=!random! %% 16"
|
||||
for %%j in (!r!) do set "devDeviceId=!devDeviceId!!hex:~%%j,1!"
|
||||
if %%i==8 set "devDeviceId=!devDeviceId!-"
|
||||
if %%i==12 set "devDeviceId=!devDeviceId!-"
|
||||
if %%i==16 set "devDeviceId=!devDeviceId!-"
|
||||
if %%i==20 set "devDeviceId=!devDeviceId!-"
|
||||
)
|
||||
|
||||
for /L %%i in (1,1,32) do (
|
||||
set /a "r=!random! %% 16"
|
||||
for %%j in (!r!) do set "sqmId=!sqmId!!hex:~%%j,1!"
|
||||
)
|
||||
|
||||
:: 创建配置目录
|
||||
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 }
|
||||
) > "%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
|
@ -1,211 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 版本号 - 与其他文件保持一致
|
||||
VERSION="2.5.0"
|
||||
|
||||
# 颜色定义
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
CYAN='\033[0;36m'
|
||||
NC='\033[0m'
|
||||
|
||||
# 语言检测优化
|
||||
detect_language() {
|
||||
local lang
|
||||
if [ -n "$LANG" ]; then
|
||||
lang="$LANG"
|
||||
else
|
||||
lang=$(locale | grep "LANG=" | cut -d= -f2)
|
||||
fi
|
||||
|
||||
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="请稍候..."
|
||||
ERROR_NO_ROOT="请使用 sudo 运行此脚本"
|
||||
ERROR_CONFIG_PATH="无法获取配置文件路径"
|
||||
ERROR_CREATE_DIR="无法创建配置目录"
|
||||
ERROR_WRITE_CONFIG="无法写入配置文件"
|
||||
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..."
|
||||
ERROR_NO_ROOT="Please run this script with sudo"
|
||||
ERROR_CONFIG_PATH="Unable to get config file path"
|
||||
ERROR_CREATE_DIR="Unable to create config directory"
|
||||
ERROR_WRITE_CONFIG="Unable to write config file"
|
||||
fi
|
||||
|
||||
# 生成随机ID - 添加错误处理
|
||||
generate_machine_id() {
|
||||
if ! command -v openssl >/dev/null 2>&1; then
|
||||
echo "$(head -c 32 /dev/urandom | xxd -p)"
|
||||
else
|
||||
openssl rand -hex 32
|
||||
fi
|
||||
}
|
||||
|
||||
generate_dev_device_id() {
|
||||
local uuid=""
|
||||
if command -v uuidgen >/dev/null 2>&1; then
|
||||
uuid=$(uuidgen)
|
||||
else
|
||||
uuid=$(printf '%04x%04x-%04x-%04x-%04x-%04x%04x%04x' \
|
||||
$RANDOM $RANDOM \
|
||||
$RANDOM \
|
||||
$(($RANDOM & 0x0fff | 0x4000)) \
|
||||
$(($RANDOM & 0x3fff | 0x8000)) \
|
||||
$RANDOM $RANDOM $RANDOM)
|
||||
fi
|
||||
echo "$uuid"
|
||||
}
|
||||
|
||||
# 获取配置文件路径 - 优化路径处理
|
||||
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 ""
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# 检查Cursor进程 - 添加错误处理
|
||||
check_cursor_running() {
|
||||
if ! command -v pgrep >/dev/null 2>&1; then
|
||||
ps aux | grep -i "Cursor\|AppRun" | grep -v grep >/dev/null
|
||||
else
|
||||
pgrep -f "Cursor|AppRun" >/dev/null
|
||||
fi
|
||||
}
|
||||
|
||||
# 关闭Cursor进程 - 优化进程关闭
|
||||
kill_cursor_processes() {
|
||||
echo -e "${CYAN}$CLOSING_PROCESSES${NC}"
|
||||
if command -v pkill >/dev/null 2>&1; then
|
||||
pkill -f "Cursor|AppRun"
|
||||
else
|
||||
killall Cursor 2>/dev/null
|
||||
killall AppRun 2>/dev/null
|
||||
fi
|
||||
sleep 2
|
||||
if check_cursor_running; then
|
||||
if command -v pkill >/dev/null 2>&1; then
|
||||
pkill -9 -f "Cursor|AppRun"
|
||||
else
|
||||
killall -9 Cursor 2>/dev/null
|
||||
killall -9 AppRun 2>/dev/null
|
||||
fi
|
||||
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 ${VERSION} <<${NC}"
|
||||
echo -e "${CYAN}\t\t [ By Pancake Fruit Rolled Shark Chili ]${NC}"
|
||||
echo
|
||||
}
|
||||
|
||||
# 主函数 - 添加错误处理
|
||||
main() {
|
||||
# 检查root权限
|
||||
if [ "$EUID" -ne 0 ]; then
|
||||
echo -e "${RED}${ERROR_NO_ROOT}${NC}"
|
||||
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")
|
||||
if [ -z "$CONFIG_PATH" ]; then
|
||||
echo -e "${RED}${ERROR_CONFIG_PATH}${NC}"
|
||||
exit 1
|
||||
fi
|
||||
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)"
|
||||
}
|
||||
EOF
|
||||
)
|
||||
|
||||
# 创建目录(如果不存在)
|
||||
if ! mkdir -p "$(dirname "$CONFIG_PATH")" 2>/dev/null; then
|
||||
echo -e "${RED}${ERROR_CREATE_DIR}${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 保存配置
|
||||
if ! echo "$NEW_CONFIG" > "$CONFIG_PATH"; then
|
||||
echo -e "${RED}${ERROR_WRITE_CONFIG}${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
chown "$REAL_USER" "$CONFIG_PATH" 2>/dev/null
|
||||
chmod 644 "$CONFIG_PATH" 2>/dev/null
|
||||
|
||||
# 显示成功消息
|
||||
echo -e "\n${GREEN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
|
||||
echo -e "${GREEN}$SUCCESS_MSG${NC}"
|
||||
echo -e "${YELLOW}$RESTART_MSG${NC}"
|
||||
echo -e "${GREEN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
|
||||
|
||||
echo -e "\n配置文件位置/Config file location:"
|
||||
echo -e "${CYAN}$CONFIG_PATH${NC}\n"
|
||||
|
||||
read -p "Press Enter to exit..."
|
||||
}
|
||||
|
||||
main "$@"
|
265
install.sh
Normal file → Executable file
265
install.sh
Normal file → Executable file
@ -1,255 +1,50 @@
|
||||
#!/bin/bash
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Version / 版本号
|
||||
VERSION="v2.5.0"
|
||||
|
||||
# Configuration / 配置
|
||||
KEEP_BINARY=false
|
||||
DOWNLOAD_DIR="/tmp"
|
||||
INSTALL_DIR="/usr/local/bin"
|
||||
AUTO_SUDO=false
|
||||
|
||||
# Colors / 颜色
|
||||
RED='\033[31m'
|
||||
GREEN='\033[32m'
|
||||
YELLOW='\033[33m'
|
||||
BLUE='\033[36m'
|
||||
BOLD='\033[1m'
|
||||
NC='\033[0m'
|
||||
|
||||
# Separator / 分隔线
|
||||
SEPARATOR="${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
|
||||
|
||||
# Bilingual message functions / 双语消息函数
|
||||
# Error handling
|
||||
error() {
|
||||
echo -e "\n${SEPARATOR}"
|
||||
echo -e "${RED}${BOLD}❌ Error:${NC} $1"
|
||||
echo -e "${RED}${BOLD}❌ 错误:${NC}$2"
|
||||
echo -e "${SEPARATOR}\n"
|
||||
echo -e "\033[31m\033[1mError:\033[0m $1" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
info() {
|
||||
echo -e "\n${BLUE}${BOLD}ℹ️ [EN]:${NC} $1"
|
||||
echo -e "${BLUE}${BOLD}ℹ️ [中文]:${NC} $2\n"
|
||||
}
|
||||
# Detect platform
|
||||
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
|
||||
ARCH=$(uname -m)
|
||||
|
||||
success() {
|
||||
echo -e "\n${SEPARATOR}"
|
||||
echo -e "${GREEN}${BOLD}✅ [EN]:${NC} $1"
|
||||
echo -e "${GREEN}${BOLD}✅ [中文]:${NC} $2"
|
||||
echo -e "${SEPARATOR}\n"
|
||||
}
|
||||
# Get latest version
|
||||
VERSION=$(curl -sL "https://api.github.com/repos/realies/go-cursor-help/releases/latest" | grep '"tag_name":' | sed -E 's/.*"v([^"]+)".*/\1/')
|
||||
[ -z "$VERSION" ] && error "Could not determine latest version"
|
||||
|
||||
warning() {
|
||||
echo -e "\n${YELLOW}${BOLD}⚠️ [EN]:${NC} $1"
|
||||
echo -e "${YELLOW}${BOLD}⚠️ [中文]:${NC} $2\n"
|
||||
}
|
||||
|
||||
# System detection / 系统检测
|
||||
detect_platform() {
|
||||
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
|
||||
ARCH=$(uname -m)
|
||||
|
||||
case "$OS" in
|
||||
# Get binary name based on platform
|
||||
case "$OS" in
|
||||
linux*)
|
||||
case "$ARCH" in
|
||||
x86_64) BINARY_NAME="cursor_id_modifier_${VERSION}_linux_amd64" ;;
|
||||
*) error "Unsupported Linux architecture: $ARCH" "不支持的Linux架构:$ARCH" ;;
|
||||
x86_64) BINARY="cursor_id_modifier_${VERSION}_linux_amd64" ;;
|
||||
aarch64|arm64) BINARY="cursor_id_modifier_${VERSION}_linux_arm64" ;;
|
||||
*) error "Unsupported Linux architecture: $ARCH" ;;
|
||||
esac
|
||||
;;
|
||||
darwin*)
|
||||
case "$ARCH" in
|
||||
x86_64) BINARY_NAME="cursor_id_modifier_${VERSION}_darwin_amd64_intel" ;;
|
||||
arm64) BINARY_NAME="cursor_id_modifier_${VERSION}_darwin_arm64_m1" ;;
|
||||
*) error "Unsupported macOS architecture: $ARCH" "不支持的macOS架构:$ARCH" ;;
|
||||
x86_64) BINARY="cursor_id_modifier_${VERSION}_darwin_amd64" ;;
|
||||
arm64) BINARY="cursor_id_modifier_${VERSION}_darwin_arm64" ;;
|
||||
*) error "Unsupported macOS architecture: $ARCH" ;;
|
||||
esac
|
||||
;;
|
||||
msys*|mingw*|cygwin*)
|
||||
case "$ARCH" in
|
||||
x86_64) BINARY_NAME="cursor_id_modifier_${VERSION}_windows_amd64.exe" ;;
|
||||
*) error "Unsupported Windows architecture: $ARCH" "不支持的Windows架构:$ARCH" ;;
|
||||
esac
|
||||
;;
|
||||
*)
|
||||
error "Unsupported operating system: $OS" "不支持的操作系统:$OS"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
*) error "Unsupported operating system: $OS" ;;
|
||||
esac
|
||||
|
||||
# System checks / 系统检查
|
||||
check_requirements() {
|
||||
info "Checking system requirements..." "正在检查系统要求..."
|
||||
# Set up cleanup trap
|
||||
trap 'rm -f "./${BINARY}"' EXIT
|
||||
|
||||
# Check network connectivity / 检查网络连接
|
||||
if ! ping -c 1 github.com >/dev/null 2>&1; then
|
||||
error "No network connection to GitHub" "无法连接到 GitHub"
|
||||
fi
|
||||
# Download and run
|
||||
DOWNLOAD_URL="https://github.com/realies/go-cursor-help/releases/download/v${VERSION}/${BINARY}"
|
||||
echo "Downloading from: ${DOWNLOAD_URL}"
|
||||
|
||||
# Check curl / 检查curl
|
||||
if ! command -v curl >/dev/null 2>&1; then
|
||||
error "curl is required. Please install curl first." \
|
||||
"需要安装 curl。请先安装 curl 后再运行此脚本。"
|
||||
fi
|
||||
}
|
||||
|
||||
# Privilege check / 权限检查
|
||||
check_privileges() {
|
||||
if [ "$EUID" -ne 0 ]; then
|
||||
if [ "$AUTO_SUDO" = "true" ]; then
|
||||
if command -v sudo >/dev/null 2>&1; then
|
||||
info "Re-running with sudo..." "使用 sudo 重新运行..."
|
||||
exec sudo bash "$0" "$@"
|
||||
else
|
||||
error "This script must be run as root. Please use sudo." \
|
||||
"此脚本必须以 root 身份运行。请使用 sudo。"
|
||||
fi
|
||||
else
|
||||
error "This script must be run as root. Please use sudo." \
|
||||
"此脚本必须以 root 身份运行。请使用 sudo。"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# Binary verification / 二进制验证
|
||||
verify_binary() {
|
||||
info "Verifying binary..." "正在验证二进制文件..."
|
||||
|
||||
# Check file existence / 检查文件是否存在
|
||||
if [ ! -f "$DOWNLOAD_PATH" ]; then
|
||||
error "Binary file download failed or does not exist" \
|
||||
"二进制文件下载失败或不存在"
|
||||
fi
|
||||
|
||||
# Check executable format / 检查可执行格式
|
||||
if ! file "$DOWNLOAD_PATH" | grep -q "executable"; then
|
||||
error "Downloaded file is not an executable" \
|
||||
"下载的文件不是可执行文件"
|
||||
fi
|
||||
|
||||
# Check file size / 检查文件大小
|
||||
local size=$(wc -c < "$DOWNLOAD_PATH")
|
||||
if [ "$size" -lt 1000000 ]; then # At least 1MB / 至少1MB
|
||||
error "Downloaded file size is abnormal" \
|
||||
"下载的文件大小异常"
|
||||
fi
|
||||
|
||||
# Set executable permissions / 设置可执行权限
|
||||
info "Setting executable permissions..." "正在设置可执行权限..."
|
||||
if ! chmod +x "$DOWNLOAD_PATH"; then
|
||||
error "Failed to set executable permissions" "无法设置可执行权限"
|
||||
fi
|
||||
}
|
||||
|
||||
# Cleanup functions / 清理函数
|
||||
cleanup_old_version() {
|
||||
if [ -f "$INSTALL_DIR/cursor-id-modifier" ]; then
|
||||
info "Removing old version..." "正在删除旧版..."
|
||||
rm -f "$INSTALL_DIR/cursor-id-modifier" || \
|
||||
error "Failed to remove old version" "删除旧版本失败"
|
||||
fi
|
||||
}
|
||||
|
||||
cleanup_temp_files() {
|
||||
if [ "$KEEP_BINARY" = "false" ]; then
|
||||
rm -f "$DOWNLOAD_PATH"
|
||||
rm -f "$INSTALL_DIR/cursor-id-modifier-wrapper"
|
||||
fi
|
||||
}
|
||||
|
||||
# Parse arguments / 解析参数
|
||||
parse_args() {
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case $1 in
|
||||
--auto-sudo)
|
||||
AUTO_SUDO=true
|
||||
shift
|
||||
;;
|
||||
--keep-binary)
|
||||
KEEP_BINARY=true
|
||||
shift
|
||||
;;
|
||||
--download-dir=*)
|
||||
DOWNLOAD_DIR="${1#*=}"
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
# Print banner / 打印横幅
|
||||
print_banner() {
|
||||
echo -e "\n${BLUE}${BOLD}"
|
||||
echo " ██████╗██╗ ██╗██████╗ ███████╗ ██████╗ ██████╗"
|
||||
echo " ██╔════╝██║ ██║██╔══██╗██╔════╝█╔═══██╗██╔══██╗"
|
||||
echo " ██║ ██║ ██║██████╔╝███████╗██║ ██║██████╔╝"
|
||||
echo " ██║ ██║ ██║██╔══██╗╚════██ ██║ ██║██╔══██╗"
|
||||
echo " ╚██████╗╚██████╔╝██║ ██║███████║╚██████╔╝██║ ██║"
|
||||
echo " ╚════╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝ ╚════╝ ╚═╝ ╚═╝"
|
||||
echo -e "${NC}"
|
||||
echo -e "${YELLOW}${BOLD} >> Cursor ID Modifier ${VERSION} <<${NC}"
|
||||
echo -e "${BLUE}${BOLD} [ By Pancake Fruit Rolled Shark Chili ]${NC}\n"
|
||||
}
|
||||
|
||||
# Main installation process / 主安装流程
|
||||
main() {
|
||||
check_privileges "$@"
|
||||
|
||||
print_banner
|
||||
|
||||
info "Starting installation of cursor-id-modifier ${VERSION}..." \
|
||||
"开始安装 cursor-id-modifier ${VERSION}..."
|
||||
|
||||
detect_platform
|
||||
check_requirements
|
||||
|
||||
# Create installation directory / 创建安装目录
|
||||
mkdir -p "$INSTALL_DIR" 2>/dev/null || \
|
||||
error "Failed to create installation directory" "无法创建安装目录"
|
||||
|
||||
# Download binary / 下载二进制文件
|
||||
info "Downloading cursor-id-modifier ($OS-$ARCH)..." \
|
||||
"正在下载 cursor-id-modifier ($OS-$ARCH)..."
|
||||
|
||||
DOWNLOAD_URL="https://github.com/yuaotian/go-cursor-help/raw/refs/heads/master/bin/$BINARY_NAME"
|
||||
DOWNLOAD_PATH="$DOWNLOAD_DIR/$BINARY_NAME"
|
||||
|
||||
if ! curl -L --progress-bar "$DOWNLOAD_URL" -o "$DOWNLOAD_PATH"; then
|
||||
error "Failed to download binary" "下载二进制文件失败"
|
||||
fi
|
||||
|
||||
success "Download completed" "下载完成"
|
||||
|
||||
verify_binary
|
||||
cleanup_old_version
|
||||
|
||||
# Install binary / 安装二进制文件
|
||||
info "Installing binary..." "正在安装二进制文件..."
|
||||
if ! cp "$DOWNLOAD_PATH" "$INSTALL_DIR/cursor-id-modifier"; then
|
||||
error "Failed to install binary" "安装二进制文件失败"
|
||||
fi
|
||||
|
||||
# Create wrapper script / 创建包装脚本
|
||||
cat > "$INSTALL_DIR/cursor-id-modifier-wrapper" << 'EOF'
|
||||
#!/bin/bash
|
||||
if [ "$(uname -s)" = "Darwin" ]; then
|
||||
sudo /usr/local/bin/cursor-id-modifier "$@"
|
||||
else
|
||||
sudo /usr/local/bin/cursor-id-modifier "$@"
|
||||
# Download with error checking
|
||||
if ! curl -fL "$DOWNLOAD_URL" -o "./${BINARY}"; then
|
||||
error "Download failed. HTTP error from GitHub"
|
||||
fi
|
||||
EOF
|
||||
chmod +x "$INSTALL_DIR/cursor-id-modifier-wrapper"
|
||||
|
||||
# Cleanup / 清理
|
||||
cleanup_temp_files
|
||||
|
||||
success "Installation successful! Run 'cursor-id-modifier-wrapper' from anywhere." \
|
||||
"安装成功!现在可以在任何位置运行 'cursor-id-modifier-wrapper'。"
|
||||
}
|
||||
|
||||
# Start installation / 开始安装
|
||||
parse_args "$@"
|
||||
main "$@"
|
||||
chmod +x "./${BINARY}"
|
||||
echo "Running cursor-id-modifier..."
|
||||
sudo "./${BINARY}"
|
||||
|
16
main.go
16
main.go
@ -23,6 +23,9 @@ import (
|
||||
"github.com/fatih/color"
|
||||
)
|
||||
|
||||
// Version information
|
||||
var version = "dev" // This will be overwritten by goreleaser
|
||||
|
||||
// Types and Constants / 类型和常量
|
||||
type Language string
|
||||
|
||||
@ -31,9 +34,6 @@ const (
|
||||
CN Language = "cn"
|
||||
EN Language = "en"
|
||||
|
||||
// Version / 版本号
|
||||
Version = "2.5.0"
|
||||
|
||||
// Error types / 错误类型
|
||||
ErrPermission = "permission_error"
|
||||
ErrConfig = "config_error"
|
||||
@ -204,17 +204,15 @@ func generateDevDeviceId() string {
|
||||
}
|
||||
|
||||
// File Operations / 文件操作
|
||||
func getConfigPath(username string) (string, error) { // Modified to take username
|
||||
func getConfigPath(username string) (string, error) {
|
||||
var configDir string
|
||||
switch runtime.GOOS {
|
||||
case "windows":
|
||||
configDir = filepath.Join(os.Getenv("APPDATA"), "Cursor", "User", "globalStorage")
|
||||
case "darwin":
|
||||
homeDir := filepath.Join("/home/", username)
|
||||
configDir = filepath.Join(homeDir, "Library", "Application Support", "Cursor", "User", "globalStorage")
|
||||
configDir = filepath.Join("/Users", username, "Library", "Application Support", "Cursor", "User", "globalStorage")
|
||||
case "linux":
|
||||
homeDir := filepath.Join("/home/", username)
|
||||
configDir = filepath.Join(homeDir, ".config", "Cursor", "User", "globalStorage")
|
||||
configDir = filepath.Join("/home", username, ".config", "Cursor", "User", "globalStorage")
|
||||
default:
|
||||
return "", fmt.Errorf("unsupported operating system: %s", runtime.GOOS)
|
||||
}
|
||||
@ -884,7 +882,7 @@ func printCyberpunkBanner() {
|
||||
╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝ ╚═════╝ ╚═╝ ╚═╝
|
||||
`
|
||||
cyan.Println(banner)
|
||||
yellow.Println("\t\t>> Cursor ID Modifier v1.0 <<")
|
||||
yellow.Printf("\t\t>> Cursor ID Modifier %s <<\n", version)
|
||||
magenta.Println("\t\t [ By Pancake Fruit Rolled Shark Chili ]")
|
||||
|
||||
langText := "当前语言/Language: "
|
||||
|
@ -1,118 +0,0 @@
|
||||
@echo off
|
||||
setlocal EnableDelayedExpansion
|
||||
|
||||
:: 设置版本信息
|
||||
set VERSION=2.5.0
|
||||
|
||||
:: 设置颜色代码
|
||||
set "GREEN=[32m"
|
||||
set "RED=[31m"
|
||||
set "YELLOW=[33m"
|
||||
set "RESET=[0m"
|
||||
set "CYAN=[36m"
|
||||
|
||||
:: 设置编译优化标志
|
||||
set "LDFLAGS=-s -w"
|
||||
set "BUILDMODE=pie"
|
||||
set "GCFLAGS=-N -l"
|
||||
|
||||
:: 设置 CGO
|
||||
set CGO_ENABLED=0
|
||||
|
||||
:: 显示编译信息
|
||||
echo %YELLOW%开始构建 version %VERSION%%RESET%
|
||||
echo %YELLOW%使用优化标志: LDFLAGS=%LDFLAGS%, BUILDMODE=%BUILDMODE%%RESET%
|
||||
echo %YELLOW%CGO_ENABLED=%CGO_ENABLED%%RESET%
|
||||
|
||||
:: 清理旧的构建文件
|
||||
echo %YELLOW%清理旧的构建文件...%RESET%
|
||||
if exist "..\bin" (
|
||||
rd /s /q "..\bin"
|
||||
echo %GREEN%清理完成%RESET%
|
||||
) else (
|
||||
echo %YELLOW%bin 目录不存在,无需清理%RESET%
|
||||
)
|
||||
|
||||
:: 创建输出目录
|
||||
mkdir "..\bin" 2>nul
|
||||
|
||||
:: 定义目标平台数组
|
||||
set platforms[0].os=windows
|
||||
set platforms[0].arch=amd64
|
||||
set platforms[0].ext=.exe
|
||||
set platforms[0].suffix=
|
||||
|
||||
set platforms[1].os=darwin
|
||||
set platforms[1].arch=amd64
|
||||
set platforms[1].ext=
|
||||
set platforms[1].suffix=_intel
|
||||
|
||||
set platforms[2].os=darwin
|
||||
set platforms[2].arch=arm64
|
||||
set platforms[2].ext=
|
||||
set platforms[2].suffix=_m1
|
||||
|
||||
set platforms[3].os=linux
|
||||
set platforms[3].arch=amd64
|
||||
set platforms[3].ext=
|
||||
set platforms[3].suffix=
|
||||
|
||||
:: 设置开始时间
|
||||
set start_time=%time%
|
||||
|
||||
:: 创建 MD5 信息文件
|
||||
echo MD5 Checksums > ..\bin\md5_checksums.txt
|
||||
echo ============= >> ..\bin\md5_checksums.txt
|
||||
echo. >> ..\bin\md5_checksums.txt
|
||||
|
||||
:: 编译所有目标
|
||||
echo 开始编译所有平台...
|
||||
|
||||
for /L %%i in (0,1,3) do (
|
||||
set "os=!platforms[%%i].os!"
|
||||
set "arch=!platforms[%%i].arch!"
|
||||
set "ext=!platforms[%%i].ext!"
|
||||
set "suffix=!platforms[%%i].suffix!"
|
||||
|
||||
echo.
|
||||
echo Building for !os! !arch!...
|
||||
|
||||
set GOOS=!os!
|
||||
set GOARCH=!arch!
|
||||
|
||||
:: 构建输出文件名
|
||||
set "outfile=..\bin\cursor_id_modifier_v%VERSION%_!os!_!arch!!suffix!!ext!"
|
||||
|
||||
:: 执行构建
|
||||
go build -trimpath -buildmode=%BUILDMODE% -ldflags="%LDFLAGS%" -gcflags="%GCFLAGS%" -o "!outfile!" ..\main.go
|
||||
|
||||
if !errorlevel! equ 0 (
|
||||
echo %GREEN%Build successful: !outfile!%RESET%
|
||||
|
||||
:: 计算并显示 MD5
|
||||
certutil -hashfile "!outfile!" MD5 | findstr /v "CertUtil" | findstr /v "MD5" > md5.tmp
|
||||
set /p MD5=<md5.tmp
|
||||
del md5.tmp
|
||||
echo !MD5! cursor_id_modifier_v%VERSION%_!os!_!arch!!suffix!!ext! >> ..\bin\md5_checksums.txt
|
||||
echo %CYAN%MD5: !MD5!%RESET%
|
||||
) else (
|
||||
echo %RED%Build failed for !os! !arch!%RESET%
|
||||
)
|
||||
)
|
||||
|
||||
:: 计算总耗时
|
||||
set end_time=%time%
|
||||
set /a duration = %end_time:~0,2% * 3600 + %end_time:~3,2% * 60 + %end_time:~6,2% - (%start_time:~0,2% * 3600 + %start_time:~3,2% * 60 + %start_time:~6,2%)
|
||||
|
||||
echo.
|
||||
echo %GREEN%所有构建完成! 总耗时: %duration% 秒%RESET%
|
||||
echo %CYAN%MD5 校验值已保存到 bin/md5_checksums.txt%RESET%
|
||||
if exist "..\bin" dir /b "..\bin"
|
||||
|
||||
:: 显示 MD5 校验文件内容
|
||||
echo.
|
||||
echo %YELLOW%MD5 校验值:%RESET%
|
||||
type ..\bin\md5_checksums.txt
|
||||
|
||||
pause
|
||||
endlocal
|
@ -1,101 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 设置颜色代码
|
||||
GREEN='\033[0;32m'
|
||||
RED='\033[0;31m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# 版本信息
|
||||
VERSION="2.5.0"
|
||||
|
||||
# 错误处理函数
|
||||
handle_error() {
|
||||
echo -e "${RED}Error: $1${NC}"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# 清理函数
|
||||
cleanup() {
|
||||
echo "Cleaning old builds..."
|
||||
rm -rf ../bin
|
||||
}
|
||||
|
||||
# 创建输出目录
|
||||
create_output_dir() {
|
||||
echo "Creating bin directory..."
|
||||
mkdir -p ../bin || handle_error "Failed to create bin directory"
|
||||
}
|
||||
|
||||
# 构建函数
|
||||
build() {
|
||||
local os=$1
|
||||
local arch=$2
|
||||
local suffix=$3
|
||||
|
||||
echo -e "\nBuilding for $os ($arch)..."
|
||||
|
||||
output_name="../bin/cursor_id_modifier_v${VERSION}_${os}_${arch}${suffix}"
|
||||
|
||||
GOOS=$os GOARCH=$arch go build -o "$output_name" ../main.go
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
echo -e "${GREEN}✓ Successfully built: ${output_name}${NC}"
|
||||
else
|
||||
echo -e "${RED}✗ Failed to build for $os $arch${NC}"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# 主函数
|
||||
main() {
|
||||
# 显示构建信息
|
||||
echo "Starting build process for version ${VERSION}"
|
||||
|
||||
# 清理旧文件
|
||||
cleanup
|
||||
|
||||
# 创建输出目录
|
||||
create_output_dir
|
||||
|
||||
# 定义构建目标
|
||||
declare -A targets=(
|
||||
["windows_amd64"]=".exe"
|
||||
["darwin_amd64"]=""
|
||||
["darwin_arm64"]=""
|
||||
["linux_amd64"]=""
|
||||
)
|
||||
|
||||
# 构建计数器
|
||||
local success_count=0
|
||||
local fail_count=0
|
||||
|
||||
# 遍历所有目标进行构建
|
||||
for target in "${!targets[@]}"; do
|
||||
os=${target%_*}
|
||||
arch=${target#*_}
|
||||
suffix=${targets[$target]}
|
||||
|
||||
if build "$os" "$arch" "$suffix"; then
|
||||
((success_count++))
|
||||
else
|
||||
((fail_count++))
|
||||
fi
|
||||
done
|
||||
|
||||
# 显示构建结果
|
||||
echo -e "\nBuild Summary:"
|
||||
echo -e "${GREEN}Successful builds: $success_count${NC}"
|
||||
if [ $fail_count -gt 0 ]; then
|
||||
echo -e "${RED}Failed builds: $fail_count${NC}"
|
||||
fi
|
||||
|
||||
# 显示生成的文件列表
|
||||
echo -e "\nGenerated files:"
|
||||
ls -1 ../bin
|
||||
}
|
||||
|
||||
# 捕获错误信号
|
||||
trap 'echo -e "\n${RED}Build process interrupted${NC}"; exit 1' INT TERM
|
||||
|
||||
# 执行主函数
|
||||
main
|
@ -1,6 +0,0 @@
|
||||
#!/bin/bash
|
||||
echo "Building for Linux..."
|
||||
export GOOS=linux
|
||||
export GOARCH=amd64
|
||||
go build -o ../bin/cursor_id_modifier_linux ../main.go
|
||||
echo "Build complete: ../bin/cursor_id_modifier_linux"
|
@ -1,13 +0,0 @@
|
||||
#!/bin/bash
|
||||
echo "Building for macOS..."
|
||||
export GOOS=darwin
|
||||
export GOARCH=amd64
|
||||
go build -o ../bin/cursor_id_modifier_mac ../main.go
|
||||
echo "Build complete: ../bin/cursor_id_modifier_mac"
|
||||
|
||||
# Build for Apple Silicon
|
||||
echo "Building for macOS ARM64..."
|
||||
export GOOS=darwin
|
||||
export GOARCH=arm64
|
||||
go build -o ../bin/cursor_id_modifier_mac_arm64 ../main.go
|
||||
echo "Build complete: ../bin/cursor_id_modifier_mac_arm64"
|
@ -1,6 +0,0 @@
|
||||
@echo off
|
||||
echo Building for Windows...
|
||||
set GOOS=windows
|
||||
set GOARCH=amd64
|
||||
go build -o ../bin/cursor_id_modifier.exe ../main.go
|
||||
echo Build complete: ../bin/cursor_id_modifier.exe
|
Loading…
x
Reference in New Issue
Block a user