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 | 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 | ␊ |
32 | # Initialise Script Globals␊ |
33 | ␊ |
34 | stage0Loader="boot0"␊ |
35 | stage0LoaderDualBoot="boot0hfs"␊ |
36 | stage1LoaderHFS="boot1h"␊ |
37 | stage1LoaderFAT="boot1f32"␊ |
38 | stage2Loader="boot"␊ |
39 | ␊ |
40 | targetVolume=$3 #was bootvolume␊ |
41 | targetDevice=$( df "${targetVolume}" | sed -n '2p' | awk '{print $1}' )␊ |
42 | targetDeviceRaw=${targetDevice/disk/rdisk}␊ |
43 | targetDisk=${targetDevice%s*}␊ |
44 | targetDiskRaw=${targetDisk/disk/rdisk}␊ |
45 | targetSlice=${targetDevice#*disk*s}␊ |
46 | ␊ |
47 | targetResources="${targetVolume%/*}" # is this needed?␊ |
48 | ␊ |
49 | ␊ |
50 | ␊ |
51 | #echo "==============================================="␊ |
52 | #echo "DEBUG: display script variables"␊ |
53 | #echo "*******************************"␊ |
54 | ␊ |
55 | #echo "DEBUG: stage0Loader: Disk loader is ${stage0Loader}"␊ |
56 | #echo "DEBUG: stage0LoaderDualBoot: Disk loader is ${stage0LoaderDualBoot}"␊ |
57 | #echo "DEBUG: stage1LoaderHFS: Partition loader is ${stage1LoaderHFS}"␊ |
58 | #echo "DEBUG: stage1LoaderFat: Partition loader is ${stage1LoaderFAT}"␊ |
59 | #echo "DEBUG: stage2Loader: Filesystem loader is ${stage2Loader}"␊ |
60 | #echo "DEBUG: targetVolume: Volume is ${targetVolume}"␊ |
61 | #echo "DEBUG: targetDevice: Volume device is ${targetDevice}"␊ |
62 | #echo "DEBUG: targetDeviceRaw: Volume raw device is ${targetDeviceRaw}"␊ |
63 | #echo "DEBUG: targetDisk: Disk device is ${targetDisk}"␊ |
64 | #echo "DEBUG: targetDiskRaw: Disk raw device is ${targetDiskRaw}"␊ |
65 | #echo "DEBUG: targetSlice: Volume slice is ${targetSlice}"␊ |
66 | #echo "DEBUG: targetResources: Boot Resources is ${targetResources}"␊ |
67 | #echo "-----------------------------------------------"␊ |
68 | #echo ""␊ |
69 | ␊ |
70 | ␊ |
71 | # Double check we can see the selected partition and it's of the right type␊ |
72 | # if not the following script returns to indicate failure.␊ |
73 | ␊ |
74 | "$scriptDir"CheckProceed.sh "${targetVolume}" "${targetDevice}"␊ |
75 | returnValue=$?␊ |
76 | if [ ${returnValue}=0 ]; then␊ |
77 | ␉# OK to proceed␊ |
78 | ␊ |
79 | ␊ |
80 | ␉# Does a GRUB or Linux loader already exist in the disk's MBR?␊ |
81 | ␊ |
82 | ␉"$scriptDir"CheckDiskMicrocodeType.sh "${targetDisk}"␊ |
83 | ␉returnValue=$?␊ |
84 | ␉if [ ${returnValue} = 0 ]; then␊ |
85 | ␉␉# OK to proceed␊ |
86 | ␊ |
87 | ␊ |
88 | ␉␉# check for a 4-byte Windows disk signature in the disk's MBR.␊ |
89 | ␉␉# the following script returns 1 if a Windows disk signature exists, and 0 if not.␊ |
90 | ␊ |
91 | ␉␉"$scriptDir"CheckDiskSignature.sh "${targetDisk}"␊ |
92 | ␉␉diskSigCheck=$?␊ |
93 | ␊ |
94 | ␊ |
95 | ␉␉# check for existing bootloaders in the disk's MBR␊ |
96 | ␉␉# and find out if we can write the Chameleon boot files.␊ |
97 | ␉␉# the following script returns 1 if we can proceed␊ |
98 | ␉␉# with writing the boot files, and 0 for not.␊ |
99 | ␊ |
100 | ␉␉"$scriptDir"CheckDiskMicrocode.sh "${targetDisk}" "${diskSigCheck}" ␊ |
101 | ␉␉diskupdate=$?␊ |
102 | ␊ |
103 | ␊ |
104 | ␉␉# Cancelled this as all it does is read the GPTdiskProtectiveMBR␊ |
105 | ␉␉# and the GPTdiskGPTHeader and look to see if they're blank␊ |
106 | |
107 | ␉␉␊ |
108 | ␉␉#"$scriptDir"FindPartitionBootcode.sh "${targetDeviceRaw}"␊ |
109 | ␊ |
110 | ␊ |
111 | ␉␉# check the format of the selected partition.␊ |
112 | ␉␉# the following script returns 1 if HFS␊ |
113 | ␉␉# the following script returns 2 if MSDOS␊ |
114 | ␉␉# the following script returns 0 if nothing␊ |
115 | ␊ |
116 | ␉␉"$scriptDir"CheckFormat.sh "${targetDevice}"␊ |
117 | ␉␉espformat=$?␊ |
118 | ␊ |
119 | ␊ |
120 | ␉␉# check the partition scheme used for the selected disk.␊ |
121 | ␉␉# the following script returns 1 if GPT␊ |
122 | ␉␉# the following script returns 2 if GPT/MBR␊ |
123 | ␉␉# the following script returns 3 if MBR␊ |
124 | ␉␉# the following script returns 0 if nothing␊ |
125 | ␊ |
126 | ␉␉"$scriptDir"CheckPartitionScheme.sh "${targetDisk}"␊ |
127 | ␉␉partitionTable=$?␊ |
128 | ␉␉if [ ${partitionTable} = 3 ]; then␊ |
129 | ␉␉␉# If MBR partition scheme then check for FAT16 or FAT32␊ |
130 | ␊ |
131 | ␉␉␉# the following script returns 1 if FAT16␊ |
132 | ␉␉␉# the following script returns 2 if FAT32␊ |
133 | ␉␉␉# the following script returns 0 if nothing␊ |
134 | ␊ |
135 | ␉␉␉"$scriptDir"CheckFatType.sh "${targetDeviceRaw}"␊ |
136 | ␉␉␉fatType=$?␊ |
137 | ␉␉fi␊ |
138 | ␊ |
139 | ␉␉if [ "${fatType}" = 1 ] && [ "${partitionTable}" = 3 ]; then␊ |
140 | ␉␉␉echo "ERROR: - Can't install to a device using FAT16"␊ |
141 | ␉␉␉# Write error to Chameleon_Error_Log file␊ |
142 | ␉␉␉"$scriptDir"WriteInstallerLog.sh "${3}" "${3} is a FAT16 device - Chameleon boot files not written"␊ |
143 | ␉␉else␊ |
144 | ␉␉␉# Continue if the selected device is not a FAT16 format device␊ |
145 | ␊ |
146 | ␉␉␉# If diskupdate is flagged as 1 then the stage 0 loader can be written to the MBR␊ |
147 | ␉␉␉if [ ${diskupdate} = 1 ]; then␊ |
148 | ␉␉␉␉"$scriptDir"WriteChameleonStage0.sh "${diskupdate}" "${diskSigCheck}" "${stage0Loader}" "${stage0LoaderDualBoot}" "${targetDisk}" "${targetVolume}"␊ |
149 | ␉␉␉fi␊ |
150 | ␊ |
151 | ␉␉␉# Write the stage 1 loader to the partition boot sector␊ |
152 | ␉␉␉"$scriptDir"WriteChameleonStage1.sh "${espformat}" "${stage1LoaderHFS}" "${stage1LoaderFAT}" "${3}" "${targetDeviceRaw}" "${targetVolume}"␊ |
153 | ␊ |
154 | ␉␉␉# Write the stage 2 loader to the root of the selected partition␊ |
155 | ␉␉␉"$scriptDir"WriteChameleonStage2.sh "${espformat}" "${stage2Loader}" "${3}" "${targetDevice}" "${targetVolume}"␊ |
156 | ␊ |
157 | ␉␉␉# Set the active partition ONLY if Windows is not installed␊ |
158 | ␉␉␉"$scriptDir"SetActivePartition.sh "${espformat}" "${diskSigCheck}" "${targetDiskRaw}" "${targetSlice}" "${targetVolume}"␉␉␉␊ |
159 | ␉␉fi␊ |
160 | ␉else␊ |
161 | ␉␉# Write error to Chameleon_Error_Log file␊ |
162 | ␉␉"$scriptDir"WriteInstallerLog.sh "${targetVolume}" "Error: Target drive has existing GRUB / Linux loader in the MBR - Not sure how to continue"␊ |
163 | ␉fi␊ |
164 | else␊ |
165 | ␉# Write error to Chameleon_Error_Log file␊ |
166 | ␉"$scriptDir"WriteInstallerLog.sh "${targetVolume}" "Error: ${targetVolume} couldn't be found or the disk doesn't use slices"␊ |
167 | fi␊ |
168 | ␊ |
169 | exit 0␊ |
170 | |