diff --git a/scripts/install.sh b/scripts/install.sh index 7c5b9d6..c8cd6d7 100644 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -1,6 +1,6 @@ #!/bin/bash -# 顏色定義 +# Color definitions RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' @@ -22,7 +22,7 @@ EOF echo -e "${NC}" } -# 获取下载文件夹路径 +# Get download folder path get_downloads_dir() { if [[ "$(uname)" == "Darwin" ]]; then echo "$HOME/Downloads" @@ -36,68 +36,95 @@ get_downloads_dir() { fi } -# 獲取最新版本 +# Get latest version get_latest_version() { - echo -e "${CYAN}ℹ️ 正在檢查最新版本...${NC}" + echo -e "${CYAN}ℹ️ Checking latest version...${NC}" local latest_release latest_release=$(curl -s https://api.github.com/repos/yeongpin/cursor-free-vip/releases/latest) if [ $? -ne 0 ]; then - echo -e "${RED}❌ 無法獲取最新版本信息${NC}" + echo -e "${RED}❌ Cannot get latest version information${NC}" exit 1 fi VERSION=$(echo "$latest_release" | grep -o '"tag_name": ".*"' | cut -d'"' -f4 | tr -d 'v') - echo -e "${GREEN}✅ 找到最新版本: ${VERSION}${NC}" + echo -e "${GREEN}✅ Found latest version: ${VERSION}${NC}" } -# 檢測系統類型和架構 +# Detect system type and architecture detect_os() { if [[ "$(uname)" == "Darwin" ]]; then - # 检测 macOS 架构 + # Detect macOS architecture ARCH=$(uname -m) if [[ "$ARCH" == "arm64" ]]; then OS="mac_arm64" - echo -e "${CYAN}ℹ️ 检测到 macOS ARM64 架构${NC}" + echo -e "${CYAN}ℹ️ Detected macOS ARM64 architecture${NC}" else OS="mac_intel" - echo -e "${CYAN}ℹ️ 检测到 macOS Intel 架构${NC}" + echo -e "${CYAN}ℹ️ Detected macOS Intel architecture${NC}" fi elif [[ "$(uname)" == "Linux" ]]; then OS="linux" - echo -e "${CYAN}ℹ️ 检测到 Linux 系统${NC}" + echo -e "${CYAN}ℹ️ Detected Linux system${NC}" else - # 假设是 Windows + # Assume Windows OS="windows" - echo -e "${CYAN}ℹ️ 检测到 Windows 系统${NC}" + echo -e "${CYAN}ℹ️ Detected Windows system${NC}" fi } -# 下載並安裝 +# Install and download install_cursor_free_vip() { local downloads_dir=$(get_downloads_dir) local binary_name="CursorFreeVIP_${VERSION}_${OS}" - local binary_path="${downloads_dir}/cursor-free-vip" + local binary_path="${downloads_dir}/${binary_name}" local download_url="https://github.com/yeongpin/cursor-free-vip/releases/download/v${VERSION}/${binary_name}" - echo -e "${CYAN}ℹ️ 正在下載到 ${downloads_dir}...${NC}" - echo -e "${CYAN}ℹ️ 下載鏈接: ${download_url}${NC}" - - # 先检查文件是否存在 - if curl --output /dev/null --silent --head --fail "$download_url"; then - echo -e "${GREEN}✅ 文件存在,开始下载...${NC}" - else - echo -e "${RED}❌ 下载链接不存在: ${download_url}${NC}" - echo -e "${YELLOW}⚠️ 尝试不带架构的版本...${NC}" + # Check if file already exists + if [ -f "${binary_path}" ]; then + echo -e "${GREEN}✅ Found existing installation file${NC}" + echo -e "${CYAN}ℹ️ Location: ${binary_path}${NC}" - # 尝试不带架构的版本 + # Check if running as root + if [ "$EUID" -ne 0 ]; then + echo -e "${YELLOW}⚠️ Requesting administrator privileges...${NC}" + if command -v sudo >/dev/null 2>&1; then + echo -e "${CYAN}ℹ️ Starting program with sudo...${NC}" + sudo chmod +x "${binary_path}" + sudo "${binary_path}" + else + echo -e "${YELLOW}⚠️ sudo not found, trying to run normally...${NC}" + chmod +x "${binary_path}" + "${binary_path}" + fi + else + # Already running as root + echo -e "${CYAN}ℹ️ Already running as root, starting program...${NC}" + chmod +x "${binary_path}" + "${binary_path}" + fi + return + fi + + echo -e "${CYAN}ℹ️ No existing installation file found, starting download...${NC}" + echo -e "${CYAN}ℹ️ Downloading to ${downloads_dir}...${NC}" + echo -e "${CYAN}ℹ️ Download link: ${download_url}${NC}" + + # Check if file exists + if curl --output /dev/null --silent --head --fail "$download_url"; then + echo -e "${GREEN}✅ File exists, starting download...${NC}" + else + echo -e "${RED}❌ Download link does not exist: ${download_url}${NC}" + echo -e "${YELLOW}⚠️ Trying without architecture...${NC}" + + # Try without architecture if [[ "$OS" == "mac_arm64" || "$OS" == "mac_intel" ]]; then OS="mac" binary_name="CursorFreeVIP_${VERSION}_${OS}" download_url="https://github.com/yeongpin/cursor-free-vip/releases/download/v${VERSION}/${binary_name}" - echo -e "${CYAN}ℹ️ 新下载链接: ${download_url}${NC}" + echo -e "${CYAN}ℹ️ New download link: ${download_url}${NC}" if ! curl --output /dev/null --silent --head --fail "$download_url"; then - echo -e "${RED}❌ 新下载链接也不存在${NC}" + echo -e "${RED}❌ New download link does not exist${NC}" exit 1 fi else @@ -105,43 +132,43 @@ install_cursor_free_vip() { fi fi - # 下载文件 + # Download file if ! curl -L -o "${binary_path}" "$download_url"; then - echo -e "${RED}❌ 下載失敗${NC}" + echo -e "${RED}❌ Download failed${NC}" exit 1 fi - # 检查下载的文件大小 + # Check downloaded file size local file_size=$(stat -f%z "${binary_path}" 2>/dev/null || stat -c%s "${binary_path}" 2>/dev/null) - echo -e "${CYAN}ℹ️ 下載的文件大小: ${file_size} 字節${NC}" + echo -e "${CYAN}ℹ️ Downloaded file size: ${file_size} bytes${NC}" - # 如果文件太小,可能是错误信息 + # If file is too small, it might be an error message if [ "$file_size" -lt 1000 ]; then - echo -e "${YELLOW}⚠️ 警告: 下載的文件太小,可能不是有效的可執行文件${NC}" - echo -e "${YELLOW}⚠️ 文件內容:${NC}" + echo -e "${YELLOW}⚠️ Warning: Downloaded file is too small, possibly not a valid executable file${NC}" + echo -e "${YELLOW}⚠️ File content:${NC}" cat "${binary_path}" echo "" - echo -e "${RED}❌ 下載失敗,請檢查版本號和操作系統是否正確${NC}" + echo -e "${RED}❌ Download failed, please check version and operating system${NC}" exit 1 fi - echo -e "${CYAN}ℹ️ 正在設置執行權限...${NC}" + echo -e "${CYAN}ℹ️ Setting executable permissions...${NC}" chmod +x "${binary_path}" if [ $? -eq 0 ]; then - echo -e "${GREEN}✅ 安裝完成!${NC}" - echo -e "${CYAN}ℹ️ 程序已下載到: ${binary_path}${NC}" - echo -e "${CYAN}ℹ️ 正在啟動程序...${NC}" + echo -e "${GREEN}✅ Installation completed!${NC}" + echo -e "${CYAN}ℹ️ Program downloaded to: ${binary_path}${NC}" + echo -e "${CYAN}ℹ️ Starting program...${NC}" - # 直接运行程序 + # Run program directly "${binary_path}" else - echo -e "${RED}❌ 安裝失敗${NC}" + echo -e "${RED}❌ Installation failed${NC}" exit 1 fi } -# 主程序 +# Main program main() { print_logo get_latest_version @@ -149,5 +176,5 @@ main() { install_cursor_free_vip } -# 運行主程序 -main \ No newline at end of file +# Run main program +main