mirror of
https://github.com/yuaotian/go-cursor-help.git
synced 2025-06-08 04:22:06 +08:00
refactor: Remove install.sh and enhance README.md with updated installation instructions
- Deleted the `install.sh` script to streamline the installation process and reduce complexity. - Updated the `README.md` to reflect the new installation method, emphasizing the recommended automatic installation approach. - Improved clarity in installation instructions for both Linux/macOS and Windows, ensuring users have clear guidance on how to install the tool. - Added details about the automatic installation script's features, including privilege requests and configuration backups. - Enhanced the manual installation section with step-by-step instructions for users who prefer that method. These changes collectively improve the documentation and user experience during the installation process.
This commit is contained in:
parent
20b2eb74b7
commit
2b2fb6d515
82
README.md
82
README.md
@ -33,19 +33,39 @@ this is a mistake.
|
|||||||
|
|
||||||
### 📥 Installation
|
### 📥 Installation
|
||||||
|
|
||||||
#### Automatic Installation
|
#### Automatic Installation (Recommended)
|
||||||
|
|
||||||
**Linux/macOS**
|
**Linux/macOS**
|
||||||
```bash
|
```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/scripts/install.sh | sudo bash
|
||||||
```
|
```
|
||||||
|
|
||||||
**Windows** (Run in PowerShell as Admin)
|
**Windows** (Run PowerShell as Admin)
|
||||||
```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
|
irm https://raw.githubusercontent.com/yuaotian/go-cursor-help/master/scripts/install.ps1 | iex
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Manual Method
|
The installation script will automatically:
|
||||||
|
- Request necessary privileges (sudo/admin)
|
||||||
|
- Close any running Cursor instances
|
||||||
|
- Backup existing configuration
|
||||||
|
- Install the tool
|
||||||
|
- Add it to system PATH
|
||||||
|
- Clean up temporary files
|
||||||
|
|
||||||
|
#### Manual Installation
|
||||||
|
|
||||||
|
1. Download the latest release for your system from the [releases page](https://github.com/yuaotian/go-cursor-help/releases)
|
||||||
|
2. Extract and run with administrator/root privileges:
|
||||||
|
```bash
|
||||||
|
# Linux/macOS
|
||||||
|
sudo ./cursor-id-modifier
|
||||||
|
|
||||||
|
# Windows (PowerShell Admin)
|
||||||
|
.\cursor-id-modifier.exe
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Manual Configuration Method
|
||||||
|
|
||||||
1. Close Cursor completely
|
1. Close Cursor completely
|
||||||
2. Navigate to the configuration file location:
|
2. Navigate to the configuration file location:
|
||||||
@ -68,17 +88,25 @@ Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManage
|
|||||||
|
|
||||||
### 🔧 Technical Details
|
### 🔧 Technical Details
|
||||||
|
|
||||||
The program modifies Cursor's `storage.json` config file:
|
#### Configuration Files
|
||||||
|
The program modifies Cursor's `storage.json` config file located at:
|
||||||
- Windows: `%APPDATA%\Cursor\User\globalStorage\`
|
- Windows: `%APPDATA%\Cursor\User\globalStorage\`
|
||||||
- macOS: `~/Library/Application Support/Cursor/User/globalStorage/`
|
- macOS: `~/Library/Application Support/Cursor/User/globalStorage/`
|
||||||
- Linux: `~/.config/Cursor/User/globalStorage/`
|
- Linux: `~/.config/Cursor/User/globalStorage/`
|
||||||
|
|
||||||
Generates new unique identifiers for:
|
#### Modified Fields
|
||||||
|
The tool generates new unique identifiers for:
|
||||||
- `telemetry.machineId`
|
- `telemetry.machineId`
|
||||||
- `telemetry.macMachineId`
|
- `telemetry.macMachineId`
|
||||||
- `telemetry.devDeviceId`
|
- `telemetry.devDeviceId`
|
||||||
- `telemetry.sqmId`
|
- `telemetry.sqmId`
|
||||||
|
|
||||||
|
#### Safety Features
|
||||||
|
- Automatic backup of existing configuration
|
||||||
|
- Safe process termination
|
||||||
|
- Atomic file operations
|
||||||
|
- Error handling and rollback
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
# 🌏 Chinese
|
# 🌏 Chinese
|
||||||
@ -102,19 +130,39 @@ this is a mistake.
|
|||||||
|
|
||||||
### 📥 安装方法
|
### 📥 安装方法
|
||||||
|
|
||||||
#### 自动安装
|
#### 自动安装(推荐)
|
||||||
|
|
||||||
**Linux/macOS**
|
**Linux/macOS**
|
||||||
```bash
|
```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/scripts/install.sh | sudo bash
|
||||||
```
|
```
|
||||||
|
|
||||||
**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
|
irm https://raw.githubusercontent.com/yuaotian/go-cursor-help/master/scripts/install.ps1 | iex
|
||||||
```
|
```
|
||||||
|
|
||||||
#### 手动方法
|
安装脚本会自动:
|
||||||
|
- 请求必要的权限(sudo/管理员)
|
||||||
|
- 关闭所有运行中的Cursor实例
|
||||||
|
- 备份现有配置
|
||||||
|
- 安装工具
|
||||||
|
- 添加到系统PATH
|
||||||
|
- 清理临时文件
|
||||||
|
|
||||||
|
#### 手动安装
|
||||||
|
|
||||||
|
1. 从[发布页面](https://github.com/yuaotian/go-cursor-help/releases)下载适合您系统的最新版本
|
||||||
|
2. 解压并以管理员/root权限运行:
|
||||||
|
```bash
|
||||||
|
# Linux/macOS
|
||||||
|
sudo ./cursor-id-modifier
|
||||||
|
|
||||||
|
# Windows (PowerShell 管理员)
|
||||||
|
.\cursor-id-modifier.exe
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 手动配置方法
|
||||||
|
|
||||||
1. 完全关闭 Cursor
|
1. 完全关闭 Cursor
|
||||||
2. 找到配置文件位置:
|
2. 找到配置文件位置:
|
||||||
@ -137,17 +185,25 @@ Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManage
|
|||||||
|
|
||||||
### 🔧 技术细节
|
### 🔧 技术细节
|
||||||
|
|
||||||
程序修改Cursor的`storage.json`配置文件:
|
#### 配置文件
|
||||||
|
程序修改Cursor的`storage.json`配置文件,位于:
|
||||||
- Windows: `%APPDATA%\Cursor\User\globalStorage\`
|
- Windows: `%APPDATA%\Cursor\User\globalStorage\`
|
||||||
- macOS: `~/Library/Application Support/Cursor/User/globalStorage/`
|
- macOS: `~/Library/Application Support/Cursor/User/globalStorage/`
|
||||||
- Linux: `~/.config/Cursor/User/globalStorage/`
|
- Linux: `~/.config/Cursor/User/globalStorage/`
|
||||||
|
|
||||||
生成新的唯一标识符:
|
#### 修改字段
|
||||||
|
工具会生成新的唯一标识符:
|
||||||
- `telemetry.machineId`
|
- `telemetry.machineId`
|
||||||
- `telemetry.macMachineId`
|
- `telemetry.macMachineId`
|
||||||
- `telemetry.devDeviceId`
|
- `telemetry.devDeviceId`
|
||||||
- `telemetry.sqmId`
|
- `telemetry.sqmId`
|
||||||
|
|
||||||
|
#### 安全特性
|
||||||
|
- 自动备份现有配置
|
||||||
|
- 安全的进程终止
|
||||||
|
- 原子文件操作
|
||||||
|
- 错误处理和回滚
|
||||||
|
|
||||||
## 📄 License
|
## 📄 License
|
||||||
|
|
||||||
MIT License
|
MIT License
|
||||||
|
255
install.sh
255
install.sh
@ -1,255 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# Version / 版本号
|
|
||||||
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 / 双语消息函数
|
|
||||||
error() {
|
|
||||||
echo -e "\n${SEPARATOR}"
|
|
||||||
echo -e "${RED}${BOLD}❌ Error:${NC} $1"
|
|
||||||
echo -e "${RED}${BOLD}❌ 错误:${NC}$2"
|
|
||||||
echo -e "${SEPARATOR}\n"
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
|
|
||||||
info() {
|
|
||||||
echo -e "\n${BLUE}${BOLD}ℹ️ [EN]:${NC} $1"
|
|
||||||
echo -e "${BLUE}${BOLD}ℹ️ [中文]:${NC} $2\n"
|
|
||||||
}
|
|
||||||
|
|
||||||
success() {
|
|
||||||
echo -e "\n${SEPARATOR}"
|
|
||||||
echo -e "${GREEN}${BOLD}✅ [EN]:${NC} $1"
|
|
||||||
echo -e "${GREEN}${BOLD}✅ [中文]:${NC} $2"
|
|
||||||
echo -e "${SEPARATOR}\n"
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
|
||||||
linux*)
|
|
||||||
case "$ARCH" in
|
|
||||||
x86_64) BINARY_NAME="cursor_id_modifier_${VERSION}_linux_amd64" ;;
|
|
||||||
*) error "Unsupported Linux architecture: $ARCH" "不支持的Linux架构:$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" ;;
|
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
# System checks / 系统检查
|
|
||||||
check_requirements() {
|
|
||||||
info "Checking system requirements..." "正在检查系统要求..."
|
|
||||||
|
|
||||||
# Check network connectivity / 检查网络连接
|
|
||||||
if ! ping -c 1 github.com >/dev/null 2>&1; then
|
|
||||||
error "No network connection to GitHub" "无法连接到 GitHub"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# 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 "$@"
|
|
||||||
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 "$@"
|
|
@ -1,41 +1,70 @@
|
|||||||
@echo off
|
@echo off
|
||||||
setlocal EnableDelayedExpansion
|
setlocal EnableDelayedExpansion
|
||||||
|
|
||||||
:: 设置版本信息
|
:: Messages / 消息
|
||||||
|
set "EN_MESSAGES[0]=Starting build process for version"
|
||||||
|
set "EN_MESSAGES[1]=Using optimization flags:"
|
||||||
|
set "EN_MESSAGES[2]=Cleaning old builds..."
|
||||||
|
set "EN_MESSAGES[3]=Cleanup completed"
|
||||||
|
set "EN_MESSAGES[4]=bin directory does not exist, no cleanup needed"
|
||||||
|
set "EN_MESSAGES[5]=Starting builds for all platforms..."
|
||||||
|
set "EN_MESSAGES[6]=Building for"
|
||||||
|
set "EN_MESSAGES[7]=Build successful:"
|
||||||
|
set "EN_MESSAGES[8]=Build failed for"
|
||||||
|
set "EN_MESSAGES[9]=All builds completed! Total time:"
|
||||||
|
set "EN_MESSAGES[10]=seconds"
|
||||||
|
|
||||||
|
set "CN_MESSAGES[0]=开始构建版本"
|
||||||
|
set "CN_MESSAGES[1]=使用优化标志:"
|
||||||
|
set "CN_MESSAGES[2]=正在清理旧的构建文件..."
|
||||||
|
set "CN_MESSAGES[3]=清理完成"
|
||||||
|
set "CN_MESSAGES[4]=bin 目录不存在,无需清理"
|
||||||
|
set "CN_MESSAGES[5]=开始编译所有平台..."
|
||||||
|
set "CN_MESSAGES[6]=正在构建"
|
||||||
|
set "CN_MESSAGES[7]=构建成功:"
|
||||||
|
set "CN_MESSAGES[8]=构建失败:"
|
||||||
|
set "CN_MESSAGES[9]=所有构建完成!总耗时:"
|
||||||
|
set "CN_MESSAGES[10]=秒"
|
||||||
|
|
||||||
|
:: 设置版本信息 / Set version
|
||||||
set VERSION=2.0.0
|
set VERSION=2.0.0
|
||||||
|
|
||||||
:: 设置颜色代码
|
:: 设置颜色代码 / Set color codes
|
||||||
set "GREEN=[32m"
|
set "GREEN=[32m"
|
||||||
set "RED=[31m"
|
set "RED=[31m"
|
||||||
set "YELLOW=[33m"
|
set "YELLOW=[33m"
|
||||||
set "RESET=[0m"
|
set "RESET=[0m"
|
||||||
|
|
||||||
:: 设置编译优化标志
|
:: 设置编译优化标志 / Set build optimization flags
|
||||||
set "LDFLAGS=-s -w"
|
set "LDFLAGS=-s -w"
|
||||||
set "BUILDMODE=pie"
|
set "BUILDMODE=pie"
|
||||||
set "GCFLAGS=-N -l"
|
set "GCFLAGS=-N -l"
|
||||||
|
|
||||||
:: 设置 CGO
|
:: 设置 CGO / Set CGO
|
||||||
set CGO_ENABLED=0
|
set CGO_ENABLED=0
|
||||||
|
|
||||||
:: 显示编译信息
|
:: 检测系统语言 / Detect system language
|
||||||
echo %YELLOW%开始构建 version %VERSION%%RESET%
|
for /f "tokens=2 delims==" %%a in ('wmic os get OSLanguage /value') do set OSLanguage=%%a
|
||||||
echo %YELLOW%使用优化标志: LDFLAGS=%LDFLAGS%, BUILDMODE=%BUILDMODE%%RESET%
|
if "%OSLanguage%"=="2052" (set LANG=cn) else (set LANG=en)
|
||||||
|
|
||||||
|
:: 显示编译信息 / Display build info
|
||||||
|
echo %YELLOW%!%LANG%_MESSAGES[0]! %VERSION%%RESET%
|
||||||
|
echo %YELLOW%!%LANG%_MESSAGES[1]! LDFLAGS=%LDFLAGS%, BUILDMODE=%BUILDMODE%%RESET%
|
||||||
echo %YELLOW%CGO_ENABLED=%CGO_ENABLED%%RESET%
|
echo %YELLOW%CGO_ENABLED=%CGO_ENABLED%%RESET%
|
||||||
|
|
||||||
:: 清理旧的构建文件
|
:: 清理旧的构建文件 / Clean old builds
|
||||||
echo %YELLOW%清理旧的构建文件...%RESET%
|
echo %YELLOW%!%LANG%_MESSAGES[2]!%RESET%
|
||||||
if exist "..\bin" (
|
if exist "..\bin" (
|
||||||
rd /s /q "..\bin"
|
rd /s /q "..\bin"
|
||||||
echo %GREEN%清理完成%RESET%
|
echo %GREEN%!%LANG%_MESSAGES[3]!%RESET%
|
||||||
) else (
|
) else (
|
||||||
echo %YELLOW%bin 目录不存在,无需清理%RESET%
|
echo %YELLOW%!%LANG%_MESSAGES[4]!%RESET%
|
||||||
)
|
)
|
||||||
|
|
||||||
:: 创建输出目录
|
:: 创建输出目录 / Create output directory
|
||||||
mkdir "..\bin" 2>nul
|
mkdir "..\bin" 2>nul
|
||||||
|
|
||||||
:: 定义目标平台数组
|
:: 定义目标平台数组 / Define target platforms array
|
||||||
set platforms[0].os=windows
|
set platforms[0].os=windows
|
||||||
set platforms[0].arch=amd64
|
set platforms[0].arch=amd64
|
||||||
set platforms[0].ext=.exe
|
set platforms[0].ext=.exe
|
||||||
@ -56,11 +85,11 @@ set platforms[3].arch=amd64
|
|||||||
set platforms[3].ext=
|
set platforms[3].ext=
|
||||||
set platforms[3].suffix=
|
set platforms[3].suffix=
|
||||||
|
|
||||||
:: 设置开始时间
|
:: 设置开始时间 / Set start time
|
||||||
set start_time=%time%
|
set start_time=%time%
|
||||||
|
|
||||||
:: 编译所有目标
|
:: 编译所有目标 / Build all targets
|
||||||
echo 开始编译所有平台...
|
echo !%LANG%_MESSAGES[5]!
|
||||||
|
|
||||||
for /L %%i in (0,1,3) do (
|
for /L %%i in (0,1,3) do (
|
||||||
set "os=!platforms[%%i].os!"
|
set "os=!platforms[%%i].os!"
|
||||||
@ -69,30 +98,30 @@ for /L %%i in (0,1,3) do (
|
|||||||
set "suffix=!platforms[%%i].suffix!"
|
set "suffix=!platforms[%%i].suffix!"
|
||||||
|
|
||||||
echo.
|
echo.
|
||||||
echo Building for !os! !arch!...
|
echo !%LANG%_MESSAGES[6]! !os! !arch!...
|
||||||
|
|
||||||
set GOOS=!os!
|
set GOOS=!os!
|
||||||
set GOARCH=!arch!
|
set GOARCH=!arch!
|
||||||
|
|
||||||
:: 构建输出文件名
|
:: 构建输出文件名 / Build output filename
|
||||||
set "outfile=..\bin\cursor_id_modifier_v%VERSION%_!os!_!arch!!suffix!!ext!"
|
set "outfile=..\bin\cursor_id_modifier_v%VERSION%_!os!_!arch!!suffix!!ext!"
|
||||||
|
|
||||||
:: 执行构建
|
:: 执行构建 / Execute build
|
||||||
go build -trimpath -buildmode=%BUILDMODE% -ldflags="%LDFLAGS%" -gcflags="%GCFLAGS%" -o "!outfile!" ..\main.go
|
go build -trimpath -buildmode=%BUILDMODE% -ldflags="%LDFLAGS%" -gcflags="%GCFLAGS%" -o "!outfile!" ..\main.go
|
||||||
|
|
||||||
if !errorlevel! equ 0 (
|
if !errorlevel! equ 0 (
|
||||||
echo %GREEN%Build successful: !outfile!%RESET%
|
echo %GREEN%!%LANG%_MESSAGES[7]! !outfile!%RESET%
|
||||||
) else (
|
) else (
|
||||||
echo %RED%Build failed for !os! !arch!%RESET%
|
echo %RED%!%LANG%_MESSAGES[8]! !os! !arch!%RESET%
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
:: 计算总耗时
|
:: 计算总耗时 / Calculate total time
|
||||||
set end_time=%time%
|
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%)
|
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.
|
||||||
echo %GREEN%所有构建完成! 总耗时: %duration% 秒%RESET%
|
echo %GREEN%!%LANG%_MESSAGES[9]! %duration% !%LANG%_MESSAGES[10]!%RESET%
|
||||||
if exist "..\bin" dir /b "..\bin"
|
if exist "..\bin" dir /b "..\bin"
|
||||||
|
|
||||||
pause
|
pause
|
||||||
|
@ -1,63 +1,117 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# 设置颜色代码
|
# 设置颜色代码 / Set color codes
|
||||||
GREEN='\033[0;32m'
|
GREEN='\033[0;32m'
|
||||||
RED='\033[0;31m'
|
RED='\033[0;31m'
|
||||||
NC='\033[0m' # No Color
|
NC='\033[0m' # No Color / 无颜色
|
||||||
|
|
||||||
# 版本信息
|
# Messages / 消息
|
||||||
|
EN_MESSAGES=(
|
||||||
|
"Starting build process for version"
|
||||||
|
"Cleaning old builds..."
|
||||||
|
"Creating bin directory..."
|
||||||
|
"Failed to create bin directory"
|
||||||
|
"Building for"
|
||||||
|
"Successfully built:"
|
||||||
|
"Failed to build for"
|
||||||
|
"Build Summary:"
|
||||||
|
"Successful builds:"
|
||||||
|
"Failed builds:"
|
||||||
|
"Generated files:"
|
||||||
|
"Build process interrupted"
|
||||||
|
"Error:"
|
||||||
|
)
|
||||||
|
|
||||||
|
CN_MESSAGES=(
|
||||||
|
"开始构建版本"
|
||||||
|
"正在清理旧的构建文件..."
|
||||||
|
"正在创建bin目录..."
|
||||||
|
"创建bin目录失败"
|
||||||
|
"正在构建"
|
||||||
|
"构建成功:"
|
||||||
|
"构建失败:"
|
||||||
|
"构建摘要:"
|
||||||
|
"成功构建数:"
|
||||||
|
"失败构建数:"
|
||||||
|
"生成的文件:"
|
||||||
|
"构建过程被中断"
|
||||||
|
"错误:"
|
||||||
|
)
|
||||||
|
|
||||||
|
# 版本信息 / Version info
|
||||||
VERSION="1.0.0"
|
VERSION="1.0.0"
|
||||||
|
|
||||||
# 错误处理函数
|
# Detect system language / 检测系统语言
|
||||||
|
detect_language() {
|
||||||
|
if [[ $(locale | grep "LANG=zh_CN") ]]; then
|
||||||
|
echo "cn"
|
||||||
|
else
|
||||||
|
echo "en"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Get message based on language / 根据语言获取消息
|
||||||
|
get_message() {
|
||||||
|
local index=$1
|
||||||
|
local lang=$(detect_language)
|
||||||
|
|
||||||
|
if [[ "$lang" == "cn" ]]; then
|
||||||
|
echo "${CN_MESSAGES[$index]}"
|
||||||
|
else
|
||||||
|
echo "${EN_MESSAGES[$index]}"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# 错误处理函数 / Error handling function
|
||||||
handle_error() {
|
handle_error() {
|
||||||
echo -e "${RED}Error: $1${NC}"
|
echo -e "${RED}$(get_message 12) $1${NC}"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
# 清理函数
|
# 清理函数 / Cleanup function
|
||||||
cleanup() {
|
cleanup() {
|
||||||
echo "Cleaning old builds..."
|
echo "$(get_message 1)"
|
||||||
rm -rf ../bin
|
rm -rf ../bin
|
||||||
}
|
}
|
||||||
|
|
||||||
# 创建输出目录
|
# 创建输出目录 / Create output directory
|
||||||
create_output_dir() {
|
create_output_dir() {
|
||||||
echo "Creating bin directory..."
|
echo "$(get_message 2)"
|
||||||
mkdir -p ../bin || handle_error "Failed to create bin directory"
|
mkdir -p ../bin || handle_error "$(get_message 3)"
|
||||||
}
|
}
|
||||||
|
|
||||||
# 构建函数
|
# 构建函数 / Build function
|
||||||
build() {
|
build() {
|
||||||
local os=$1
|
local os=$1
|
||||||
local arch=$2
|
local arch=$2
|
||||||
local suffix=$3
|
local suffix=$3
|
||||||
|
|
||||||
echo -e "\nBuilding for $os ($arch)..."
|
echo -e "\n$(get_message 4) $os ($arch)..."
|
||||||
|
|
||||||
output_name="../bin/cursor_id_modifier_v${VERSION}_${os}_${arch}${suffix}"
|
output_name="../bin/cursor_id_modifier_v${VERSION}_${os}_${arch}${suffix}"
|
||||||
|
|
||||||
GOOS=$os GOARCH=$arch go build -o "$output_name" ../main.go
|
GOOS=$os GOARCH=$arch go build -o "$output_name" ../main.go
|
||||||
|
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
echo -e "${GREEN}✓ Successfully built: ${output_name}${NC}"
|
echo -e "${GREEN}✓ $(get_message 5) ${output_name}${NC}"
|
||||||
else
|
else
|
||||||
echo -e "${RED}✗ Failed to build for $os $arch${NC}"
|
echo -e "${RED}✗ $(get_message 6) $os $arch${NC}"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# 主函数
|
# 主函数 / Main function
|
||||||
main() {
|
main() {
|
||||||
# 显示构建信息
|
# 显示构建信息 / Display build info
|
||||||
echo "Starting build process for version ${VERSION}"
|
echo "$(get_message 0) ${VERSION}"
|
||||||
|
|
||||||
# 清理旧文件
|
# 清理旧文件 / Clean old files
|
||||||
cleanup
|
cleanup
|
||||||
|
|
||||||
# 创建输出目录
|
# 创建输出目录 / Create output directory
|
||||||
create_output_dir
|
create_output_dir
|
||||||
|
|
||||||
# 定义构建目标
|
# 定义构建目标 / Define build targets
|
||||||
declare -A targets=(
|
declare -A targets=(
|
||||||
["windows_amd64"]=".exe"
|
["windows_amd64"]=".exe"
|
||||||
["darwin_amd64"]=""
|
["darwin_amd64"]=""
|
||||||
@ -65,11 +119,11 @@ main() {
|
|||||||
["linux_amd64"]=""
|
["linux_amd64"]=""
|
||||||
)
|
)
|
||||||
|
|
||||||
# 构建计数器
|
# 构建计数器 / Build counters
|
||||||
local success_count=0
|
local success_count=0
|
||||||
local fail_count=0
|
local fail_count=0
|
||||||
|
|
||||||
# 遍历所有目标进行构建
|
# 遍历所有目标进行构建 / Build all targets
|
||||||
for target in "${!targets[@]}"; do
|
for target in "${!targets[@]}"; do
|
||||||
os=${target%_*}
|
os=${target%_*}
|
||||||
arch=${target#*_}
|
arch=${target#*_}
|
||||||
@ -82,20 +136,20 @@ main() {
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
# 显示构建结果
|
# 显示构建结果 / Display build results
|
||||||
echo -e "\nBuild Summary:"
|
echo -e "\n$(get_message 7)"
|
||||||
echo -e "${GREEN}Successful builds: $success_count${NC}"
|
echo -e "${GREEN}$(get_message 8) $success_count${NC}"
|
||||||
if [ $fail_count -gt 0 ]; then
|
if [ $fail_count -gt 0 ]; then
|
||||||
echo -e "${RED}Failed builds: $fail_count${NC}"
|
echo -e "${RED}$(get_message 9) $fail_count${NC}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 显示生成的文件列表
|
# 显示生成的文件列表 / Display generated files
|
||||||
echo -e "\nGenerated files:"
|
echo -e "\n$(get_message 10)"
|
||||||
ls -1 ../bin
|
ls -1 ../bin
|
||||||
}
|
}
|
||||||
|
|
||||||
# 捕获错误信号
|
# 捕获错误信号 / Catch error signals
|
||||||
trap 'echo -e "\n${RED}Build process interrupted${NC}"; exit 1' INT TERM
|
trap 'echo -e "\n${RED}$(get_message 11)${NC}"; exit 1' INT TERM
|
||||||
|
|
||||||
# 执行主函数
|
# 执行主函数 / Execute main function
|
||||||
main
|
main
|
216
scripts/install.ps1
Normal file
216
scripts/install.ps1
Normal file
@ -0,0 +1,216 @@
|
|||||||
|
# Auto-elevate to admin rights if not already running as admin
|
||||||
|
if (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
|
||||||
|
Write-Host "Requesting administrator privileges..."
|
||||||
|
Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs
|
||||||
|
Exit
|
||||||
|
}
|
||||||
|
|
||||||
|
# Set TLS to 1.2 / 设置 TLS 为 1.2
|
||||||
|
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
|
||||||
|
|
||||||
|
# Colors for output / 输出颜色
|
||||||
|
$Red = "`e[31m"
|
||||||
|
$Green = "`e[32m"
|
||||||
|
$Blue = "`e[36m"
|
||||||
|
$Yellow = "`e[33m"
|
||||||
|
$Reset = "`e[0m"
|
||||||
|
|
||||||
|
# Messages / 消息
|
||||||
|
$EN_MESSAGES = @(
|
||||||
|
"Starting installation...",
|
||||||
|
"Detected architecture:",
|
||||||
|
"Only 64-bit Windows is supported",
|
||||||
|
"Latest version:",
|
||||||
|
"Creating installation directory...",
|
||||||
|
"Downloading latest release from:",
|
||||||
|
"Failed to download binary:",
|
||||||
|
"Downloaded file not found",
|
||||||
|
"Installing binary...",
|
||||||
|
"Failed to install binary:",
|
||||||
|
"Adding to PATH...",
|
||||||
|
"Cleaning up...",
|
||||||
|
"Installation completed successfully!",
|
||||||
|
"You can now use 'cursor-id-modifier' from any terminal (you may need to restart your terminal first)",
|
||||||
|
"Checking for running Cursor instances...",
|
||||||
|
"Found running Cursor processes. Attempting to close them...",
|
||||||
|
"Successfully closed all Cursor instances",
|
||||||
|
"Failed to close Cursor instances. Please close them manually",
|
||||||
|
"Backing up storage.json...",
|
||||||
|
"Backup created at:"
|
||||||
|
)
|
||||||
|
|
||||||
|
$CN_MESSAGES = @(
|
||||||
|
"开始安装...",
|
||||||
|
"检测到架构:",
|
||||||
|
"仅支持64位Windows系统",
|
||||||
|
"最新版本:",
|
||||||
|
"正在创建安装目录...",
|
||||||
|
"正在从以下地址下载最新版本:",
|
||||||
|
"下载二进制文件失败:",
|
||||||
|
"未找到下载的文件",
|
||||||
|
"正在安装程序...",
|
||||||
|
"安装二进制文件失败:",
|
||||||
|
"正在添加到PATH...",
|
||||||
|
"正在清理...",
|
||||||
|
"安装成功完成!",
|
||||||
|
"现在可以在任何终端中使用 'cursor-id-modifier' 了(可能需要重启终端)",
|
||||||
|
"正在检查运行中的Cursor进程...",
|
||||||
|
"发现正在运行的Cursor进程,尝试关闭...",
|
||||||
|
"成功关闭所有Cursor实例",
|
||||||
|
"无法关闭Cursor实例,请手动关闭",
|
||||||
|
"正在备份storage.json...",
|
||||||
|
"备份已创建于:"
|
||||||
|
)
|
||||||
|
|
||||||
|
# Detect system language / 检测系统语言
|
||||||
|
function Get-SystemLanguage {
|
||||||
|
if ((Get-Culture).Name -like "zh-CN") {
|
||||||
|
return "cn"
|
||||||
|
}
|
||||||
|
return "en"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Get message based on language / 根据语言获取消息
|
||||||
|
function Get-Message($Index) {
|
||||||
|
$lang = Get-SystemLanguage
|
||||||
|
if ($lang -eq "cn") {
|
||||||
|
return $CN_MESSAGES[$Index]
|
||||||
|
}
|
||||||
|
return $EN_MESSAGES[$Index]
|
||||||
|
}
|
||||||
|
|
||||||
|
# Functions for colored output / 彩色输出函数
|
||||||
|
function Write-Status($Message) {
|
||||||
|
Write-Host "${Blue}[*]${Reset} $Message"
|
||||||
|
}
|
||||||
|
|
||||||
|
function Write-Success($Message) {
|
||||||
|
Write-Host "${Green}[✓]${Reset} $Message"
|
||||||
|
}
|
||||||
|
|
||||||
|
function Write-Warning($Message) {
|
||||||
|
Write-Host "${Yellow}[!]${Reset} $Message"
|
||||||
|
}
|
||||||
|
|
||||||
|
function Write-Error($Message) {
|
||||||
|
Write-Host "${Red}[✗]${Reset} $Message"
|
||||||
|
Exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Close Cursor instances / 关闭Cursor实例
|
||||||
|
function Close-CursorInstances {
|
||||||
|
Write-Status (Get-Message 14)
|
||||||
|
$cursorProcesses = Get-Process "Cursor" -ErrorAction SilentlyContinue
|
||||||
|
|
||||||
|
if ($cursorProcesses) {
|
||||||
|
Write-Status (Get-Message 15)
|
||||||
|
try {
|
||||||
|
$cursorProcesses | ForEach-Object { $_.CloseMainWindow() | Out-Null }
|
||||||
|
Start-Sleep -Seconds 2
|
||||||
|
$cursorProcesses | Where-Object { !$_.HasExited } | Stop-Process -Force
|
||||||
|
Write-Success (Get-Message 16)
|
||||||
|
} catch {
|
||||||
|
Write-Error (Get-Message 17)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Backup storage.json / 备份storage.json
|
||||||
|
function Backup-StorageJson {
|
||||||
|
Write-Status (Get-Message 18)
|
||||||
|
$storageJsonPath = "$env:APPDATA\Cursor\User\globalStorage\storage.json"
|
||||||
|
if (Test-Path $storageJsonPath) {
|
||||||
|
$backupPath = "$storageJsonPath.backup"
|
||||||
|
Copy-Item -Path $storageJsonPath -Destination $backupPath -Force
|
||||||
|
Write-Success "$(Get-Message 19) $backupPath"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Get latest release version from GitHub / 从GitHub获取最新版本
|
||||||
|
function Get-LatestVersion {
|
||||||
|
$repo = "yuaotian/go-cursor-help"
|
||||||
|
$release = Invoke-RestMethod -Uri "https://api.github.com/repos/$repo/releases/latest"
|
||||||
|
return $release.tag_name
|
||||||
|
}
|
||||||
|
|
||||||
|
# Main installation process / 主安装过程
|
||||||
|
Write-Status (Get-Message 0)
|
||||||
|
|
||||||
|
# Close any running Cursor instances
|
||||||
|
Close-CursorInstances
|
||||||
|
|
||||||
|
# Backup storage.json
|
||||||
|
Backup-StorageJson
|
||||||
|
|
||||||
|
# Get system architecture / 获取系统架构
|
||||||
|
$arch = if ([Environment]::Is64BitOperatingSystem) { "amd64" } else { "386" }
|
||||||
|
Write-Status "$(Get-Message 1) $arch"
|
||||||
|
|
||||||
|
if ($arch -ne "amd64") {
|
||||||
|
Write-Error (Get-Message 2)
|
||||||
|
}
|
||||||
|
|
||||||
|
# Get latest version / 获取最新版本
|
||||||
|
$version = Get-LatestVersion
|
||||||
|
Write-Status "$(Get-Message 3) $version"
|
||||||
|
|
||||||
|
# Set up paths / 设置路径
|
||||||
|
$installDir = "$env:ProgramFiles\cursor-id-modifier"
|
||||||
|
$binaryName = "cursor_id_modifier_${version}_windows_amd64.exe"
|
||||||
|
$downloadUrl = "https://github.com/yuaotian/go-cursor-help/releases/download/$version/$binaryName"
|
||||||
|
$tempFile = "$env:TEMP\$binaryName"
|
||||||
|
|
||||||
|
# Create installation directory / 创建安装目录
|
||||||
|
Write-Status (Get-Message 4)
|
||||||
|
if (-not (Test-Path $installDir)) {
|
||||||
|
New-Item -ItemType Directory -Path $installDir -Force | Out-Null
|
||||||
|
}
|
||||||
|
|
||||||
|
# Download binary / 下载二进制文件
|
||||||
|
Write-Status "$(Get-Message 5) $downloadUrl"
|
||||||
|
try {
|
||||||
|
Invoke-WebRequest -Uri $downloadUrl -OutFile $tempFile
|
||||||
|
} catch {
|
||||||
|
Write-Error "$(Get-Message 6) $_"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Verify download / 验证下载
|
||||||
|
if (-not (Test-Path $tempFile)) {
|
||||||
|
Write-Error (Get-Message 7)
|
||||||
|
}
|
||||||
|
|
||||||
|
# Install binary / 安装二进制文件
|
||||||
|
Write-Status (Get-Message 8)
|
||||||
|
try {
|
||||||
|
Move-Item -Force $tempFile "$installDir\cursor-id-modifier.exe"
|
||||||
|
} catch {
|
||||||
|
Write-Error "$(Get-Message 9) $_"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Add to PATH if not already present / 如果尚未添加则添加到PATH
|
||||||
|
$userPath = [Environment]::GetEnvironmentVariable("Path", "User")
|
||||||
|
if ($userPath -notlike "*$installDir*") {
|
||||||
|
Write-Status (Get-Message 10)
|
||||||
|
[Environment]::SetEnvironmentVariable(
|
||||||
|
"Path",
|
||||||
|
"$userPath;$installDir",
|
||||||
|
"User"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
# Create shortcut in Start Menu / 在开始菜单创建快捷方式
|
||||||
|
$startMenuPath = "$env:ProgramData\Microsoft\Windows\Start Menu\Programs\cursor-id-modifier.lnk"
|
||||||
|
$shell = New-Object -ComObject WScript.Shell
|
||||||
|
$shortcut = $shell.CreateShortcut($startMenuPath)
|
||||||
|
$shortcut.TargetPath = "$installDir\cursor-id-modifier.exe"
|
||||||
|
$shortcut.Save()
|
||||||
|
|
||||||
|
# Cleanup / 清理
|
||||||
|
Write-Status (Get-Message 11)
|
||||||
|
if (Test-Path $tempFile) {
|
||||||
|
Remove-Item -Force $tempFile
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Success (Get-Message 12)
|
||||||
|
Write-Success (Get-Message 13)
|
||||||
|
Write-Host ""
|
251
scripts/install.sh
Executable file
251
scripts/install.sh
Executable file
@ -0,0 +1,251 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# Colors for output / 输出颜色
|
||||||
|
RED='\033[0;31m'
|
||||||
|
GREEN='\033[0;32m'
|
||||||
|
BLUE='\033[0;36m'
|
||||||
|
YELLOW='\033[0;33m'
|
||||||
|
NC='\033[0m' # No Color / 无颜色
|
||||||
|
|
||||||
|
# Messages / 消息
|
||||||
|
EN_MESSAGES=(
|
||||||
|
"Starting installation..."
|
||||||
|
"Detected OS:"
|
||||||
|
"Downloading latest release..."
|
||||||
|
"URL:"
|
||||||
|
"Installing binary..."
|
||||||
|
"Cleaning up..."
|
||||||
|
"Installation completed successfully!"
|
||||||
|
"You can now use 'sudo %s' from your terminal"
|
||||||
|
"Failed to download binary from:"
|
||||||
|
"Failed to download the binary"
|
||||||
|
"curl is required but not installed. Please install curl first."
|
||||||
|
"sudo is required but not installed. Please install sudo first."
|
||||||
|
"Unsupported operating system"
|
||||||
|
"Unsupported architecture:"
|
||||||
|
"Checking for running Cursor instances..."
|
||||||
|
"Found running Cursor processes. Attempting to close them..."
|
||||||
|
"Successfully closed all Cursor instances"
|
||||||
|
"Failed to close Cursor instances. Please close them manually"
|
||||||
|
"Backing up storage.json..."
|
||||||
|
"Backup created at:"
|
||||||
|
"This script requires root privileges. Requesting sudo access..."
|
||||||
|
)
|
||||||
|
|
||||||
|
CN_MESSAGES=(
|
||||||
|
"开始安装..."
|
||||||
|
"检测到操作系统:"
|
||||||
|
"正在下载最新版本..."
|
||||||
|
"下载地址:"
|
||||||
|
"正在安装程序..."
|
||||||
|
"正在清理..."
|
||||||
|
"安装成功完成!"
|
||||||
|
"现在可以在终端中使用 'sudo %s' 了"
|
||||||
|
"从以下地址下载二进制文件失败:"
|
||||||
|
"下载二进制文件失败"
|
||||||
|
"需要 curl 但未安装。请先安装 curl。"
|
||||||
|
"需要 sudo 但未安装。请先安装 sudo。"
|
||||||
|
"不支持的操作系统"
|
||||||
|
"不支持的架构:"
|
||||||
|
"正在检查运行中的Cursor进程..."
|
||||||
|
"发现正在运行的Cursor进程,尝试关闭..."
|
||||||
|
"成功关闭所有Cursor实例"
|
||||||
|
"无法关闭Cursor实例,请手动关闭"
|
||||||
|
"正在备份storage.json..."
|
||||||
|
"备份已创建于:"
|
||||||
|
"此脚本需要root权限。正在请求sudo访问..."
|
||||||
|
)
|
||||||
|
|
||||||
|
# Detect system language / 检测系统语言
|
||||||
|
detect_language() {
|
||||||
|
if [[ $(locale | grep "LANG=zh_CN") ]]; then
|
||||||
|
echo "cn"
|
||||||
|
else
|
||||||
|
echo "en"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Get message based on language / 根据语言获取消息
|
||||||
|
get_message() {
|
||||||
|
local index=$1
|
||||||
|
local lang=$(detect_language)
|
||||||
|
|
||||||
|
if [[ "$lang" == "cn" ]]; then
|
||||||
|
echo "${CN_MESSAGES[$index]}"
|
||||||
|
else
|
||||||
|
echo "${EN_MESSAGES[$index]}"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Print with color / 带颜色打印
|
||||||
|
print_status() {
|
||||||
|
echo -e "${BLUE}[*]${NC} $1"
|
||||||
|
}
|
||||||
|
|
||||||
|
print_success() {
|
||||||
|
echo -e "${GREEN}[✓]${NC} $1"
|
||||||
|
}
|
||||||
|
|
||||||
|
print_warning() {
|
||||||
|
echo -e "${YELLOW}[!]${NC} $1"
|
||||||
|
}
|
||||||
|
|
||||||
|
print_error() {
|
||||||
|
echo -e "${RED}[✗]${NC} $1"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Check and request root privileges / 检查并请求root权限
|
||||||
|
check_root() {
|
||||||
|
if [ "$EUID" -ne 0 ]; then
|
||||||
|
print_status "$(get_message 20)"
|
||||||
|
if command -v sudo >/dev/null 2>&1; then
|
||||||
|
exec sudo bash "$0" "$@"
|
||||||
|
else
|
||||||
|
print_error "$(get_message 11)"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Close Cursor instances / 关闭Cursor实例
|
||||||
|
close_cursor_instances() {
|
||||||
|
print_status "$(get_message 14)"
|
||||||
|
|
||||||
|
if pgrep -x "Cursor" >/dev/null; then
|
||||||
|
print_status "$(get_message 15)"
|
||||||
|
if pkill -x "Cursor" 2>/dev/null; then
|
||||||
|
sleep 2
|
||||||
|
print_success "$(get_message 16)"
|
||||||
|
else
|
||||||
|
print_error "$(get_message 17)"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Backup storage.json / 备份storage.json
|
||||||
|
backup_storage_json() {
|
||||||
|
print_status "$(get_message 18)"
|
||||||
|
local storage_path
|
||||||
|
|
||||||
|
if [ "$(uname)" == "Darwin" ]; then
|
||||||
|
storage_path="$HOME/Library/Application Support/Cursor/User/globalStorage/storage.json"
|
||||||
|
else
|
||||||
|
storage_path="$HOME/.config/Cursor/User/globalStorage/storage.json"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -f "$storage_path" ]; then
|
||||||
|
cp "$storage_path" "${storage_path}.backup"
|
||||||
|
print_success "$(get_message 19) ${storage_path}.backup"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Detect OS / 检测操作系统
|
||||||
|
detect_os() {
|
||||||
|
if [[ "$OSTYPE" == "darwin"* ]]; then
|
||||||
|
echo "macos"
|
||||||
|
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
|
||||||
|
echo "linux"
|
||||||
|
else
|
||||||
|
print_error "$(get_message 12)"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Get latest release version from GitHub / 从GitHub获取最新版本
|
||||||
|
get_latest_version() {
|
||||||
|
local repo="yuaotian/go-cursor-help"
|
||||||
|
curl -s "https://api.github.com/repos/${repo}/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/'
|
||||||
|
}
|
||||||
|
|
||||||
|
# Get the binary name based on OS and architecture / 根据操作系统和架构获取二进制文件名
|
||||||
|
get_binary_name() {
|
||||||
|
OS=$(detect_os)
|
||||||
|
ARCH=$(uname -m)
|
||||||
|
VERSION=$(get_latest_version)
|
||||||
|
|
||||||
|
case "$ARCH" in
|
||||||
|
x86_64)
|
||||||
|
echo "cursor_id_modifier_${VERSION}_${OS}_amd64"
|
||||||
|
;;
|
||||||
|
aarch64|arm64)
|
||||||
|
echo "cursor_id_modifier_${VERSION}_${OS}_arm64"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
print_error "$(get_message 13) $ARCH"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
# Install the binary / 安装二进制文件
|
||||||
|
install_binary() {
|
||||||
|
OS=$(detect_os)
|
||||||
|
BINARY_NAME=$(get_binary_name)
|
||||||
|
REPO="yuaotian/go-cursor-help"
|
||||||
|
VERSION=$(get_latest_version)
|
||||||
|
DOWNLOAD_URL="https://github.com/${REPO}/releases/download/${VERSION}/${BINARY_NAME}"
|
||||||
|
TMP_DIR=$(mktemp -d)
|
||||||
|
FINAL_BINARY_NAME="cursor-id-modifier"
|
||||||
|
|
||||||
|
print_status "$(get_message 2)"
|
||||||
|
print_status "$(get_message 3) ${DOWNLOAD_URL}"
|
||||||
|
|
||||||
|
if ! curl -L -f "$DOWNLOAD_URL" -o "$TMP_DIR/$BINARY_NAME"; then
|
||||||
|
print_error "$(get_message 8) $DOWNLOAD_URL"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -f "$TMP_DIR/$BINARY_NAME" ]; then
|
||||||
|
print_error "$(get_message 9)"
|
||||||
|
fi
|
||||||
|
|
||||||
|
print_status "$(get_message 4)"
|
||||||
|
INSTALL_DIR="/usr/local/bin"
|
||||||
|
|
||||||
|
# Create directory if it doesn't exist / 如果目录不存在则创建
|
||||||
|
mkdir -p "$INSTALL_DIR"
|
||||||
|
|
||||||
|
# Move binary to installation directory / 移动二进制文件到安装目录
|
||||||
|
mv "$TMP_DIR/$BINARY_NAME" "$INSTALL_DIR/$FINAL_BINARY_NAME"
|
||||||
|
chmod +x "$INSTALL_DIR/$FINAL_BINARY_NAME"
|
||||||
|
|
||||||
|
# Cleanup / 清理
|
||||||
|
print_status "$(get_message 5)"
|
||||||
|
rm -rf "$TMP_DIR"
|
||||||
|
|
||||||
|
print_success "$(get_message 6)"
|
||||||
|
printf "${GREEN}[✓]${NC} $(get_message 7)\n" "$FINAL_BINARY_NAME"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Check for required tools / 检查必需工具
|
||||||
|
check_requirements() {
|
||||||
|
if ! command -v curl >/dev/null 2>&1; then
|
||||||
|
print_error "$(get_message 10)"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! command -v sudo >/dev/null 2>&1; then
|
||||||
|
print_error "$(get_message 11)"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Main installation process / 主安装过程
|
||||||
|
main() {
|
||||||
|
print_status "$(get_message 0)"
|
||||||
|
|
||||||
|
# Check root privileges / 检查root权限
|
||||||
|
check_root "$@"
|
||||||
|
|
||||||
|
# Close Cursor instances / 关闭Cursor实例
|
||||||
|
close_cursor_instances
|
||||||
|
|
||||||
|
# Backup storage.json / 备份storage.json
|
||||||
|
backup_storage_json
|
||||||
|
|
||||||
|
OS=$(detect_os)
|
||||||
|
print_status "$(get_message 1) $OS"
|
||||||
|
|
||||||
|
check_requirements
|
||||||
|
install_binary
|
||||||
|
}
|
||||||
|
|
||||||
|
# Run main function / 运行主函数
|
||||||
|
main "$@"
|
Loading…
x
Reference in New Issue
Block a user