Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 28 additions & 8 deletions cursor_setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ readonly SCRIPT_ALIAS_NAME="cursor-setup"
readonly DOWNLOAD_DIR="$HOME/.AppImage"
readonly ICON_DIR="$HOME/.local/share/icons"
readonly USER_DESKTOP_FILE="$HOME/Desktop/cursor.desktop"
readonly DOWNLOAD_URL="https://downloader.cursor.sh/linux/appImage/x64"
readonly DOWNLOAD_URL="https://downloads.cursor.com/production/96e5b01ca25f8fbd4c4c10bc69b15f6228c80771/linux/x64/Cursor-0.50.5-x86_64.AppImage"
readonly ICON_URL="https://mintlify.s3-us-west-1.amazonaws.com/cursor/images/logo/app-logo.svg"
readonly VERSION_CHECK_TIMEOUT=5 # in seconds | if you have a slow connection, increase this value to 10, 15, or more
readonly VERSION_CHECK_TIMEOUT=360 # in seconds | if you have a slow connection, increase this value to 10, 15, or more
readonly SPINNERS=("meter" "line" "dot" "minidot" "jump" "pulse" "points" "globe" "moon" "monkey" "hamburger")
readonly SPINNER="${SPINNERS[0]}"
readonly DEPENDENCIES=("gum" "curl" "wget" "pv" "bc" "find:findutils" "chmod:coreutils" "timeout:coreutils" "mkdir:coreutils" "apparmor_parser:apparmor-utils")
Expand Down Expand Up @@ -126,8 +126,18 @@ edit_this_script() {
}

extract_version() {
[[ "$1" =~ ([0-9]+\.[0-9]+\.[0-9]+) ]] && { echo "${BASH_REMATCH[1]}"; return 0; }
echo "Error: No version found in filename" >&2; return 1
# Make this function more robust
if [[ "$1" =~ [Cc]ursor[-_]([0-9]+\.[0-9]+\.[0-9]+) ]]; then
echo "${BASH_REMATCH[1]}"
return 0
elif [[ "$1" =~ ([0-9]+\.[0-9]+\.[0-9]+) ]]; then
echo "${BASH_REMATCH[1]}"
return 0
else
# Default version from DOWNLOAD_URL if no version found
echo "0.50.5"
return 0
fi
}

convert_to_mb() { printf "%.2f MB" "$(bc <<< "scale=2; $1 / 1048576")"; }
Expand Down Expand Up @@ -176,22 +186,32 @@ fetch_remote_version() {
return 1
fi
logg success "Latest version details retrieved successfully."
remote_name=$(echo "$headers" | grep -oE 'filename="[^"]+"' | sed 's/filename=//g; s/\"//g') || remote_name=""

# Extract the filename from the download URL if headers don't have it
if [[ "$DOWNLOAD_URL" =~ /([^/]+)$ ]]; then
remote_name="${BASH_REMATCH[1]}"
else
remote_name=$(echo "$headers" | grep -oE 'filename="[^"]+"' | sed 's/filename=//g; s/\"//g') || remote_name=""
fi

remote_size=$(echo "$headers" | grep -oE 'Content-Length: [0-9]+' | sed 's/Content-Length: //') || remote_size="0"
remote_version=$(extract_version "$remote_name")
remote_md5=$(echo "$headers" | grep -oE 'ETag: "[^"]+"' | sed 's/ETag: //; s/"//g' || echo "unknown")

if [[ -z "$remote_name" ]]; then
logg error "Could not fetch the filename info. Please check that the 'DOWNLOAD_URL' variable is correct and try again."
return 1
logg error "Could not fetch the filename info. Using default from DOWNLOAD_URL."
remote_name=$(basename "$DOWNLOAD_URL")
remote_version=$(extract_version "$remote_name")
fi

logg info "$(echo -e "Latest version online:\n - name: $remote_name\n - version: $remote_version\n - size: $(convert_to_mb "$remote_size")\n - MD5 Hash: $remote_md5\n")"
}

find_local_version() {
show_log=${1:-false}
[[ $show_log == true ]] && spinner "Searching for a local version..." "sleep 2;"
mkdir -p "$DOWNLOAD_DIR"
local_path=$(find "$DOWNLOAD_DIR" -maxdepth 1 -type f -name 'cursor-*.AppImage' -printf '%T@ %p\n' 2>/dev/null | sort -nr | head -n 1 | cut -d' ' -f2-)
local_path=$(find "$DOWNLOAD_DIR" -maxdepth 1 -type f -name 'Cursor-*.AppImage' -printf '%T@ %p\n' 2>/dev/null | sort -nr | head -n 1 | cut -d' ' -f2-)
if [[ -n "$local_path" ]]; then
local_name=$(basename "$local_path")
local_size=$(stat -c %s "$local_path" 2>/dev/null || echo "0")
Expand Down