| 1 | #!/bin/bash␊ |
| 2 | ␊ |
| 3 | echo "==============================================="␊ |
| 4 | echo "Check the Partition Scheme: GPT, GPT/MBR or MBR?"␊ |
| 5 | echo "************************************************"␊ |
| 6 | ␊ |
| 7 | # Looks for the first 8 bytes of the GPTdiskGPTHeader to identify a GUID partition table.␊ |
| 8 | # Byte number 450 of the GPTdiskProtectiveMBR to identify ID of 'EE' to identify a GPT partition.␊ |
| 9 | # Byte numbers 466, 482 & 498 of the GPTdiskProtectiveMBR to identify further partitions.␊ |
| 10 | #␊ |
| 11 | # Exit with value 1 for GPT, 2 for GPT/MBR and 3 for MBR. ␊ |
| 12 | # Exit with value 0 if nothing is found - this shouldn't happen.?␊ |
| 13 | ␊ |
| 14 | # Receives targetDisk: for example, /dev/disk0s2␊ |
| 15 | # Receives targetVolume: Volume to install to.␊ |
| 16 | # Receives scriptDir: The location of the main script dir.␊ |
| 17 | ␊ |
| 18 | ␊ |
| 19 | if [ "$#" -eq 3 ]; then␊ |
| 20 | ␉targetDisk="$1"␊ |
| 21 | ␉targetVolume="$2"␊ |
| 22 | ␉scriptDir="$3"␊ |
| 23 | ␉echo "DEBUG: passed argument = $targetDisk"␊ |
| 24 | ␉echo "DEBUG: passed argument for targetVolume = $targetVolume"␊ |
| 25 | ␉echo "DEBUG: passed argument for scriptDir = $scriptDir"␊ |
| 26 | else␊ |
| 27 | ␉echo "Error - wrong number of values passed"␊ |
| 28 | ␉exit 9␊ |
| 29 | fi␊ |
| 30 | ␊ |
| 31 | ␊ |
| 32 | partitiontable=$( dd 2>/dev/null if="$targetDisk" count=1 skip=1 | dd 2>/dev/null count=8 bs=1 | perl -ne '@a=split"";for(@a){printf"%02x",ord}' )␊ |
| 33 | if [ "${partitiontable:0:16}" == "4546492050415254" ]; then␉␊ |
| 34 | ␉partitiontable=$( dd 2>/dev/null if="$targetDisk" count=1 | dd 2>/dev/null count=64 bs=1 skip=446 | perl -ne '@a=split"";for(@a){printf"%02x",ord}' )␊ |
| 35 | ␊ |
| 36 | ␉if [ "${partitiontable:8:2}" == "ee" ]; then␊ |
| 37 | ␉␉echo "Found System ID 'EE' to identify GPT Partition"␊ |
| 38 | ␊ |
| 39 | ␉␉if [ "${partitiontable:40:2}" == "00" ] && [ "${partitiontable:72:2}" == "00" ] && [ "${partitiontable:104:2}" == "00" ]; then␊ |
| 40 | ␉␉␉echo "Found System ID '00' for each remaining possible partition"␊ |
| 41 | ␉␉␉partitiontable="GPT"␊ |
| 42 | ␉␉␉echo "${partitiontable} found."␊ |
| 43 | ␉␉␉echo "-----------------------------------------------"␊ |
| 44 | ␉␉␉echo ""␊ |
| 45 | ␉␉␉#"$scriptDir"InstallLog.sh "${targetVolume}" "${targetDisk} is using a GPT."␊ |
| 46 | ␉␉␉exit 1␊ |
| 47 | ␉ ␉else␊ |
| 48 | ␉␉␉partitiontable="GPT/MBR"␊ |
| 49 | ␉␉␉echo "${partitiontable} found."␊ |
| 50 | ␉␉␉echo "-----------------------------------------------"␊ |
| 51 | ␉␉␉echo ""␊ |
| 52 | ␉␉␉#"$scriptDir"InstallLog.sh "${targetVolume}" "${targetDisk} is using a GPT/MBR."␊ |
| 53 | ␉␉␉exit 2␊ |
| 54 | ␉␉fi␊ |
| 55 | ␉fi␊ |
| 56 | else␊ |
| 57 | ␉partitiontable="MBR"␊ |
| 58 | ␉echo "${partitiontable} found."␊ |
| 59 | ␉echo "-----------------------------------------------"␊ |
| 60 | ␉echo ""␊ |
| 61 | ␉#"$scriptDir"InstallLog.sh "${targetVolume}" "${targetDisk} is using MBR."␊ |
| 62 | ␉exit 3␊ |
| 63 | fi␊ |
| 64 | ␊ |
| 65 | echo "No partition table found."␊ |
| 66 | echo "-----------------------------------------------"␊ |
| 67 | echo ""␊ |
| 68 | ␊ |
| 69 | "$scriptDir"InstallLog.sh "${targetVolume}" "NOTE: No partition table found."␊ |
| 70 | ␊ |
| 71 | exit 0 |