Chameleon Applications

Chameleon Applications Svn Source Tree

Root/branches/blackosx/trunk/PackageBuilder/Main_Package_Elements/Scripts/MainESPPostinstall.sh

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

Archive Download this file

Revision: 258