Update documentation with comprehensive usage guide and improved update script

This commit is contained in:
thinktankmachine
2025-08-06 15:38:06 +10:00
parent 9d0bcd6aed
commit 035a280383
2 changed files with 392 additions and 122 deletions
+133 -18
View File
@@ -1,32 +1,147 @@
#!/usr/bin/env bash
# Script to update the SHA256 hash for Cursor AppImage
# Run this script to get the correct hash and update home.nix
# This script helps you update the Cursor version and hash in the flake
set -e
echo "Fetching SHA256 hash for Cursor 1.3.9 AppImage..."
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Function to print colored output
print_info() {
echo -e "${BLUE}[INFO]${NC} $1"
}
print_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Check if we're in the right directory
if [[ ! -f "home.nix" ]]; then
print_error "This script must be run from the cursor-flake directory"
exit 1
fi
print_info "Cursor AppImage Hash Updater"
echo ""
# Get current URL from home.nix
CURRENT_URL=$(grep -o 'https://downloads\.cursor\.com/[^"]*' home.nix | head -1)
if [[ -z "$CURRENT_URL" ]]; then
print_error "Could not find Cursor download URL in home.nix"
exit 1
fi
print_info "Current URL: $CURRENT_URL"
# Extract version from URL
CURRENT_VERSION=$(echo "$CURRENT_URL" | grep -o 'Cursor-[0-9]\+\.[0-9]\+\.[0-9]\+' | head -1 | sed 's/Cursor-//')
if [[ -z "$CURRENT_VERSION" ]]; then
print_warning "Could not extract version from URL, using 'unknown'"
CURRENT_VERSION="unknown"
fi
print_info "Current version: $CURRENT_VERSION"
echo ""
# Ask user if they want to update to a new version
read -p "Do you want to update to a new version? (y/N): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo ""
print_info "To update to a new version:"
echo "1. Go to https://cursor.sh/"
echo "2. Download the Linux AppImage"
echo "3. Copy the download URL"
echo "4. Paste it below"
echo ""
read -p "Enter the new Cursor download URL: " NEW_URL
if [[ -z "$NEW_URL" ]]; then
print_error "No URL provided"
exit 1
fi
# Extract new version
NEW_VERSION=$(echo "$NEW_URL" | grep -o 'Cursor-[0-9]\+\.[0-9]\+\.[0-9]\+' | head -1 | sed 's/Cursor-//')
if [[ -z "$NEW_VERSION" ]]; then
print_warning "Could not extract version from new URL"
NEW_VERSION="unknown"
fi
print_info "New version: $NEW_VERSION"
# Update the URL in home.nix
sed -i "s|$CURRENT_URL|$NEW_URL|g" home.nix
print_success "Updated URL in home.nix"
URL_TO_HASH="$NEW_URL"
else
URL_TO_HASH="$CURRENT_URL"
fi
echo ""
print_info "Fetching SHA256 hash for AppImage..."
echo "URL: $URL_TO_HASH"
echo ""
# Get the hash
HASH=$(nix-prefetch-url https://downloads.cursor.com/production/54c27320fab08c9f5dd5873f07fca101f7a3e076/linux/x64/Cursor-1.3.9-x86_64.AppImage)
print_info "Downloading and computing hash (this may take a moment)..."
HASH=$(nix-prefetch-url "$URL_TO_HASH")
if [[ -z "$HASH" ]]; then
print_error "Failed to get hash"
exit 1
fi
echo "SHA256 hash: $HASH"
echo ""
echo "Please update the hash in home.nix:"
echo "Replace the placeholder hash with:"
echo "sha256 = \"$HASH\";"
echo ""
echo "You can do this manually or run:"
echo "sed -i 's/sha256 = \"sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=\";/sha256 = \"$HASH\";/' home.nix"
print_success "SHA256 hash: $HASH"
echo ""
# Optionally update the file automatically
read -p "Do you want to update home.nix automatically? (y/N): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
sed -i "s/sha256 = \"sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=\";/sha256 = \"$HASH\";/" home.nix
echo "Updated home.nix with the correct hash!"
# Find the current hash in home.nix
CURRENT_HASH=$(grep -o 'sha256 = "[^"]*"' home.nix | head -1 | sed 's/sha256 = "//;s/"//')
if [[ -z "$CURRENT_HASH" ]]; then
print_warning "Could not find current hash in home.nix"
print_info "Please manually update the hash in home.nix:"
echo "sha256 = \"$HASH\";"
else
echo "Please update home.nix manually with the hash above."
fi
print_info "Current hash: $CURRENT_HASH"
print_info "New hash: $HASH"
echo ""
if [[ "$CURRENT_HASH" == "$HASH" ]]; then
print_success "Hash is already up to date!"
else
# Update the hash in home.nix
sed -i "s/sha256 = \"$CURRENT_HASH\";/sha256 = \"$HASH\";/" home.nix
print_success "Updated hash in home.nix"
fi
fi
echo ""
print_info "Next steps:"
echo "1. Test the build: nix build .#packages.x86_64-linux.cursor"
echo "2. Update your system: sudo nixos-rebuild switch --flake .#your-system"
echo "3. Test Cursor: cursor --version"
echo ""
print_success "Hash update complete!"