Browse Source

chore: Update installation script and .gitignore for improved functionality

- Enhanced `install.sh` by adding network connectivity checks and executable file format validation to ensure a smoother installation process.
- Updated the installation directory creation logic to handle errors more gracefully.
- Modified the download URL to point to the correct repository branch and improved the curl command to show download progress.
- Cleaned up `.gitignore` by removing obsolete entries related to binaries and IDE configurations, streamlining the ignored files list.
- Added a new function to clean up old versions of the binary during installation.

These changes improve the reliability and user experience of the installation process.
pull/20/head
Xx 6 months ago
parent
commit
e46a7ecfec
  1. 8
      .gitignore
  2. 1
      .vscode/settings.json
  3. BIN
      bin/cursor_id_modifier_v2.0.0_darwin_amd64_intel
  4. BIN
      bin/cursor_id_modifier_v2.0.0_darwin_arm64_m1
  5. 41
      install.sh

8
.gitignore

@ -1,20 +1,12 @@
# Binary files
app.exe
cursor-id-modifier-linux
cursor-id-modifier-macos
cursor-id-modifier-*
*.exe
*.dll
*.so
*.dylib
# Build directories
bin/
releases/
scripts/
# IDE
.vscode/
# Go specific
go.sum

1
.vscode/settings.json

@ -1,6 +1,7 @@
{
"cSpell.words": [
"buildmode",
"dylib",
"endlocal",
"errorlevel",
"fatih",

BIN
bin/cursor_id_modifier_v2.0.0_darwin_amd64_intel

BIN
bin/cursor_id_modifier_v2.0.0_darwin_arm64_m1

41
install.sh

@ -55,6 +55,12 @@ detect_platform() {
check_requirements() {
info "Checking system requirements..." "正在检查系统要求..."
# 添加网络连接检查
if ! ping -c 1 github.com >/dev/null 2>&1; then
error "No network connection to GitHub" \
"无法连接到 GitHub"
fi
# Check curl
if ! command -v curl >/dev/null 2>&1; then
error "curl is required. Please install curl first." \
@ -76,6 +82,12 @@ verify_binary() {
"二进制文件下载失败或不存在"
fi
# 添加可执行文件格式检查
if ! file "$TEMP_DIR/$BINARY_NAME" | grep -q "executable"; then
error "Downloaded file is not an executable" \
"下载的文件不是可执行文件"
fi
# Check file size / 检查文件大小
local size=$(wc -c < "$TEMP_DIR/$BINARY_NAME")
if [ "$size" -lt 1000000 ]; then # At least 1MB / 至少1MB
@ -92,7 +104,12 @@ main() {
# Initialize installation / 初始化安装
detect_platform
INSTALL_DIR="/usr/local/bin"
[ -d "$INSTALL_DIR" ] || mkdir -p "$INSTALL_DIR"
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
@ -104,10 +121,16 @@ main() {
# Download binary / 下载二进制文件
info "Downloading cursor-id-modifier ($OS-$ARCH)..." \
"正在下载 cursor-id-modifier ($OS-$ARCH)..."
DOWNLOAD_URL="https://github.com/yuaotian/go-cursor-help/raw/main/bin/$BINARY_NAME"
if ! curl -fsSL "$DOWNLOAD_URL" -o "$TEMP_DIR/$BINARY_NAME"; then
error "Failed to download binary" "下载二进制文件失败"
# 修改下载 URL,使用正确的仓库分支和文件路径
DOWNLOAD_URL="https://github.com/yuaotian/go-cursor-help/raw/refs/heads/master/bin/$BINARY_NAME"
# 使用 curl 显示详细的下载进度信息
if ! curl -L --progress --show-error \
--write-out "\n" \
"$DOWNLOAD_URL" -o "$TEMP_DIR/$BINARY_NAME"; then
error "Failed to download binary from: $DOWNLOAD_URL" \
"从以下地址下载二进制文件失败:$DOWNLOAD_URL"
fi
# Verify download / 验证下载
@ -116,7 +139,7 @@ main() {
# Set permissions / 设置权限
info "Setting execution permissions..." "正在设置执行权限..."
if ! chmod +x "$TEMP_DIR/$BINARY_NAME"; then
error "Failed to set executable permissions" "无法设置可执行权���"
error "Failed to set executable permissions" "无法设置可执行权"
fi
# Handle macOS security / 处理macOS安全设置
@ -137,5 +160,13 @@ main() {
"如需帮助,请运行 'cursor-id-modifier --help'"
}
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
}
# Start installation / 开始安装
main
Loading…
Cancel
Save