1 | #!/bin/bash␊ |
2 | ␊ |
3 | echo "==============================================="␊ |
4 | echo "Main EFI System Partition Post-Install Script"␊ |
5 | echo "*********************************************"␊ |
6 | echo "-----------------------------------------------"␊ |
7 | echo ""␊ |
8 | ␊ |
9 | # Find location of this script in the package installer␊ |
10 | # so we know where all the other scripts are located.␊ |
11 | MYLOCATION="${PWD}/${BASH_ARGV[0]}"␊ |
12 | export MYLOCATION="${MYLOCATION%/*}"␊ |
13 | scriptDir=$MYLOCATION␊ |
14 | ␊ |
15 | ␊ |
16 | #echo "==============================================="␊ |
17 | #echo "Apple Installer Package Variables"␊ |
18 | #echo "*********************************"␊ |
19 | #echo "DEBUG: $ 1 = Full path to the installation package the installer app is processing: " $1␊ |
20 | #echo "DEBUG: $ 2 = Full path to the installation destination: " $2␊ |
21 | #echo "DEBUG: $ 3 = Installation volume (mountpoint) to receive the payload: " $3␊ |
22 | #echo "DEBUG: $ 4 = Root directory for the system: " $4␊ |
23 | #echo "DEBUG: Script Name: " $SCRIPT_NAME␊ |
24 | #echo "DEBUG: Package Path: " $PACKAGE_PATH␊ |
25 | #echo "DEBUG: Installer Temp: " $INSTALLER_TEMP␊ |
26 | #echo "DEBUG: Full path to the temp directory containing the operation executable: " $RECEIPT_PATH␊ |
27 | #echo "-----------------------------------------------"␊ |
28 | #echo ""␊ |
29 | ␊ |
30 | ␊ |
31 | # Initialise Script Globals␊ |
32 | ␊ |
33 | stage0Loader="boot0" #diskloader␊ |
34 | stage0LoaderDualBoot="boot0hfs" #was stage0Loaderdualboot␊ |
35 | stage1LoaderHFS="boot1h" #was stage1LoaderHFS␊ |
36 | stage1LoaderFAT="boot1f32" #was partitionloaderfat␊ |
37 | stage2Loader="boot" #was filesystemloader␊ |
38 | ␊ |
39 | targetVolumeTemp=$3 #was bootvolume␊ |
40 | targetDeviceTemp=$( df "${targetVolumeTemp}" | sed -n '2p' | awk '{print $1}' ) #was bootdev␊ |
41 | ␊ |
42 | targetVolume="/Volumes/EFI"␊ |
43 | targetDevice=${targetDeviceTemp%s*}s1␊ |
44 | targetDeviceRaw=${targetDevice/disk/rdisk} #was bootrdev␊ |
45 | targetDisk=${targetDevice%s*} #was bootdisk␊ |
46 | targetDiskRaw=${targetDisk/disk/rdisk} #was bootrdisk␊ |
47 | targetSlice=${targetDevice#*disk*s} #was bootslice␊ |
48 | targetResources="${targetVolume%/*}" #was bootresources - is this needed?␊ |
49 | ␊ |
50 | ␊ |
51 | ␊ |
52 | echo "==============================================="␊ |
53 | echo "DEBUG: display script variables"␊ |
54 | echo "***************************"␊ |
55 | ␊ |
56 | echo "DEBUG: stage0Loader: Disk loader is ${stage0Loader}"␊ |
57 | echo "DEBUG: stage0LoaderDualBoot: Disk loader is ${stage0LoaderDualBoot}"␊ |
58 | echo "DEBUG: stage1LoaderHFS: Partition loader is ${stage1LoaderHFS}"␊ |
59 | echo "DEBUG: stage1LoaderFat: Partition loader is ${stage1LoaderFAT}"␊ |
60 | echo "DEBUG: stage2Loader: Filesystem loader is ${stage2Loader}"␊ |
61 | echo "DEBUG: targetVolumeTemp: Volume is ${targetVolumeTemp}"␊ |
62 | echo "DEBUG: targetDeviceTemp: Volume device is ${targetDeviceTemp}"␊ |
63 | echo "DEBUG: targetVolume: Volume is ${targetVolume}"␊ |
64 | echo "DEBUG: targetDevice: Volume device is ${targetDevice}"␊ |
65 | echo "DEBUG: targetDeviceRaw: Volume raw device is ${targetDeviceRaw}"␊ |
66 | echo "DEBUG: targetDisk: Disk device is ${targetDisk}"␊ |
67 | echo "DEBUG: targetDiskRaw: Disk raw device is ${targetDiskRaw}"␊ |
68 | echo "DEBUG: targetSlice: Volume slice is ${targetSlice}"␊ |
69 | echo "DEBUG: targetResources: Boot Resources is ${targetResources} - ????????????"␊ |
70 | echo "DEBUG: targetName: Volume name to look for is ${targetName} - ????????????"␊ |
71 | echo "-----------------------------------------------"␊ |
72 | echo ""␊ |
73 | ␊ |
74 | ␊ |
75 | # Check to see if the selected disk uses a GPT␊ |
76 | ␊ |
77 | bootuuid=$( diskutil info "$targetDeviceTemp" | grep Volume\ UUID | awk {'print $3'} )␊ |
78 | partitiontable=$( diskutil list ${targetDeviceTemp%s*} | sed -n '3p' | awk '{print $2}' )␊ |
79 | ␊ |
80 | if [ ${partitiontable} = "GUID_partition_scheme" ]; then␊ |
81 | ␉echo "Confirm this is a GPT partitioned disk."␊ |
82 | ␊ |
83 | ␉# Double check we can see the selected partition and it's of the right type␊ |
84 | ␊ |
85 | ␉"$scriptDir"CheckProceed.sh "${targetVolumeTemp}" "${targetDeviceTemp}"␊ |
86 | ␉returnValue=$?␊ |
87 | ␉if [ ${returnValue} = 0 ]; then␊ |
88 | ␉␉# OK to proceed␊ |
89 | ␊ |
90 | ␊ |
91 | ␉␉# Does a GRUB or Linux loader already exist in the disk's MBR?␊ |
92 | ␊ |
93 | ␉␉"$scriptDir"CheckDiskMicrocodeType.sh "${targetDisk}"␊ |
94 | ␉␉returnValue=$?␊ |
95 | ␉␉if [ ${returnValue} = 0 ]; then␊ |
96 | ␉␉␉# OK to proceed␊ |
97 | ␊ |
98 | ␊ |
99 | ␉␉␉# check for a 4-byte Windows disk signature in the disk's MBR.␊ |
100 | ␉␉␉# the following script returns 1 if a Windows disk signature exists, and 0 if not.␊ |
101 | ␊ |
102 | ␉␉␉"$scriptDir"CheckDiskSignature.sh "${targetDisk}"␊ |
103 | ␉␉␉diskSigCheck=$?␊ |
104 | ␊ |
105 | ␊ |
106 | ␉␉␉# check for existing bootloaders in the disk's MBR␊ |
107 | ␉␉␉# and find out if we can write the Chameleon boot files.␊ |
108 | ␉␉␉# the following script returns 1 if we can proceed␊ |
109 | ␉␉␉# with writing the boot files, and 0 for not.␊ |
110 | ␊ |
111 | ␉␉␉"$scriptDir"CheckDiskMicrocode.sh "${targetDisk}" "${diskSigCheck}" ␊ |
112 | ␉␉␉diskupdate=$?␊ |
113 | ␊ |
114 | ␊ |
115 | ␉␉␉# Cancelled this as all it does is read the GPTdiskProtectiveMBR␊ |
116 | ␉␉␉# and the GPTdiskGPTHeader and look to see if they're blank␊ |
117 | |
118 | ␊ |
119 | ␉␉␉#"$scriptDir"FindPartitionBootcode.sh "${targetDeviceRaw}"␊ |
120 | ␊ |
121 | ␊ |
122 | ␉␉␉# check the format of the selected partition.␊ |
123 | ␉␉␉# the following script returns 1 if HFS␊ |
124 | ␉␉␉# the following script returns 2 if MSDOS␊ |
125 | ␉␉␉# the following script returns 0 if nothing␊ |
126 | ␊ |
127 | ␉␉␉"$scriptDir"CheckFormat.sh "${targetDevice}"␊ |
128 | ␉␉␉espformat=$?␊ |
129 | ␊ |
130 | ␊ |
131 | ␉␉␉# Determine the partition scheme of the selected disk␊ |
132 | ␉␉␉# is it GPT or a hybrid GPT/MBR␊ |
133 | ␊ |
134 | ␉␉␉"$scriptDir"CheckPartitionScheme.sh "${targetDisk}"␊ |
135 | ␊ |
136 | ␊ |
137 | ␉␉␉# Unmount ALL mounted volumes named EFI␊ |
138 | ␉␉␉# the following script returns 0 if it succeeds␊ |
139 | ␉␉␉# the following script returns 1 if it fails to un-mount any EFI volume␊ |
140 | ␊ |
141 | ␉␉␉"$scriptDir"UnMountEFIvolumes.sh␊ |
142 | ␉␉␉returnValue=$?␊ |
143 | ␉␉␉if [ ${returnValue} = 0 ]; then␊ |
144 | ␉␉␉␉# OK to proceed␊ |
145 | ␊ |
146 | ␊ |
147 | ␉␉␉␉# Check the format of the EFI system partition␊ |
148 | ␉␉␉␉# No Needed as this is done earlier by CheckFormat.sh␊ |
149 | ␉␉␉␉#"$scriptDir"CheckESPformat.sh "${targetDevice}"␊ |
150 | ␊ |
151 | ␊ |
152 | ␉␉␉␉# If diskupdate is flagged as 1 then the stage 0 loader can be written to the MBR␊ |
153 | ␉␉␉␉if [ ${diskupdate} = 1 ]; then␊ |
154 | ␉␉␉␉␉"$scriptDir"WriteChameleonStage0.sh "${diskupdate}" "${diskSigCheck}" "${stage0Loader}" "${stage0LoaderDualBoot}" "${targetDisk}" "${targetVolumeTemp}"␊ |
155 | ␉␉␉␉fi␊ |
156 | ␊ |
157 | ␉␉␉␉# Write the stage 1 loader to the partition boot sector␊ |
158 | ␉␉␉␉"$scriptDir"WriteChameleonStage1.sh "${espformat}" "${stage1LoaderHFS}" "${stage1LoaderFAT}" "${targetVolumeTemp}" "${targetDeviceRaw}" "${targetVolume}"␊ |
159 | ␊ |
160 | ␉␉␉␉# Write the stage 2 loader to the root of the selected partition␊ |
161 | ␉␉␉␉"$scriptDir"WriteChameleonStage2.sh "${espformat}" "${stage2Loader}" "${targetVolumeTemp}" "${targetDevice}" "${targetVolume}"␊ |
162 | ␊ |
163 | ␉␉␉␉# Set the active partition ONLY if Windows is not installed␊ |
164 | ␉␉␉␉"$scriptDir"SetActivePartition.sh "${espformat}" "${diskSigCheck}" "${targetDiskRaw}" "${targetSlice}" "${targetVolumeTemp}"␊ |
165 | ␉␉␉␊ |
166 | ␉␉␉fi␊ |
167 | ␉␉fi␊ |
168 | ␉fi␊ |
169 | else␊ |
170 | ␉echo␊ |
171 | ␉echo "ERROR Volume is not on a GPT partitioned disc."␊ |
172 | ␉echo␊ |
173 | fi␊ |
174 | ␊ |
175 | exit 0␊ |
176 | |