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