From 505aee4732698a40b474baf6778210700a2bbdc3 Mon Sep 17 00:00:00 2001 From: FelixHHS Date: Wed, 19 Mar 2025 10:31:46 +0800 Subject: [PATCH] Maintain the original coding structure. Update download_cursor function to dynamically download the latest Cursor version, update setup_cursor for dynamic file naming. --- shell/functions.sh | 36 ++++++++++++++++++++++++++++-------- shell/vars.sh | 4 +--- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/shell/functions.sh b/shell/functions.sh index ce94db6..292bff0 100755 --- a/shell/functions.sh +++ b/shell/functions.sh @@ -4,12 +4,23 @@ function download_cursor() { # Create the output directory if it doesn't exist mkdir -p "$OUTPUT_DIRECTORY" + # Get the download URL from the API + echo -e "🔍 ${CYAN}Fetching latest Cursor version...${NC}" + APPIMAGE_URL=$(curl -s "$URL_CURSOR_DOWN" | grep -o '"downloadUrl":"[^"]*"' | cut -d'"' -f4) + + # Extract the version from the URL + VERSION=$(echo "$APPIMAGE_URL" | grep -o 'Cursor-[0-9.]*' | cut -d'-' -f2) + + # Set file name and output file dynamically + FILE_NAME="cursor-${VERSION}-x86_64.AppImage" + OUTPUT_FILE="$OUTPUT_DIRECTORY/$FILE_NAME" + # Download cursor if it doesn't exist if [ -e "$OUTPUT_FILE" ]; then echo -e "${GREEN}✅ The file already exists: $OUTPUT_FILE${NC}" else - echo -e "↓ ${CYAN}Downloading cursor... ${DOWNLOAD_EMOJI}${NC}" - curl -o "$OUTPUT_FILE" "$URL_CURSOR_DOWN" + echo -e "↓ ${CYAN}Downloading Cursor version $VERSION... ${DOWNLOAD_EMOJI}${NC}" + wget -O "$OUTPUT_FILE" "$APPIMAGE_URL" if [ $? -eq 0 ]; then echo -e "${GREEN}✅ Download completed: $OUTPUT_FILE${NC}" else @@ -17,6 +28,10 @@ function download_cursor() { exit 1 fi fi + + # Export these variables so they're available to other functions + export FILE_NAME + export OUTPUT_FILE } @@ -38,20 +53,23 @@ function setup_cursor() { sudo chmod +x /opt/cursor/$FILE_NAME sudo chown $USER:$USER /opt/cursor if [ $? -eq 0 ]; then - echo -e "${GREEN}✅ Permissions granted successfully to /opt/cursor/cursor.AppImage${NC}" + echo -e "${GREEN}✅ Permissions granted successfully to /opt/cursor/$FILE_NAME${NC}" else echo -e "${RED}❌ Error granting permissions${NC}" exit 1 fi # Extract the appimage + echo -e "${CYAN}Extracting AppImage (this may take a moment)...${NC}" cd /opt/cursor && \ - sudo /opt/cursor/$FILE_NAME --appimage-extract && \ + sudo /opt/cursor/$FILE_NAME --appimage-extract > /dev/null 2>&1 && \ sudo chown -R $USER:$USER /opt/cursor/squashfs-root && \ sudo chown root:root /opt/cursor/squashfs-root/chrome-sandbox && \ - sudo chmod 4755 /opt/cursor/squashfs-root/chrome-sandbox + sudo chmod 4755 /opt/cursor/squashfs-root/chrome-sandbox && \ + sudo mv /opt/cursor/squashfs-root/AppRun /opt/cursor/squashfs-root/cursor export EXE_PATH="/opt/cursor/squashfs-root/cursor" cd $CURRENT_DIRECTORY - echo -e "${GREEN} Extracted cursor to: '${EXE_PATH}'${NC}" + echo -e "${GREEN}✅ Extracted cursor to: '${EXE_PATH}'${NC}" + echo -e "${GREEN}â„šī¸ All extracted content is located in: /opt/cursor/squashfs-root/${NC}" # Create .desktop file sudo tee "$DESKTOP_FILE" > /dev/null < /dev/null < /dev/null 2>&1 && \ sudo chown $USER:$USER \$APPDIR/squashfs-root && \ sudo chown root:root \$APPDIR/squashfs-root/chrome-sandbox && \ sudo chmod 4755 \$APPDIR/squashfs-root/chrome-sandbox && \ @@ -115,6 +134,7 @@ cd \$APPDIR && sudo "\$APPDIR/cursor-\${VERSION}-x86_64.AppImage" --appimage-ext cd - echo "Cursor has been updated to version \$VERSION" +echo "All extracted content is located in: \$APPDIR/squashfs-root/" EOF # permissions to script execution diff --git a/shell/vars.sh b/shell/vars.sh index 1ab3f24..f168f07 100755 --- a/shell/vars.sh +++ b/shell/vars.sh @@ -12,6 +12,4 @@ readonly DOWNLOAD_EMOJI='\U1F4E2' # Unicode character for a download emoji # vars readonly OUTPUT_DIRECTORY=~/Cursor -readonly FILE_NAME=cursor-0.40.3x86_64.AppImage -readonly OUTPUT_FILE=$OUTPUT_DIRECTORY/$FILE_NAME -readonly URL_CURSOR_DOWN="https://downloader.cursor.sh/linux/appImage/x64" +readonly URL_CURSOR_DOWN="https://www.cursor.com/api/download?platform=linux-x64&releaseTrack=stable"