mirror of
https://github.com/yuaotian/go-cursor-help.git
synced 2025-08-02 22:07:36 +08:00
commit
1b6933267d
1
.gitignore
vendored
1
.gitignore
vendored
@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
# Build directories
|
# Build directories
|
||||||
releases/
|
releases/
|
||||||
|
cursor-id-modifier
|
||||||
|
|
||||||
|
|
||||||
# Go specific
|
# Go specific
|
||||||
|
331
README.md
331
README.md
@ -2,306 +2,151 @@
|
|||||||
|
|
||||||
<div align="center">
|
<div align="center">
|
||||||
|
|
||||||
[](https://github.com/yuaotian/go-cursor-help/releases/latest)
|
[](https://github.com/yuaotian/go-cursor-help/releases/latest)
|
||||||
[](https://github.com/yuaotian/go-cursor-help/blob/main/LICENSE)
|
[](https://github.com/yuaotian/go-cursor-help/blob/main/LICENSE)
|
||||||
[](https://github.com/yuaotian/go-cursor-help/stargazers)
|
[](https://github.com/yuaotian/go-cursor-help/stargazers)
|
||||||
|
|
||||||
[English](#english) | [中文](#chinese)
|
[English](#-english) | [中文](#-chinese)
|
||||||
|
|
||||||
---
|
<img src="https://ai-cursor.com/wp-content/uploads/2024/09/logo-cursor-ai-png.webp" alt="Cursor Logo" width="120"/>
|
||||||
|
|
||||||
<img src="https://ai-cursor.com/wp-content/uploads/2024/09/logo-cursor-ai-png.webp" alt="Cursor Logo" width="150"/>
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
## ⚠️ Important Notice | 重要声明
|
# 🌟 English
|
||||||
|
|
||||||
<table>
|
|
||||||
<tr>
|
|
||||||
<td>
|
|
||||||
|
|
||||||
<a name="english"></a>
|
|
||||||
|
|
||||||
## 🌟 English
|
|
||||||
|
|
||||||
### 📝 Description
|
### 📝 Description
|
||||||
|
|
||||||
A tool to resolve the following prompt issue during Cursor's free trial period:
|
Resets Cursor's free trial limitation when you see:
|
||||||
|
|
||||||
<table>
|
```
|
||||||
<tr>
|
|
||||||
<td>
|
|
||||||
<pre>
|
|
||||||
Too many free trial accounts used on this machine.
|
Too many free trial accounts used on this machine.
|
||||||
Please upgrade to pro. We have this limit in place
|
Please upgrade to pro. We have this limit in place
|
||||||
to prevent abuse. Please let us know if you believe
|
to prevent abuse. Please let us know if you believe
|
||||||
this is a mistake.
|
this is a mistake.
|
||||||
</pre>
|
```
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
|
|
||||||
### ✨ Features
|
|
||||||
|
|
||||||
- 🔄 Reset Cursor free trial limitations
|
|
||||||
- 🔍 Automatic detection and closing of running instances
|
|
||||||
- 🌐 Cross-platform support with architecture detection
|
|
||||||
- 📦 Automated installation scripts
|
|
||||||
- 🖥️ Both GUI and command-line interfaces
|
|
||||||
|
|
||||||
### 💻 System Support
|
### 💻 System Support
|
||||||
|
|
||||||
| Platform | Status |
|
**Windows** ✅ x64
|
||||||
| ----------------------------------------------------------------------------------------------- | ---------------------- |
|
**macOS** ✅ Intel & M-series
|
||||||
|  | ✅ x64 |
|
**Linux** ✅ x64 & ARM64
|
||||||
|  | ✅ Intel/Apple Silicon |
|
|
||||||
|  | ✅ x64/ARM64 |
|
|
||||||
|
|
||||||
### 📥 Installation Methods
|
### 📥 Installation
|
||||||
|
|
||||||
<details open>
|
#### Automatic Installation
|
||||||
<summary><b>1️⃣ Automated Installation (Recommended)</b></summary>
|
|
||||||
|
|
||||||
#### Linux/macOS
|
|
||||||
|
|
||||||
|
**Linux/macOS**
|
||||||
```bash
|
```bash
|
||||||
curl -fsSL https://raw.githubusercontent.com/yuaotian/go-cursor-help/refs/heads/master/install.sh | sudo 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_*
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Windows PowerShell
|
**Windows** (Run in PowerShell as Admin)
|
||||||
|
|
||||||
```powershell
|
```powershell
|
||||||
# Download and run with admin privileges
|
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.0.0_windows_amd64.exe')); Remove-Item -Path "$env:TEMP\cursor-id-modifier.exe" -ErrorAction SilentlyContinue
|
||||||
$url = "https://raw.githubusercontent.com/yuaotian/go-cursor-help/refs/heads/master/bin/cursor_id_modifier_v2.0.0_windows_amd64.exe"
|
|
||||||
$output = "$env:TEMP\cursor-id-modifier.exe"
|
|
||||||
Invoke-WebRequest -Uri $url -OutFile $output
|
|
||||||
Start-Process -FilePath $output -Verb RunAs
|
|
||||||
```
|
```
|
||||||
|
|
||||||
</details>
|
#### Manual Method
|
||||||
|
|
||||||
<details>
|
1. Close Cursor completely
|
||||||
<summary><b>2️⃣ Manual Download</b></summary>
|
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",
|
||||||
|
"lastModified": "2024-01-01T00:00:00.000Z",
|
||||||
|
"version": "1.0.1"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
5. Save the file and restart Cursor
|
||||||
|
|
||||||
Download from [Releases](https://github.com/yuaotian/go-cursor-help/releases/latest):
|
### 🔧 Technical Details
|
||||||
|
|
||||||
| Platform | Architecture | File |
|
The program modifies Cursor's `storage.json` config file:
|
||||||
| ----------------------------------------------------------------------------------------------- | ------------- | -------------------------- |
|
- Windows: `%APPDATA%\Cursor\User\globalStorage\`
|
||||||
|  | x64 | `cursor-id-modifier.exe` |
|
- macOS: `~/Library/Application Support/Cursor/User/globalStorage/`
|
||||||
|  | Intel (x64) | `cursor-id-modifier-amd64` |
|
- Linux: `~/.config/Cursor/User/globalStorage/`
|
||||||
|  | Apple Silicon | `cursor-id-modifier-arm64` |
|
|
||||||
|  | x64 | `cursor-id-modifier` |
|
|
||||||
|  | ARM64 | `cursor-id-modifier-arm64` |
|
|
||||||
|
|
||||||
</details>
|
Generates new unique identifiers for:
|
||||||
|
- `telemetry.machineId`
|
||||||
### 📚 Usage Instructions
|
- `telemetry.macMachineId`
|
||||||
|
- `telemetry.devDeviceId`
|
||||||
<details>
|
- `telemetry.sqmId`
|
||||||
<summary>Prerequisites</summary>
|
|
||||||
|
|
||||||
- 👑 Administrator/root privileges required
|
|
||||||
- 🚫 Cursor should be completely closed
|
|
||||||
- 🌐 Internet connection for installation
|
|
||||||
|
|
||||||
</details>
|
|
||||||
|
|
||||||
<details>
|
|
||||||
<summary>Running the Tool</summary>
|
|
||||||
|
|
||||||
The tool will automatically:
|
|
||||||
|
|
||||||
1. 🔑 Check for and request admin privileges
|
|
||||||
2. 🔍 Detect and close Cursor instances
|
|
||||||
3. 💾 Backup existing configuration
|
|
||||||
4. 🔄 Generate new identifiers
|
|
||||||
5. ✅ Apply changes
|
|
||||||
|
|
||||||
Restart Cursor after completion.
|
|
||||||
|
|
||||||
</details>
|
|
||||||
|
|
||||||
### 🔧 Troubleshooting
|
|
||||||
|
|
||||||
<details>
|
|
||||||
<summary>Common Issues</summary>
|
|
||||||
|
|
||||||
#### 🚫 Permission Denied
|
|
||||||
|
|
||||||
- Windows: Right-click → "Run as Administrator"
|
|
||||||
- Linux/macOS: Use \`sudo\` when running
|
|
||||||
|
|
||||||
#### ⚠️ Cursor Still Running
|
|
||||||
|
|
||||||
- Tool will attempt auto-close
|
|
||||||
- Manual close via Task Manager if needed
|
|
||||||
|
|
||||||
#### 🔒 macOS Security
|
|
||||||
|
|
||||||
If you see "unidentified developer" warning:
|
|
||||||
|
|
||||||
1. Right-click → Open
|
|
||||||
2. Click "Open" in dialog
|
|
||||||
|
|
||||||
</details>
|
|
||||||
|
|
||||||
### ⚠️ Cautions
|
|
||||||
|
|
||||||
- 🛡️ Use at your own risk
|
|
||||||
- 💾 Backup important data
|
|
||||||
- 📚 Educational purposes only
|
|
||||||
|
|
||||||
### 🤝 Contributing
|
|
||||||
|
|
||||||
We welcome contributions! Please ensure:
|
|
||||||
|
|
||||||
- ✅ Cross-platform compatibility
|
|
||||||
- 🚫 No breaking changes
|
|
||||||
- 🔍 Proper error handling
|
|
||||||
- 📝 Documentation updates
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
<a name="chinese"></a>
|
# 🌏 Chinese
|
||||||
|
|
||||||
## 🌏 中文
|
|
||||||
|
|
||||||
### 📝 问题描述
|
### 📝 问题描述
|
||||||
|
|
||||||
解决Cursor在免费订阅期间出现以下提示的问题:
|
当看到以下提示时重置Cursor试用期:
|
||||||
|
|
||||||
<table>
|
```
|
||||||
<tr>
|
|
||||||
<td>
|
|
||||||
<pre>
|
|
||||||
Too many free trial accounts used on this machine.
|
Too many free trial accounts used on this machine.
|
||||||
Please upgrade to pro. We have this limit in place
|
Please upgrade to pro. We have this limit in place
|
||||||
to prevent abuse. Please let us know if you believe
|
to prevent abuse. Please let us know if you believe
|
||||||
this is a mistake.
|
this is a mistake.
|
||||||
</pre>
|
```
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
|
|
||||||
### ✨ 功能特性
|
|
||||||
|
|
||||||
- 🔄 重置Cursor免费试用限制
|
|
||||||
- 🔍 自动检测和关闭运行中的实例
|
|
||||||
- 🌐 跨平台支持,自动检测系统架构
|
|
||||||
- 📦 自动化安装脚本
|
|
||||||
- 🖥️ 支持图形界面和命令行
|
|
||||||
|
|
||||||
### 💻 系统支持
|
### 💻 系统支持
|
||||||
|
|
||||||
| 平台 | 状态 |
|
**Windows** ✅ x64
|
||||||
| ----------------------------------------------------------------------------------------------- | ---------------------- |
|
**macOS** ✅ Intel和M系列
|
||||||
|  | ✅ x64 |
|
**Linux** ✅ x64和ARM64
|
||||||
|  | ✅ Intel/Apple Silicon |
|
|
||||||
|  | ✅ x64/ARM64 |
|
|
||||||
|
|
||||||
### 📥 安装方法
|
### 📥 安装方法
|
||||||
|
|
||||||
<details open>
|
#### 自动安装
|
||||||
<summary><b>1️⃣ 自动安装(推荐)</b></summary>
|
|
||||||
|
|
||||||
#### Linux/macOS
|
|
||||||
|
|
||||||
|
|
||||||
|
**Linux/macOS**
|
||||||
```bash
|
```bash
|
||||||
curl -fsSL https://raw.githubusercontent.com/yuaotian/go-cursor-help/refs/heads/master/install.sh | sudo 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_*
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Windows PowerShell
|
**Windows** (以管理员身份运行PowerShell)
|
||||||
|
|
||||||
```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.0.0_windows_amd64.exe')); Remove-Item -Path "$env:TEMP\cursor-id-modifier.exe" -ErrorAction SilentlyContinue
|
||||||
$url = "https://raw.githubusercontent.com/yuaotian/go-cursor-help/refs/heads/master/bin/cursor_id_modifier_v2.0.0_windows_amd64.exe"
|
|
||||||
$output = "$env:TEMP\cursor-id-modifier.exe"
|
|
||||||
Invoke-WebRequest -Uri $url -OutFile $output
|
|
||||||
Start-Process -FilePath $output -Verb RunAs
|
|
||||||
```
|
```
|
||||||
|
|
||||||
</details>
|
#### 手动方法
|
||||||
|
|
||||||
<details>
|
1. 完全关闭 Cursor
|
||||||
<summary><b>2️⃣ 手动下载</b></summary>
|
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",
|
||||||
|
"lastModified": "2024-01-01T00:00:00.000Z",
|
||||||
|
"version": "1.0.1"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
5. 保存文件并重启 Cursor
|
||||||
|
|
||||||
从[发布页面](https://github.com/yuaotian/go-cursor-help/releases/latest)下载:
|
### 🔧 技术细节
|
||||||
|
|
||||||
| 平台 | 架构 | 文件 |
|
程序修改Cursor的`storage.json`配置文件:
|
||||||
| ----------------------------------------------------------------------------------------------- | ------------- | -------------------------- |
|
- Windows: `%APPDATA%\Cursor\User\globalStorage\`
|
||||||
|  | x64 | `cursor-id-modifier.exe` |
|
- macOS: `~/Library/Application Support/Cursor/User/globalStorage/`
|
||||||
|  | Intel (x64) | `cursor-id-modifier-amd64` |
|
- Linux: `~/.config/Cursor/User/globalStorage/`
|
||||||
|  | Apple Silicon | `cursor-id-modifier-arm64` |
|
|
||||||
|  | x64 | `cursor-id-modifier` |
|
|
||||||
|  | ARM64 | `cursor-id-modifier-arm64` |
|
|
||||||
|
|
||||||
</details>
|
生成新的唯一标识符:
|
||||||
|
- `telemetry.machineId`
|
||||||
### 📚 使用说明
|
- `telemetry.macMachineId`
|
||||||
|
- `telemetry.devDeviceId`
|
||||||
<details>
|
- `telemetry.sqmId`
|
||||||
<summary>使用前提</summary>
|
|
||||||
|
|
||||||
- 👑 需要管理员/root权限
|
|
||||||
- 🚫 确保Cursor完全关闭
|
|
||||||
- 🌐 需要网络连接进行安装
|
|
||||||
|
|
||||||
</details>
|
|
||||||
|
|
||||||
<details>
|
|
||||||
<summary>运行工具</summary>
|
|
||||||
|
|
||||||
工具将自动执行:
|
|
||||||
|
|
||||||
1. 🔑 检查并请求管理员权限
|
|
||||||
2. 🔍 检测并关闭Cursor进程
|
|
||||||
3. 💾 备份现有配置
|
|
||||||
4. 🔄 生成新的标识符
|
|
||||||
5. ✅ 应用更改
|
|
||||||
|
|
||||||
完成后重启Cursor即可。
|
|
||||||
|
|
||||||
</details>
|
|
||||||
|
|
||||||
### 🔧 故障排除
|
|
||||||
|
|
||||||
<details>
|
|
||||||
<summary>常见问题</summary>
|
|
||||||
|
|
||||||
#### 🚫 权限被拒绝
|
|
||||||
|
|
||||||
- Windows:右键 → "以管理员身份运行"
|
|
||||||
- Linux/macOS:使用 \`sudo\` 运行
|
|
||||||
|
|
||||||
#### ⚠️ Cursor仍在运行
|
|
||||||
|
|
||||||
- 工具会尝试自动关闭
|
|
||||||
- 如需要请通过任务管理器手动关闭
|
|
||||||
|
|
||||||
#### 🔒 macOS安全性问题
|
|
||||||
|
|
||||||
如果看到"未识别的开发者"提示:
|
|
||||||
|
|
||||||
1. 右键点击 → 打开
|
|
||||||
2. 点击确认对话框中的"打开"
|
|
||||||
|
|
||||||
</details>
|
|
||||||
|
|
||||||
### ⚠️ 注意事项
|
|
||||||
|
|
||||||
- 🛡️ 使用本工具需自行承担风险
|
|
||||||
- 💾 使用前请备份重要数据
|
|
||||||
- 📚 仅用于学习研究目的
|
|
||||||
|
|
||||||
### 🤝 贡献
|
|
||||||
|
|
||||||
欢迎提交问题和改进建议!请确保:
|
|
||||||
|
|
||||||
- ✅ 保持跨平台兼容性
|
|
||||||
- 🚫 避免破坏性更改
|
|
||||||
- 🔍 完善的错误处理
|
|
||||||
- 📝 更新相关文档
|
|
||||||
|
|
||||||
## 📄 License
|
## 📄 License
|
||||||
|
|
||||||
|
217
install.sh
217
install.sh
@ -3,24 +3,50 @@
|
|||||||
# Version / 版本号
|
# Version / 版本号
|
||||||
VERSION="v2.0.0"
|
VERSION="v2.0.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 / 双语消息函数
|
# Bilingual message functions / 双语消息函数
|
||||||
error() {
|
error() {
|
||||||
echo "❌ Error: $1"
|
echo -e "\n${SEPARATOR}"
|
||||||
echo "❌ 错误:$2"
|
echo -e "${RED}${BOLD}❌ Error:${NC} $1"
|
||||||
|
echo -e "${RED}${BOLD}❌ 错误:${NC}$2"
|
||||||
|
echo -e "${SEPARATOR}\n"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
info() {
|
info() {
|
||||||
echo "ℹ️ $1"
|
echo -e "\n${BLUE}${BOLD}ℹ️ [EN]:${NC} $1"
|
||||||
echo "ℹ️ $2"
|
echo -e "${BLUE}${BOLD}ℹ️ [中文]:${NC} $2\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
success() {
|
success() {
|
||||||
echo "✅ $1"
|
echo -e "\n${SEPARATOR}"
|
||||||
echo "✅ $2"
|
echo -e "${GREEN}${BOLD}✅ [EN]:${NC} $1"
|
||||||
|
echo -e "${GREEN}${BOLD}✅ [中文]:${NC} $2"
|
||||||
|
echo -e "${SEPARATOR}\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Detect OS and architecture / 检测操作系统和架构
|
warning() {
|
||||||
|
echo -e "\n${YELLOW}${BOLD}⚠️ [EN]:${NC} $1"
|
||||||
|
echo -e "${YELLOW}${BOLD}⚠️ [中文]:${NC} $2\n"
|
||||||
|
}
|
||||||
|
|
||||||
|
# System detection / 系统检测
|
||||||
detect_platform() {
|
detect_platform() {
|
||||||
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
|
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
|
||||||
ARCH=$(uname -m)
|
ARCH=$(uname -m)
|
||||||
@ -51,38 +77,51 @@ detect_platform() {
|
|||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check system requirements / 检查系统要求
|
# System checks / 系统检查
|
||||||
check_requirements() {
|
check_requirements() {
|
||||||
info "Checking system requirements..." "正在检查系统要求..."
|
info "Checking system requirements..." "正在检查系统要求..."
|
||||||
|
|
||||||
# 添加网络连接检查
|
# Check network connectivity / 检查网络连接
|
||||||
if ! ping -c 1 github.com >/dev/null 2>&1; then
|
if ! ping -c 1 github.com >/dev/null 2>&1; then
|
||||||
error "No network connection to GitHub" \
|
error "No network connection to GitHub" "无法连接到 GitHub"
|
||||||
"无法连接到 GitHub"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check curl
|
# Check curl / 检查curl
|
||||||
if ! command -v curl >/dev/null 2>&1; then
|
if ! command -v curl >/dev/null 2>&1; then
|
||||||
error "curl is required. Please install curl first." \
|
error "curl is required. Please install curl first." \
|
||||||
"需要安装 curl。请先安装 curl 后再运行此脚本。"
|
"需要安装 curl。请先安装 curl 后再运行此脚本。"
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# Check write permissions / 检查写入权限
|
# Privilege check / 权限检查
|
||||||
if [ ! -w "$INSTALL_DIR" ]; then
|
check_privileges() {
|
||||||
error "No write permission for $INSTALL_DIR. Please run with sudo." \
|
if [ "$EUID" -ne 0 ]; then
|
||||||
"没有 $INSTALL_DIR 的写入权限。请使用 sudo 运行此脚本。"
|
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
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Verify binary / 验证二进制文件
|
# Binary verification / 二进制验证
|
||||||
verify_binary() {
|
verify_binary() {
|
||||||
info "Verifying binary..." "正在验证二进制文件..."
|
info "Verifying binary..." "正在验证二进制文件..."
|
||||||
|
|
||||||
|
# Check file existence / 检查文件是否存在
|
||||||
if [ ! -f "$DOWNLOAD_PATH" ]; then
|
if [ ! -f "$DOWNLOAD_PATH" ]; then
|
||||||
error "Binary file download failed or does not exist" \
|
error "Binary file download failed or does not exist" \
|
||||||
"二进制文件下载失败或不存在"
|
"二进制文件下载失败或不存在"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 添加可执行文件格式检查
|
# Check executable format / 检查可执行格式
|
||||||
if ! file "$DOWNLOAD_PATH" | grep -q "executable"; then
|
if ! file "$DOWNLOAD_PATH" | grep -q "executable"; then
|
||||||
error "Downloaded file is not an executable" \
|
error "Downloaded file is not an executable" \
|
||||||
"下载的文件不是可执行文件"
|
"下载的文件不是可执行文件"
|
||||||
@ -91,8 +130,8 @@ verify_binary() {
|
|||||||
# Check file size / 检查文件大小
|
# Check file size / 检查文件大小
|
||||||
local size=$(wc -c < "$DOWNLOAD_PATH")
|
local size=$(wc -c < "$DOWNLOAD_PATH")
|
||||||
if [ "$size" -lt 1000000 ]; then # At least 1MB / 至少1MB
|
if [ "$size" -lt 1000000 ]; then # At least 1MB / 至少1MB
|
||||||
error "Downloaded file size is abnormal, download might be incomplete" \
|
error "Downloaded file size is abnormal" \
|
||||||
"下载的文件大小异常,可能下载不完整"
|
"下载的文件大小异常"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Set executable permissions / 设置可执行权限
|
# Set executable permissions / 设置可执行权限
|
||||||
@ -102,14 +141,30 @@ verify_binary() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# 在文件开头添加配置项
|
# Cleanup functions / 清理函数
|
||||||
KEEP_BINARY=true # 修改默认值为 true
|
cleanup_old_version() {
|
||||||
DOWNLOAD_DIR="." # 默认下载到当前目录
|
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
|
||||||
|
}
|
||||||
|
|
||||||
# 在 main 函数之前添加参数解析
|
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() {
|
parse_args() {
|
||||||
while [[ $# -gt 0 ]]; do
|
while [[ $# -gt 0 ]]; do
|
||||||
case $1 in
|
case $1 in
|
||||||
|
--auto-sudo)
|
||||||
|
AUTO_SUDO=true
|
||||||
|
shift
|
||||||
|
;;
|
||||||
--keep-binary)
|
--keep-binary)
|
||||||
KEEP_BINARY=true
|
KEEP_BINARY=true
|
||||||
shift
|
shift
|
||||||
@ -125,104 +180,76 @@ parse_args() {
|
|||||||
done
|
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 installation process / 主安装流程
|
||||||
main() {
|
main() {
|
||||||
|
check_privileges "$@"
|
||||||
|
|
||||||
|
print_banner
|
||||||
|
|
||||||
info "Starting installation of cursor-id-modifier ${VERSION}..." \
|
info "Starting installation of cursor-id-modifier ${VERSION}..." \
|
||||||
"开始安装 cursor-id-modifier ${VERSION}..."
|
"开始安装 cursor-id-modifier ${VERSION}..."
|
||||||
|
|
||||||
# Initialize installation / 初始化安装
|
|
||||||
detect_platform
|
detect_platform
|
||||||
INSTALL_DIR="/usr/local/bin"
|
|
||||||
if [ ! -d "$INSTALL_DIR" ]; then
|
|
||||||
if ! mkdir -p "$INSTALL_DIR" 2>/dev/null; then
|
|
||||||
error "Failed to create installation directory" \
|
|
||||||
"无法创建安装目录"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Check requirements / 检查要求
|
|
||||||
check_requirements
|
check_requirements
|
||||||
|
|
||||||
# Create temp directory / 创建临时目录
|
# Create installation directory / 创建安装目录
|
||||||
info "Creating temporary directory..." \
|
mkdir -p "$INSTALL_DIR" 2>/dev/null || \
|
||||||
"正在创建临时目录..."
|
error "Failed to create installation directory" "无法创建安装目录"
|
||||||
TEMP_DIR=$(mktemp -d)
|
|
||||||
info "Note: Temporary directory will be automatically cleaned up after installation" \
|
|
||||||
"注意:临时目录将在安装完成后自动清理"
|
|
||||||
trap 'rm -rf "$TEMP_DIR"' EXIT
|
|
||||||
|
|
||||||
# 检查下载目录权限
|
# Download binary / 下载二进制文件
|
||||||
if [ ! -w "$DOWNLOAD_DIR" ]; then
|
|
||||||
error "No write permission for download directory: $DOWNLOAD_DIR" \
|
|
||||||
"下载目录无写入权限:$DOWNLOAD_DIR"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# 下载二进制文件
|
|
||||||
info "Downloading cursor-id-modifier ($OS-$ARCH)..." \
|
info "Downloading cursor-id-modifier ($OS-$ARCH)..." \
|
||||||
"正在下载 cursor-id-modifier ($OS-$ARCH)..."
|
"正在下载 cursor-id-modifier ($OS-$ARCH)..."
|
||||||
|
|
||||||
# 定义下载 URL
|
|
||||||
DOWNLOAD_URL="https://github.com/yuaotian/go-cursor-help/raw/refs/heads/master/bin/$BINARY_NAME"
|
DOWNLOAD_URL="https://github.com/yuaotian/go-cursor-help/raw/refs/heads/master/bin/$BINARY_NAME"
|
||||||
DOWNLOAD_PATH="$DOWNLOAD_DIR/$BINARY_NAME"
|
DOWNLOAD_PATH="$DOWNLOAD_DIR/$BINARY_NAME"
|
||||||
info "File will be downloaded to: $DOWNLOAD_PATH" \
|
|
||||||
"文件将下载到:$DOWNLOAD_PATH"
|
|
||||||
|
|
||||||
if ! curl -L --progress-bar "$DOWNLOAD_URL" -o "$DOWNLOAD_PATH"; then
|
if ! curl -L --progress-bar "$DOWNLOAD_URL" -o "$DOWNLOAD_PATH"; then
|
||||||
error "Failed to download binary from: $DOWNLOAD_URL" \
|
error "Failed to download binary" "下载二进制文件失败"
|
||||||
"从以下地址下载二进制文件失败:$DOWNLOAD_URL"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
success "Download completed to: $DOWNLOAD_PATH" \
|
success "Download completed" "下载完成"
|
||||||
"下载完成,文件位置:$DOWNLOAD_PATH"
|
|
||||||
|
|
||||||
# 添加手动设置权限的提示
|
|
||||||
info "To make the file executable, run:" \
|
|
||||||
"要使文件可执行,请运行:"
|
|
||||||
info "chmod +x $DOWNLOAD_PATH" \
|
|
||||||
"chmod +x $DOWNLOAD_PATH"
|
|
||||||
info "Then you can run it with:" \
|
|
||||||
"然后可以通过以下命令运行:"
|
|
||||||
info "./$BINARY_NAME" \
|
|
||||||
"./$BINARY_NAME"
|
|
||||||
|
|
||||||
# 验证和安装
|
|
||||||
verify_binary
|
verify_binary
|
||||||
|
cleanup_old_version
|
||||||
|
|
||||||
# 安装到系统目录
|
# Install binary / 安装二进制文件
|
||||||
info "Installing binary..." "正在安装二进制文件..."
|
info "Installing binary..." "正在安装二进制文件..."
|
||||||
if ! cp "$DOWNLOAD_PATH" "$INSTALL_DIR/cursor-id-modifier"; then
|
if ! cp "$DOWNLOAD_PATH" "$INSTALL_DIR/cursor-id-modifier"; then
|
||||||
error "Failed to install binary" "安装二进制文件失败"
|
error "Failed to install binary" "安装二进制文件失败"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 根据设置决定是否保留下载的文件
|
# Create wrapper script / 创建包装脚本
|
||||||
if [ "$KEEP_BINARY" = false ]; then
|
cat > "$INSTALL_DIR/cursor-id-modifier-wrapper" << 'EOF'
|
||||||
info "Binary file will be cleaned up after installation" \
|
#!/bin/bash
|
||||||
"二进制文件将在安装后被清理"
|
if [ "$(uname -s)" = "Darwin" ]; then
|
||||||
info "Use --keep-binary flag to keep the downloaded file" \
|
sudo /usr/local/bin/cursor-id-modifier "$@"
|
||||||
"使用 --keep-binary 参数可以保留下载的文件"
|
else
|
||||||
info "Cleaning up downloaded file..." "正在清理下载的文件..."
|
sudo /usr/local/bin/cursor-id-modifier "$@"
|
||||||
rm -f "$DOWNLOAD_PATH"
|
fi
|
||||||
else
|
EOF
|
||||||
info "Binary file is kept at: $DOWNLOAD_PATH" \
|
chmod +x "$INSTALL_DIR/cursor-id-modifier-wrapper"
|
||||||
"二进制文件保留在:$DOWNLOAD_PATH"
|
|
||||||
fi
|
|
||||||
|
|
||||||
success "Installation successful! You can now run 'cursor-id-modifier' from anywhere." \
|
# Cleanup / 清理
|
||||||
"安装成功!现在可以在任何位置运行 'cursor-id-modifier'。"
|
cleanup_temp_files
|
||||||
success "For help, run 'cursor-id-modifier --help'" \
|
|
||||||
"如需帮助,请运行 'cursor-id-modifier --help'"
|
success "Installation successful! Run 'cursor-id-modifier-wrapper' from anywhere." \
|
||||||
|
"安装成功!现在可以在任何位置运行 'cursor-id-modifier-wrapper'。"
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
# 在主程序开始前解析参数
|
|
||||||
parse_args "$@"
|
|
||||||
|
|
||||||
# Start installation / 开始安装
|
# Start installation / 开始安装
|
||||||
main
|
parse_args "$@"
|
||||||
|
main "$@"
|
Loading…
x
Reference in New Issue
Block a user