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 | # Before starting - we'd better check to see if the user selected␊ |
17 | # both the standard and the EFI system partition install options.␊ |
18 | # If they did then the standard install will have already be run.␊ |
19 | # Therefore, we will not run this.␊ |
20 | ␊ |
21 | if ! [ -f "${3}"/.Chameleon/nullstandard ]; then␊ |
22 | ␉# OK to continue␊ |
23 | ␊ |
24 | ␉#echo "==============================================="␊ |
25 | ␉#echo "Apple Installer Package Variables"␊ |
26 | ␉#echo "*********************************"␊ |
27 | ␉#echo "DEBUG: $ 1 = Full path to the installation package the installer app is processing: " $1␊ |
28 | ␉#echo "DEBUG: $ 2 = Full path to the installation destination: " $2␊ |
29 | ␉#echo "DEBUG: $ 3 = Installation volume (mountpoint) to receive the payload: " $3␊ |
30 | ␉#echo "DEBUG: $ 4 = Root directory for the system: " $4␊ |
31 | ␉#echo "DEBUG: Script Name: " $SCRIPT_NAME␊ |
32 | ␉#echo "DEBUG: Package Path: " $PACKAGE_PATH␊ |
33 | ␉#echo "DEBUG: Installer Temp: " $INSTALLER_TEMP␊ |
34 | ␉#echo "DEBUG: Full path to the temp directory containing the operation executable: " $RECEIPT_PATH␊ |
35 | ␉#echo "-----------------------------------------------"␊ |
36 | ␉#echo ""␊ |
37 | ␊ |
38 | ␊ |
39 | ␉# Initialise Script Globals␊ |
40 | ␊ |
41 | ␉stage0Loader="boot0"␊ |
42 | ␉stage0LoaderDualBoot="boot0hfs"␊ |
43 | ␉stage1LoaderHFS="boot1h"␊ |
44 | ␉stage1LoaderFAT="boot1f32"␊ |
45 | ␉stage2Loader="boot"␊ |
46 | ␊ |
47 | ␉targetVolumeTemp=$3␊ |
48 | ␉targetDeviceTemp=$( df "${targetVolumeTemp}" | sed -n '2p' | awk '{print $1}' )␊ |
49 | ␊ |
50 | ␉targetVolume="/Volumes/EFI"␊ |
51 | ␉targetDevice=${targetDeviceTemp%s*}s1␊ |
52 | ␉targetDeviceRaw=${targetDevice/disk/rdisk}␊ |
53 | ␉targetDisk=${targetDevice%s*}␊ |
54 | ␉targetDiskRaw=${targetDisk/disk/rdisk}␊ |
55 | ␉targetSlice=${targetDevice#*disk*s}␊ |
56 | ␊ |
57 | ␊ |
58 | ␊ |
59 | ␉echo "==============================================="␊ |
60 | ␉echo "DEBUG: display script variables"␊ |
61 | ␉echo "***************************"␊ |
62 | ␊ |
63 | ␉echo "DEBUG: stage0Loader: Disk loader is ${stage0Loader}"␊ |
64 | ␉echo "DEBUG: stage0LoaderDualBoot: Disk loader is ${stage0LoaderDualBoot}"␊ |
65 | ␉echo "DEBUG: stage1LoaderHFS: Partition loader is ${stage1LoaderHFS}"␊ |
66 | ␉echo "DEBUG: stage1LoaderFat: Partition loader is ${stage1LoaderFAT}"␊ |
67 | ␉echo "DEBUG: stage2Loader: Filesystem loader is ${stage2Loader}"␊ |
68 | ␉echo "DEBUG: targetVolumeTemp: Volume is ${targetVolumeTemp}"␊ |
69 | ␉echo "DEBUG: targetDeviceTemp: Volume device is ${targetDeviceTemp}"␊ |
70 | ␉echo "DEBUG: targetVolume: Volume is ${targetVolume}"␊ |
71 | ␉echo "DEBUG: targetDevice: Volume device is ${targetDevice}"␊ |
72 | ␉echo "DEBUG: targetDeviceRaw: Volume raw device is ${targetDeviceRaw}"␊ |
73 | ␉echo "DEBUG: targetDisk: Disk device is ${targetDisk}"␊ |
74 | ␉echo "DEBUG: targetDiskRaw: Disk raw device is ${targetDiskRaw}"␊ |
75 | ␉echo "DEBUG: targetSlice: Volume slice is ${targetSlice}"␊ |
76 | ␉echo "-----------------------------------------------"␊ |
77 | ␉echo ""␊ |
78 | ␊ |
79 | ␊ |
80 | ␉# Check to see if the selected disk uses a GPT␊ |
81 | ␊ |
82 | ␉bootuuid=$( diskutil info "$targetDeviceTemp" | grep Volume\ UUID | awk {'print $3'} )␊ |
83 | ␉partitiontable=$( diskutil list ${targetDeviceTemp%s*} | sed -n '3p' | awk '{print $2}' )␊ |
84 | ␊ |
85 | ␉if [ ${partitiontable} = "GUID_partition_scheme" ]; then␊ |
86 | ␉␉echo "Confirm this is a GPT partitioned disk."␊ |
87 | ␊ |
88 | ␉␉# Double check we can see the selected partition and it's of the right type␊ |
89 | ␊ |
90 | ␉␉"$scriptDir"CheckProceed.sh "${targetVolumeTemp}" "${targetDeviceTemp}"␊ |
91 | ␉␉returnValue=$?␊ |
92 | ␉␉if [ ${returnValue} = 0 ]; then␊ |
93 | ␉␉␉# OK to proceed␊ |
94 | ␊ |
95 | ␊ |
96 | ␉␉␉# Does a GRUB or Linux loader already exist in the disk's MBR?␊ |
97 | ␉␉␉# The script returns 1 if yes, 0 if no.␊ |
98 | ␊ |
99 | ␉␉␉"$scriptDir"CheckGRUBLinuxLoader.sh "${targetDisk}"␊ |
100 | ␉␉␉returnValue=$?␊ |
101 | ␉␉␉if [ ${returnValue} = 0 ]; then␊ |
102 | ␉␉␉␉# OK to proceed␊ |
103 | ␊ |
104 | ␊ |
105 | ␉␉␉␉# check for a 4-byte Windows disk signature in the disk's MBR.␊ |
106 | ␉␉␉␉# the following script returns 1 if a Windows disk signature exists, and 0 if not.␊ |
107 | ␊ |
108 | ␉␉␉␉"$scriptDir"CheckWindowsDiskSignature.sh "${targetDisk}"␊ |
109 | ␉␉␉␉diskSigCheck=$?␊ |
110 | ␊ |
111 | ␊ |
112 | ␉␉␉␉# check for existing bootloaders in the disk's MBR␊ |
113 | ␉␉␉␉# and find out if we can write the Chameleon boot files.␊ |
114 | ␉␉␉␉# the following script returns 0 if we can proceed␊ |
115 | ␉␉␉␉# with writing the boot files, and 1 for not.␊ |
116 | ␊ |
117 | ␉␉␉␉"$scriptDir"CheckDiskMicrocode.sh "${targetDisk}" "${diskSigCheck}" ␊ |
118 | ␉␉␉␉diskupdate=$?␊ |
119 | ␊ |
120 | ␊ |
121 | ␉␉␉␉# check the format of the selected partition.␊ |
122 | ␉␉␉␉# the following script returns 1 if HFS␊ |
123 | ␉␉␉␉# the following script returns 2 if MSDOS␊ |
124 | ␉␉␉␉# the following script returns 0 if nothing␊ |
125 | ␊ |
126 | ␉␉␉␉"$scriptDir"CheckFormat.sh "${targetDevice}"␊ |
127 | ␉␉␉␉espformat=$?␊ |
128 | ␊ |
129 | ␊ |
130 | ␉␉␉␉# Determine the partition scheme of the selected disk␊ |
131 | ␉␉␉␉# is it GPT or a hybrid GPT/MBR␊ |
132 | ␊ |
133 | ␉␉␉␉"$scriptDir"CheckPartitionScheme.sh "${targetDisk}"␊ |
134 | ␊ |
135 | ␊ |
136 | ␉␉␉␉# Unmount ALL mounted volumes named EFI␊ |
137 | ␉␉␉␉# the following script returns 0 if it succeeds␊ |
138 | ␉␉␉␉# the following script returns 1 if it fails to un-mount any EFI volume␊ |
139 | ␊ |
140 | ␉␉␉␉"$scriptDir"UnMountEFIvolumes.sh␊ |
141 | ␉␉␉␉returnValue=$?␊ |
142 | ␉␉␉␉if [ ${returnValue} = 0 ]; then␊ |
143 | ␉␉␉␉␉# OK to proceed␊ |
144 | ␊ |
145 | ␊ |
146 | ␉␉␉␉␉# If diskupdate is flagged as 0 then the stage 0 loader can be written to the MBR␊ |
147 | ␉␉␉␉␉if [ ${diskupdate} = 0 ]; then␊ |
148 | ␉␉␉␉␉␉"$scriptDir"WriteChameleonStage0.sh "${diskupdate}" "${diskSigCheck}" "${stage0Loader}" "${stage0LoaderDualBoot}" "${targetDisk}" "${targetVolumeTemp}"␊ |
149 | ␉␉␉␉␉fi␊ |
150 | ␊ |
151 | ␉␉␉␉␉# Write the stage 1 loader to the partition boot sector␊ |
152 | ␉␉␉␉␉"$scriptDir"WriteChameleonStage1.sh "${espformat}" "${stage1LoaderHFS}" "${stage1LoaderFAT}" "${targetVolumeTemp}" "${targetDeviceRaw}" "${targetVolume}"␊ |
153 | ␊ |
154 | ␉␉␉␉␉# Write the stage 2 loader to the root of the selected partition␊ |
155 | ␉␉␉␉␉"$scriptDir"WriteChameleonStage2.sh "${espformat}" "${stage2Loader}" "${targetVolumeTemp}" "${targetDevice}" "${targetVolume}"␊ |
156 | ␊ |
157 | ␉␉␉␉␉# Set the active partition ONLY if Windows is not installed␊ |
158 | ␉␉␉␉␉"$scriptDir"SetActivePartition.sh "${espformat}" "${diskSigCheck}" "${targetDiskRaw}" "${targetSlice}" "${targetVolumeTemp}"␊ |
159 | ␉␉␉␊ |
160 | ␉␉␉␉fi␊ |
161 | ␉␉␉else␊ |
162 | ␉␉␉␉# Write error to Chameleon_Error_Log file␊ |
163 | ␉␉␉␉"$scriptDir"WriteInstallerLog.sh "${targetVolumeTemp}" "Error: Target drive has existing GRUB / Linux loader in the MBR - Not sure how to continue"␊ |
164 | ␉␉␉fi␊ |
165 | ␉␉fi␊ |
166 | ␉else␊ |
167 | ␉␉echo "ERROR Volume is not on a GPT partitioned disc."␊ |
168 | ␉␉# Write error to Chameleon_Error_Log file␊ |
169 | ␉␉"$scriptDir"WriteInstallerLog.sh "${targetVolumeTemp}" "Error: ${targetVolumeTemp} is not on a GPT partitioned disc."␊ |
170 | ␉fi␊ |
171 | else␊ |
172 | ␉echo "Note: User selected both locations for installation - So not Continuing with EFI System Partition script"␊ |
173 | ␉# Write error to Chameleon_Error_Log file␊ |
174 | ␉"$scriptDir"WriteInstallerLog.sh "${3}" "Note: User selected both locations for installation. Not continuing with the script for installing to the EFI system partition"␊ |
175 | fi␊ |
176 | ␊ |
177 | exit 0␊ |
178 | |