#!/bin/bash
set -e

echo "Downloading rsync universal binary..."
curl -L -o rsync_universal https://ripperdoc.de/rsync_universal
echo "Downloading rsync autobackup script(use very carefully)"
curl -L -o autobackup.sh https://ripperdoc.de/autobackup.sh
chmod +x autobackup.sh

chmod +x rsync_universal
printf "\nrsync_universal downloaded and ready.\n\n"

printf "To back up a user folder from macOS Recovery:\n"
printf "  rsync_universal -aEHX --progress --exclude 'Library/'  /Volumes/\033[1;36mMacintosh HD - Data\033[0m/Users/\033[1;36myourusername\033[0m/ /Volumes/\033[1;36mBackupDrive\033[0m/UserBackup\n\n"

printf "Replace \033[1;36myourusername\033[0m with the actual user folder name.\n"
printf "correct /Volumes/\033[1;36mMacintosh HD - Data\033[0m/ if necessary.\n\n"
printf "Available user folders, example:\n"
printf "ls \"/Volumes/Macintosh HD - Data/Users\"" 
printf "\n"

printf "Replace \033[1;36mBackupDrive\033[0m with the name of your mounted external disk.\n\n"

printf "Options:\n"
printf "  -a   archive mode (preserves structure/metadata)\n"
printf "  -E   preserve extended attributes (macOS metadata)\n"
printf "  -H   preserve hard links\n"
printf "  -X   preserve ACLs\n"
printf "  --progress   show file transfer progress\n"
printf "  --exclude 'Library/'   skip user Library folder\n\n"

printf "To format the external drive (choose one):\n"
printf "  diskutil eraseDisk HFS+ \033[1;36mBackupDrive\033[0m \033[1;36m/dev/diskX\033[0m     # for HFS+\n"
printf "  diskutil eraseDisk APFS \033[1;36mBackupDrive\033[0m \033[1;36m/dev/diskX\033[0m     # for APFS (better for SSDs)\n\n"

printf "Use 'diskutil list' to find the correct \033[1;36m/dev/diskX\033[0m identifier.\n"