Update install.sh

This commit is contained in:
Pin Studios 2025-02-26 22:34:38 +08:00 committed by GitHub
parent 040c5f5836
commit 2bca7d7d14
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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}"
# 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}✅ 文件存在,开始下载...${NC}"
echo -e "${GREEN}File exists, starting download...${NC}"
else
echo -e "${RED}❌ 下载链接不存在: ${download_url}${NC}"
echo -e "${YELLOW}⚠️ 尝试不带架构的版本...${NC}"
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
}
# 運行主程序
# Run main program
main