KC9UZR

Automatic Linux Install rEFInd

Aug 18th, 2025
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.67 KB | Software | 0 0
  1. #!/bin/bash
  2.  
  3. # A script to automate the download and installation of rEFInd on Linux.
  4. # This script must be run with sudo or as root.
  5. #
  6. # MODIFICATION 2: Corrected the flag for specifying the EFI partition.
  7. # The correct flag is "--usedefault {device}" not "--device {device}".
  8.  
  9. # --- Configuration ---
  10. REFIND_VERSION="0.14.2"
  11. DOWNLOAD_URL="https://sourceforge.net/projects/refind/files/${REFIND_VERSION}/refind-bin-${REFIND_VERSION}.zip/download"
  12. TEMP_DIR="/tmp/refind-install-$$"
  13. EFI_DEVICE="/dev/sda1" # Your confirmed EFI partition
  14.  
  15. # --- Functions ---
  16.  
  17. # Function to check for root privileges
  18. check_root() {
  19.     if [ "$EUID" -ne 0 ]; then
  20.         echo "Error: This script must be run as root. Please use sudo."
  21.         exit 1
  22.     fi
  23. }
  24.  
  25. # Function to check for UEFI boot mode
  26. check_uefi() {
  27.     if [ ! -d "/sys/firmware/efi" ]; then
  28.         echo "Error: System not booted in UEFI mode. rEFInd requires UEFI."
  29.         exit 1
  30.     fi
  31. }
  32.  
  33. # Function for cleanup
  34. cleanup() {
  35.     echo "Cleaning up temporary files..."
  36.     rm -rf "$TEMP_DIR"
  37. }
  38.  
  39. # --- Main Script Logic ---
  40.  
  41. # Ensure script exits if any command fails
  42. set -e
  43.  
  44. # Trap CTRL+C and other signals for cleanup
  45. trap cleanup EXIT
  46.  
  47. # 1. Initial Checks
  48. check_root
  49. check_uefi
  50.  
  51. echo "rEFInd Installer for Linux (Acer Specific - Corrected)"
  52. echo "----------------------------------------------------"
  53. echo "Targeting EFI Partition: $EFI_DEVICE"
  54.  
  55. # 2. Check/Install Dependencies
  56. if ! command -v curl &> /dev/null || ! command -v unzip &> /dev/null; then
  57.     echo "curl and/or unzip not found. Attempting to install..."
  58.     if command -v apt-get &> /dev/null; then
  59.         apt-get update
  60.         apt-get install -y curl unzip
  61.     else
  62.         echo "Error: Cannot automatically install dependencies. Please install curl and unzip manually."
  63.         exit 1
  64.     fi
  65. fi
  66.  
  67. # 3. Download and Extract rEFInd
  68. mkdir -p "$TEMP_DIR"
  69. cd "$TEMP_DIR"
  70.  
  71. echo "Downloading rEFInd version $REFIND_VERSION..."
  72. curl -L -o refind.zip "$DOWNLOAD_URL"
  73. echo "Extracting archive..."
  74. unzip -q refind.zip
  75.  
  76. # Find the extracted directory name
  77. EXTRACTED_DIR=$(ls -d refind-bin-*/)
  78.  
  79. # 4. Run the official rEFInd installation script
  80. cd "$EXTRACTED_DIR"
  81. echo "Running the official refind-install script on $EFI_DEVICE..."
  82.  
  83. # THIS IS THE CORRECTED COMMAND:
  84. ./refind-install --usedefault $EFI_DEVICE
  85.  
  86. if [ $? -eq 0 ]; then
  87.     echo ""
  88.     echo -e "\e[32m rEFInd has been installed successfully! \e[0m"
  89.     echo "On next boot, rEFInd should appear as the default boot manager."
  90. else
  91.     echo ""
  92.     echo -e "\e[31m The refind-install script reported an error. \e[0m"
  93. fi
  94.  
  95. # Cleanup is handled by the trap at the beginning
  96.  
  97. exit 0
Advertisement
Add Comment
Please, Sign In to add comment