mirror of
https://github.com/yuaotian/go-cursor-help.git
synced 2025-06-08 12:32:06 +08:00
feat: Enhance installation scripts with logging, progress display, and prerequisite checks
- Added logging functionality to track installation progress and errors in both PowerShell and Bash scripts. - Implemented a download progress display for better user experience during file downloads. - Introduced prerequisite checks to ensure the required PowerShell version and internet connectivity before installation. - Modified the installation process to run the installed program directly after completion. - Updated messages to clarify usage instructions for the 'cursor-id-modifier' tool. These changes improve the robustness and user-friendliness of the installation process across platforms.
This commit is contained in:
parent
3316f8b0b0
commit
180c3fd275
@ -1,7 +1,8 @@
|
|||||||
# Auto-elevate to admin rights if not already running as admin
|
# 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")) {
|
if (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
|
||||||
Write-Host "Requesting administrator privileges..."
|
Write-Host "Requesting administrator privileges..."
|
||||||
Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs
|
$arguments = "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`" -ExecutionFromElevated"
|
||||||
|
Start-Process powershell.exe -ArgumentList $arguments -Verb RunAs
|
||||||
Exit
|
Exit
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -30,7 +31,7 @@ $EN_MESSAGES = @(
|
|||||||
"Adding to PATH...",
|
"Adding to PATH...",
|
||||||
"Cleaning up...",
|
"Cleaning up...",
|
||||||
"Installation completed successfully!",
|
"Installation completed successfully!",
|
||||||
"You can now use 'cursor-id-modifier' from any terminal (you may need to restart your terminal first)",
|
"You can now use 'cursor-id-modifier' directly",
|
||||||
"Checking for running Cursor instances...",
|
"Checking for running Cursor instances...",
|
||||||
"Found running Cursor processes. Attempting to close them...",
|
"Found running Cursor processes. Attempting to close them...",
|
||||||
"Successfully closed all Cursor instances",
|
"Successfully closed all Cursor instances",
|
||||||
@ -53,7 +54,7 @@ $CN_MESSAGES = @(
|
|||||||
"正在添加到PATH...",
|
"正在添加到PATH...",
|
||||||
"正在清理...",
|
"正在清理...",
|
||||||
"安装成功完成!",
|
"安装成功完成!",
|
||||||
"现在可以在任何终端中使用 'cursor-id-modifier' 了(可能需要重启终端)",
|
"现在可以直接使用 'cursor-id-modifier' 了",
|
||||||
"正在检查运行中的Cursor进程...",
|
"正在检查运行中的Cursor进程...",
|
||||||
"发现正在运行的Cursor进程,尝试关闭...",
|
"发现正在运行的Cursor进程,尝试关闭...",
|
||||||
"成功关闭所有Cursor实例",
|
"成功关闭所有Cursor实例",
|
||||||
@ -133,6 +134,94 @@ function Get-LatestVersion {
|
|||||||
return $release.tag_name
|
return $release.tag_name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# 在文件开头添加日志函数
|
||||||
|
function Write-Log {
|
||||||
|
param(
|
||||||
|
[string]$Message,
|
||||||
|
[string]$Level = "INFO"
|
||||||
|
)
|
||||||
|
$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
|
||||||
|
$logMessage = "[$timestamp] [$Level] $Message"
|
||||||
|
$logFile = "$env:TEMP\cursor-id-modifier-install.log"
|
||||||
|
Add-Content -Path $logFile -Value $logMessage
|
||||||
|
|
||||||
|
# 同时输出到控制台
|
||||||
|
switch ($Level) {
|
||||||
|
"ERROR" { Write-Error $Message }
|
||||||
|
"WARNING" { Write-Warning $Message }
|
||||||
|
"SUCCESS" { Write-Success $Message }
|
||||||
|
default { Write-Status $Message }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# 添加安装前检查函数
|
||||||
|
function Test-Prerequisites {
|
||||||
|
Write-Log "Checking prerequisites..." "INFO"
|
||||||
|
|
||||||
|
# 检查PowerShell版本
|
||||||
|
if ($PSVersionTable.PSVersion.Major -lt 5) {
|
||||||
|
Write-Log "PowerShell 5.0 or higher is required" "ERROR"
|
||||||
|
return $false
|
||||||
|
}
|
||||||
|
|
||||||
|
# 检查网络连接
|
||||||
|
try {
|
||||||
|
$testConnection = Test-Connection -ComputerName "github.com" -Count 1 -Quiet
|
||||||
|
if (-not $testConnection) {
|
||||||
|
Write-Log "No internet connection available" "ERROR"
|
||||||
|
return $false
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
Write-Log "Failed to check internet connection: $_" "ERROR"
|
||||||
|
return $false
|
||||||
|
}
|
||||||
|
|
||||||
|
return $true
|
||||||
|
}
|
||||||
|
|
||||||
|
# 添加文件验证函数
|
||||||
|
function Test-FileHash {
|
||||||
|
param(
|
||||||
|
[string]$FilePath,
|
||||||
|
[string]$ExpectedHash
|
||||||
|
)
|
||||||
|
|
||||||
|
$actualHash = Get-FileHash -Path $FilePath -Algorithm SHA256
|
||||||
|
return $actualHash.Hash -eq $ExpectedHash
|
||||||
|
}
|
||||||
|
|
||||||
|
# 修改下载函数,添加进度条
|
||||||
|
function Download-File {
|
||||||
|
param(
|
||||||
|
[string]$Url,
|
||||||
|
[string]$OutFile
|
||||||
|
)
|
||||||
|
|
||||||
|
try {
|
||||||
|
$webClient = New-Object System.Net.WebClient
|
||||||
|
$webClient.Headers.Add("User-Agent", "PowerShell Script")
|
||||||
|
|
||||||
|
$webClient.DownloadFileAsync($Url, $OutFile)
|
||||||
|
|
||||||
|
while ($webClient.IsBusy) {
|
||||||
|
Write-Progress -Activity "Downloading..." -Status "Progress:" -PercentComplete -1
|
||||||
|
Start-Sleep -Milliseconds 100
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Progress -Activity "Downloading..." -Completed
|
||||||
|
return $true
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Write-Log "Download failed: $_" "ERROR"
|
||||||
|
return $false
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
if ($webClient) {
|
||||||
|
$webClient.Dispose()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
# Main installation process / 主安装过程
|
# Main installation process / 主安装过程
|
||||||
Write-Status (Get-Message 0)
|
Write-Status (Get-Message 0)
|
||||||
|
|
||||||
@ -156,7 +245,8 @@ Write-Status "$(Get-Message 3) $version"
|
|||||||
|
|
||||||
# Set up paths / 设置路径
|
# Set up paths / 设置路径
|
||||||
$installDir = "$env:ProgramFiles\cursor-id-modifier"
|
$installDir = "$env:ProgramFiles\cursor-id-modifier"
|
||||||
$binaryName = "cursor_id_modifier_${version}_windows_amd64.exe"
|
$versionWithoutV = $version.TrimStart('v') # 移除版本号前面的 'v' 字符
|
||||||
|
$binaryName = "cursor_id_modifier_${versionWithoutV}_windows_amd64.exe"
|
||||||
$downloadUrl = "https://github.com/yuaotian/go-cursor-help/releases/download/$version/$binaryName"
|
$downloadUrl = "https://github.com/yuaotian/go-cursor-help/releases/download/$version/$binaryName"
|
||||||
$tempFile = "$env:TEMP\$binaryName"
|
$tempFile = "$env:TEMP\$binaryName"
|
||||||
|
|
||||||
@ -169,7 +259,9 @@ if (-not (Test-Path $installDir)) {
|
|||||||
# Download binary / 下载二进制文件
|
# Download binary / 下载二进制文件
|
||||||
Write-Status "$(Get-Message 5) $downloadUrl"
|
Write-Status "$(Get-Message 5) $downloadUrl"
|
||||||
try {
|
try {
|
||||||
Invoke-WebRequest -Uri $downloadUrl -OutFile $tempFile
|
if (-not (Download-File -Url $downloadUrl -OutFile $tempFile)) {
|
||||||
|
Write-Error "$(Get-Message 6)"
|
||||||
|
}
|
||||||
} catch {
|
} catch {
|
||||||
Write-Error "$(Get-Message 6) $_"
|
Write-Error "$(Get-Message 6) $_"
|
||||||
}
|
}
|
||||||
@ -198,13 +290,6 @@ if ($userPath -notlike "*$installDir*") {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
# 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 / 清理
|
# Cleanup / 清理
|
||||||
Write-Status (Get-Message 11)
|
Write-Status (Get-Message 11)
|
||||||
if (Test-Path $tempFile) {
|
if (Test-Path $tempFile) {
|
||||||
@ -213,4 +298,11 @@ if (Test-Path $tempFile) {
|
|||||||
|
|
||||||
Write-Success (Get-Message 12)
|
Write-Success (Get-Message 12)
|
||||||
Write-Success (Get-Message 13)
|
Write-Success (Get-Message 13)
|
||||||
Write-Host ""
|
Write-Host ""
|
||||||
|
|
||||||
|
# 直接运行程序
|
||||||
|
try {
|
||||||
|
Start-Process "$installDir\cursor-id-modifier.exe" -NoNewWindow
|
||||||
|
} catch {
|
||||||
|
Write-Warning "Failed to start cursor-id-modifier: $_"
|
||||||
|
}
|
@ -177,12 +177,22 @@ get_binary_name() {
|
|||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
# Install the binary / 安装二进制文件
|
# Add download progress display function
|
||||||
|
download_with_progress() {
|
||||||
|
local url="$1"
|
||||||
|
local output_file="$2"
|
||||||
|
|
||||||
|
curl -L -f --progress-bar "$url" -o "$output_file"
|
||||||
|
return $?
|
||||||
|
}
|
||||||
|
|
||||||
|
# Optimize installation function
|
||||||
install_binary() {
|
install_binary() {
|
||||||
OS=$(detect_os)
|
OS=$(detect_os)
|
||||||
BINARY_NAME=$(get_binary_name)
|
|
||||||
REPO="yuaotian/go-cursor-help"
|
|
||||||
VERSION=$(get_latest_version)
|
VERSION=$(get_latest_version)
|
||||||
|
VERSION_WITHOUT_V=${VERSION#v} # Remove 'v' from version number
|
||||||
|
BINARY_NAME="cursor_id_modifier_${VERSION_WITHOUT_V}_${OS}_$(get_arch)"
|
||||||
|
REPO="yuaotian/go-cursor-help"
|
||||||
DOWNLOAD_URL="https://github.com/${REPO}/releases/download/${VERSION}/${BINARY_NAME}"
|
DOWNLOAD_URL="https://github.com/${REPO}/releases/download/${VERSION}/${BINARY_NAME}"
|
||||||
TMP_DIR=$(mktemp -d)
|
TMP_DIR=$(mktemp -d)
|
||||||
FINAL_BINARY_NAME="cursor-id-modifier"
|
FINAL_BINARY_NAME="cursor-id-modifier"
|
||||||
@ -190,30 +200,61 @@ install_binary() {
|
|||||||
print_status "$(get_message 2)"
|
print_status "$(get_message 2)"
|
||||||
print_status "$(get_message 3) ${DOWNLOAD_URL}"
|
print_status "$(get_message 3) ${DOWNLOAD_URL}"
|
||||||
|
|
||||||
if ! curl -L -f "$DOWNLOAD_URL" -o "$TMP_DIR/$BINARY_NAME"; then
|
if ! download_with_progress "$DOWNLOAD_URL" "$TMP_DIR/$BINARY_NAME"; then
|
||||||
|
rm -rf "$TMP_DIR"
|
||||||
print_error "$(get_message 8) $DOWNLOAD_URL"
|
print_error "$(get_message 8) $DOWNLOAD_URL"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -f "$TMP_DIR/$BINARY_NAME" ]; then
|
if [ ! -f "$TMP_DIR/$BINARY_NAME" ]; then
|
||||||
|
rm -rf "$TMP_DIR"
|
||||||
print_error "$(get_message 9)"
|
print_error "$(get_message 9)"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
print_status "$(get_message 4)"
|
print_status "$(get_message 4)"
|
||||||
INSTALL_DIR="/usr/local/bin"
|
INSTALL_DIR="/usr/local/bin"
|
||||||
|
|
||||||
# Create directory if it doesn't exist / 如果目录不存在则创建
|
# Create directory if it doesn't exist
|
||||||
mkdir -p "$INSTALL_DIR"
|
mkdir -p "$INSTALL_DIR"
|
||||||
|
|
||||||
# Move binary to installation directory / 移动二进制文件到安装目录
|
# Move binary to installation directory
|
||||||
mv "$TMP_DIR/$BINARY_NAME" "$INSTALL_DIR/$FINAL_BINARY_NAME"
|
if ! mv "$TMP_DIR/$BINARY_NAME" "$INSTALL_DIR/$FINAL_BINARY_NAME"; then
|
||||||
chmod +x "$INSTALL_DIR/$FINAL_BINARY_NAME"
|
rm -rf "$TMP_DIR"
|
||||||
|
print_error "Failed to move binary to installation directory"
|
||||||
|
fi
|
||||||
|
|
||||||
# Cleanup / 清理
|
if ! chmod +x "$INSTALL_DIR/$FINAL_BINARY_NAME"; then
|
||||||
|
rm -rf "$TMP_DIR"
|
||||||
|
print_error "Failed to set executable permissions"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Cleanup
|
||||||
print_status "$(get_message 5)"
|
print_status "$(get_message 5)"
|
||||||
rm -rf "$TMP_DIR"
|
rm -rf "$TMP_DIR"
|
||||||
|
|
||||||
print_success "$(get_message 6)"
|
print_success "$(get_message 6)"
|
||||||
printf "${GREEN}[✓]${NC} $(get_message 7)\n" "$FINAL_BINARY_NAME"
|
printf "${GREEN}[✓]${NC} $(get_message 7)\n" "$FINAL_BINARY_NAME"
|
||||||
|
|
||||||
|
# Try to run the program directly
|
||||||
|
if [ -x "$INSTALL_DIR/$FINAL_BINARY_NAME" ]; then
|
||||||
|
"$INSTALL_DIR/$FINAL_BINARY_NAME" &
|
||||||
|
else
|
||||||
|
print_warning "Failed to start cursor-id-modifier"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Optimize architecture detection function
|
||||||
|
get_arch() {
|
||||||
|
case "$(uname -m)" in
|
||||||
|
x86_64)
|
||||||
|
echo "amd64"
|
||||||
|
;;
|
||||||
|
aarch64|arm64)
|
||||||
|
echo "arm64"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
print_error "$(get_message 13) $(uname -m)"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check for required tools / 检查必需工具
|
# Check for required tools / 检查必需工具
|
||||||
@ -234,6 +275,9 @@ main() {
|
|||||||
# Check root privileges / 检查root权限
|
# Check root privileges / 检查root权限
|
||||||
check_root "$@"
|
check_root "$@"
|
||||||
|
|
||||||
|
# Check required tools / 检查必需工具
|
||||||
|
check_requirements
|
||||||
|
|
||||||
# Close Cursor instances / 关闭Cursor实例
|
# Close Cursor instances / 关闭Cursor实例
|
||||||
close_cursor_instances
|
close_cursor_instances
|
||||||
|
|
||||||
@ -243,7 +287,7 @@ main() {
|
|||||||
OS=$(detect_os)
|
OS=$(detect_os)
|
||||||
print_status "$(get_message 1) $OS"
|
print_status "$(get_message 1) $OS"
|
||||||
|
|
||||||
check_requirements
|
# Install the binary / 安装二进制文件
|
||||||
install_binary
|
install_binary
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user