Advertisement
mac_editor

automate-eGPU-EFI-Installer.sh

Jan 30th, 2019
1,604
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 4.83 KB | None | 0 0
  1. #!/usr/bin/env bash
  2. # Author: Mayank Kumar (@mac_editor on egpu.io)
  3. # Format an external disk and install automate-eGPU-EFI (v1.0.5)
  4.  
  5. clear
  6.  
  7. # Text configuration
  8. shopt -s nocasematch
  9. bold="$(tput bold)"
  10. normal="$(tput sgr0)"
  11.  
  12. # Environment
  13. pb="/usr/libexec/PlistBuddy"
  14. disk_plist=".disks.plist"
  15. partition_names=()
  16. partition_ids=()
  17.  
  18. echo -e ">> ${bold}Automate eGPU EFI 1.0.5 Installer${normal}\n"
  19.  
  20. # Phase 1: Disk Management
  21. echo -e "> ${bold}Phase 1${normal}: Disk Management\n"
  22. diskutil list -plist external > "${disk_plist}"
  23. whole_disk_count=$($pb -c "Print :WholeDisks" "${disk_plist}" | sed -e 1d -e '$d' | wc -w)
  24. if (( $whole_disk_count == 0 ))
  25. then
  26.   echo -e "No external disks detected. Please connect an external disk."
  27.   echo -e "Internal disks are not supported for safety reasons.\n"
  28.   rm "${disk_plist}"
  29.   exit
  30. fi
  31. for (( i = 0; i < ${whole_disk_count}; i++ ))
  32. do
  33.   base_cmd="Print :AllDisksAndPartitions:${i}:Partitions"
  34.   partition_count=$($pb -c "${base_cmd}" "${disk_plist}" | sed -e 1d -e '$d' | grep -o -i "Dict" | wc -l)
  35.   for (( j = 0; j < ${partition_count}; j++ ))
  36.   do
  37.     partition_content="$($pb -c "${base_cmd}:${j}:Content" "${disk_plist}")"
  38.     if [[ "${partition_content}" == "EFI" ]]
  39.     then
  40.       continue
  41.     fi
  42.     partition_name="$($pb -c "${base_cmd}:${j}:VolumeName" "${disk_plist}")"
  43.     partition_id="$($pb -c "${base_cmd}:${j}:DeviceIdentifier" "${disk_plist}")"
  44.     partition_names+=("${partition_name}")
  45.     partition_ids+=("${partition_id}")
  46.   done
  47. done
  48. for (( i = 0; i < ${#partition_names[@]}; i++ ))
  49. do
  50.   disk_no=$(( $i + 1 ))
  51.   echo -e "  ${bold}${disk_no}${normal}. ${partition_names[$i]}"
  52. done
  53. echo -e "\n  ${bold}0${normal}. Quit"
  54. echo -e "\nChoose a disk to format. All data on that disk will be lost.\n"
  55. input=""
  56. read -n1 -p "${bold}Disk #${normal}: " input
  57. echo
  58. if [[ -z "${input}" ]] || (( $input < 1 || $input > ${#partition_names[@]} ))
  59. then
  60.   echo -e "\nAborting.\n"
  61.   rm ${disk_plist}
  62.   exit
  63. fi
  64. input=$(( $input - 1 ))
  65. echo -e "\n${bold}Selected Disk${normal}: ${partition_names[${input}]} (/dev/${partition_ids[${input}]})"
  66. echo -e "\nIf you proceed, the selected disk will be erased.\n"
  67. proceed="N"
  68. read -n1 -p "${bold}Proceed?${normal} [Y/N]: " proceed
  69. echo
  70. if [[ "${proceed}" != "Y" ]]
  71. then
  72.   echo -e "\nAborting.\n"
  73.   exit
  74. fi
  75. echo -e "\n${bold}Erasing disk...${normal}"
  76. diskutil eraseVolume FAT32 EGPUBOOT "${partition_ids[${input}]}" 2>/dev/null 1>/dev/null
  77. target_dir="/Volumes/EGPUBOOT"
  78. if [[ ! -e "${target_dir}" ]]
  79. then
  80.   echo -e "Erasure failed. Aborting.\n"
  81.   exit
  82. fi
  83. echo -e "Disk erased.\n"
  84. rm .disks.plist
  85.  
  86. # Phase 2: Disk Management
  87. echo -e "> ${bold}Phase 2${normal}: EFI Installation\n"
  88. echo -e "${bold}Retrieving...${normal}"
  89. curl -L -s -o "${target_dir}/EFI.zip" "https://egpu.io/wp-content/uploads/2018/10/EFI.zip"
  90. exp_integrity="75cea4616bc74d2fab8179251ec15f6e773dc4cc9f7f858d4cdb473db241797131e40a5bce1114f214ef4b98cc731d9e2e5600338189916cbac2dd40c277b869"
  91. file_integrity=$(shasum -a 512 -b "${target_dir}/EFI.zip" | awk '{ print $1 }')
  92. if [[ "${file_integrity}" != "${exp_integrity}" ]]
  93. then
  94.   echo -e "Download failed or invalid file.\n"
  95.   rm "${target_dir}/EFI.zip"
  96.   exit
  97. fi
  98. echo "Files retrieved."
  99. echo "${bold}Setting up disk...${normal}"
  100. unzip -d "${target_dir}" "${target_dir}/EFI.zip" 1>/dev/null 2>&1
  101. rm "${target_dir}/EFI.zip"
  102. if [[ ! -d "${target_dir}/EFI" ]]
  103. then
  104.   echo -e "Unable to set up disk. Aborting.\n"
  105.   exit
  106. fi
  107. rm -rf "${target_dir}/__MACOSX"
  108. echo -e "Setup complete.\n"
  109.  
  110. # Phase 3: Patch Selection
  111. echo -e "> ${bold}Phase 3${normal}: Patch Selection\n"
  112. tb_type="$(ioreg | grep AppleThunderboltNHIType)"
  113. tb_type="${tb_type##*+-o AppleThunderboltNHIType}"
  114. tb_type="${tb_type::1}"
  115. echo -e "Specify which eGPU vendor you are using for optimized patches.\n"
  116. echo -e "${bold}1${normal}. NVIDIA\n${bold}2${normal}. AMD\n"
  117. read -n1 -p "${bold}Vendor${normal}: " input
  118. echo
  119. if [[ -z "${input}" ]] || (( $input < 1 || $input > 2 ))
  120. then
  121.   echo -e "\nInvalid input. Aborting.\n"
  122.   exit
  123. fi
  124. if (( $input == 1 ))
  125. then
  126.   echo -e "\n${bold}EFI ready to go.${normal}\n"
  127.   exit
  128. fi
  129. echo -e "\n${bold}Updating configuration...${normal}"
  130. config_plist="${target_dir}/EFI/CLOVER/config.plist"
  131. $pb -c "Delete :KernelAndKextPatches:KextsToPatch:0" "${config_plist}"
  132. $pb -c "Set :KernelAndKextPatches:KextsToPatch:0:Comment \"AppleGPUWrangler Thunderbolt Patch © egpu.io [mac_editor]\"" "${config_plist}"
  133. patch_data_find="IOThunderboltSwitchType3"
  134. patch_data_replace="IOThunderboltSwitchType${tb_type}"
  135. $pb -c "Set :KernelAndKextPatches:KextsToPatch:0:Find ${patch_data_find}" "${config_plist}"
  136. $pb -c "Set :KernelAndKextPatches:KextsToPatch:0:Replace ${patch_data_replace}" "${config_plist}"
  137. $pb -c "Delete :SystemParameters:NvidiaWeb" "${config_plist}"
  138. echo "Configuration updated."
  139. echo -e "\n${bold}EFI ready to go.${normal}\n"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement