1 | #!/bin/bash␊ |
2 | ␊ |
3 | echo "==============================================="␊ |
4 | echo "Check Proceed: Can the installation continue?"␊ |
5 | echo "***********************************************"␊ |
6 | ␊ |
7 | # Checks the selected volume is present and the disk is partitioned␊ |
8 | # Now also check for another existing Chameleon installation on the same disk.␊ |
9 | ␊ |
10 | # Receives targetDisk: for example, /dev/disk3.␊ |
11 | # Receives targetDeviceRaw: for example, /dev/rdisk3s1.␊ |
12 | # Receives targetVolume: Volume to install to (will be '/Volumes/EFI' if EFI install)␊ |
13 | # Receives targetDevice: Stores device number, for example /dev/disk2s1.␊ |
14 | # Receives installerVolume: Volume to write the installer log to.␊ |
15 | # Receives scriptDir: The location of the main script dir.␊ |
16 | ␊ |
17 | if [ "$#" -eq 6 ]; then␊ |
18 | ␉targetDisk="$1"␊ |
19 | ␉targetDeviceRaw="$2"␊ |
20 | ␉targetVolume="$3"␊ |
21 | ␉targetDevice="$4"␊ |
22 | ␉installerVolume="$5"␊ |
23 | ␉scriptDir="$6"␊ |
24 | ␉echo "DEBUG: passed argument for targetDisk = $targetDisk"␊ |
25 | ␉echo "DEBUG: passed argument for targetDeviceRaw = $targetDeviceRaw"␊ |
26 | ␉echo "DEBUG: passed argument for targetVolume = $targetVolume"␊ |
27 | ␉echo "DEBUG: passed argument for targetDevice = $targetDevice"␊ |
28 | ␉echo "DEBUG: passed argument for installerVolume = $installerVolume"␊ |
29 | ␉echo "DEBUG: passed argument for scriptDir = $scriptDir"␊ |
30 | else␊ |
31 | ␉echo "Error - wrong number of values passed"␊ |
32 | ␉exit 9␊ |
33 | fi␊ |
34 | ␊ |
35 | ␊ |
36 | # Does target volume exist?␊ |
37 | if [ -z "$targetVolume" ]; then␊ |
38 | ␉echo "*** Cannot find the volume. Exiting."␊ |
39 | ␉"$scriptDir"InstallLog.sh "${installerVolume}" "FAIL: Cannot file the volume: $targetVolume."␊ |
40 | ␉exit 1␊ |
41 | #else␊ |
42 | ␉#echo "DEBUG: Confirming target volume exists"␊ |
43 | fi␊ |
44 | ␊ |
45 | ␊ |
46 | # Does target volume use slices?␊ |
47 | if [ "$targetDevice" = "$targetDevice#*disk*s" ]; then␊ |
48 | ␉echo "*** ERROR Volume does not use slices. Exiting."␊ |
49 | ␉"$scriptDir"InstallLog.sh "${installerVolume}" "FAIL: $targetVolume doesn't use slices."␊ |
50 | ␉exit 1␉␉␊ |
51 | #else␊ |
52 | ␉#echo "DEBUG: Confirming target device uses slices"␊ |
53 | fi␊ |
54 | ␊ |
55 | ␊ |
56 | # Add check for installing to a 'small' HFS device like a␊ |
57 | # 1GB USB flash drive which won't have an EFI System Partition.␊ |
58 | if [ "$targetVolume" = "/Volumes/EFI" ]; then␊ |
59 | ␉# Take target device and check slice 1 matches partition named "EFI"␊ |
60 | ␉stripped=$( echo ${targetDevice#/dev/} )␊ |
61 | ␉if [ ! $(echo ${stripped#*disk*s}) = 1 ]; then␊ |
62 | ␉␉stripped=$( echo ${stripped%s*})"s1"␊ |
63 | ␉fi␊ |
64 | ␉if [ ! $( diskutil list | grep ${stripped} | awk {'print $2'} ) = "EFI" ]; then␊ |
65 | ␉␉#echo "DEBUG: *** The selected volume doesn't have an EFI System Partition. Exiting."␊ |
66 | ␉␉"$scriptDir"InstallLog.sh "${installerVolume}" "FAIL: Selected disk does not have an EFI System Partition."␊ |
67 | ␉␉exit 1␊ |
68 | ␉fi␊ |
69 | fi␊ |
70 | ␊ |
71 | ␊ |
72 | # Check for existing Chameleon installations on a different␊ |
73 | # partition of the same target disk.␊ |
74 | #echo "DEBUG: Checking for existing Chameleon installations on ${targetDisk#/dev/}..."␊ |
75 | ␊ |
76 | sliceNumber=$( echo ${targetDeviceRaw#*disk*s} )␊ |
77 | # strip slice from end␊ |
78 | targetDiskRawNoSlice=$( echo ${targetDeviceRaw%$sliceNumber} )␊ |
79 | ␊ |
80 | # Are there any other partitions on the disk?␊ |
81 | # How many actual partitions are there?␊ |
82 | numSlices=$(( $( diskutil list | grep $( echo ${targetDisk#/dev/} ) | sed -n '$=' ) -2 ))␊ |
83 | ␊ |
84 | # Only check the disk for Chameleon installations if there is more than one partition.␊ |
85 | if [ $numSlices -gt 1 ]; then ␊ |
86 | ␉␉␊ |
87 | ␉#Scan all partitions for Chameleon code␊ |
88 | ␉for (( i=1; i <= $numSlices; i++ ));␊ |
89 | ␉do␊ |
90 | ␉␉stageExistence=0␊ |
91 | ␉␉targetDiskRaw=$targetDiskRawNoSlice$i␊ |
92 | ␊ |
93 | ␉␉# Check for existing stage 0 boot file from CheckDiskMicrocode.sh script␊ |
94 | ␉␉stage0type=$( dd 2>/dev/null if="$targetDisk" count=3 bs=1 skip=105 | xxd | awk '{print $2$3}' )␊ |
95 | ␉␉if [ "${stage0type}" == "0b807c" ] || [ "${stage0type}" == "0a803c" ] || [ "${stage0type}" == "ee7505" ]; then␊ |
96 | ␉␉␉#echo "DEBUG: boot0 found on $targetDisk"␊ |
97 | ␉␉␉(( stageExistence++ ))␊ |
98 | ␉␉fi␊ |
99 | ␉␉␉␊ |
100 | ␉␉# Check for boot1h and boot1f32␊ |
101 | ␉␉boot1hSearch=$( dd 2>/dev/null if="$targetDiskRaw" count=1 | perl -ne '@a=split"";for(@a){printf"%02x",ord}' )␊ |
102 | ␉␉if [ "${boot1hSearch:0:16}" == "fa31c08ed0bcf0ff" ]; then␊ |
103 | ␉␉␉#echo "DEBUG: boot1h found on "$targetDiskRaw␊ |
104 | ␉␉␉(( stageExistence++ ))␊ |
105 | ␉␉elif [ "${boot1hSearch:0:4}" == "e962" ] && [ "${boot1hSearch:180:12}" == "424f4f542020" ]; then␊ |
106 | ␉␉␉#echo "DEBUG: boot1f32 found on "$targetDiskRaw␊ |
107 | ␉␉␉(( stageExistence++ ))␊ |
108 | ␉␉fi␊ |
109 | ␉␉␊ |
110 | ␉␉# Check for existing stage 2 boot file also␊ |
111 | ␉␉if [ -e "$( df | grep $targetDisk"s"$i | awk '{ print $6 }' )"/boot ]; then␊ |
112 | ␉␉␉#echo "DEBUG: boot found on $targetDiskRaw"␊ |
113 | ␉␉␉(( stageExistence++ ))␊ |
114 | ␉␉fi␊ |
115 | ␉␉␊ |
116 | ␉␉if [ $stageExistence == 3 ] && [ $i -ne $sliceNumber ]; then␊ |
117 | ␉␉␉#echo "DEBUG: STOP: There is already an existing Chameleon installation on $targetDiskRaw"␊ |
118 | ␉␉␉"$scriptDir"InstallLog.sh "${installerVolume}" "STOP: There is already an existing Chameleon installation on $targetDiskRaw."␊ |
119 | ␉␉␉"$scriptDir"InstallLog.sh "${installerVolume}" "STOP: You could continue to install to $targetDeviceRaw, but you will have to"␊ |
120 | ␉␉␉"$scriptDir"InstallLog.sh "${installerVolume}" "STOP: control which partition is loaded by flagging the required partition active."␊ |
121 | ␉␉␉"$scriptDir"InstallLog.sh "${installerVolume}" "STOP: For now, please proceed by installing Chameleon manually."␊ |
122 | ␉␉␉exit 1␊ |
123 | ␉␉fi␊ |
124 | ␉done␊ |
125 | ␊ |
126 | #else␊ |
127 | ␉#echo "DEBUG: Just one slice"␊ |
128 | fi␊ |
129 | ␊ |
130 | #"$scriptDir"InstallLog.sh "${installerVolume}" "CheckProceed: PASS"␊ |
131 | ␊ |
132 | exit 0 |