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.
11MYLOCATION="${PWD}/${BASH_ARGV[0]}"
12export MYLOCATION="${MYLOCATION%/*}"
13scriptDir=$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
21if ! [ -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
41stage0Loader="boot0"
42stage0LoaderDualBoot="boot0hfs"
43stage1LoaderHFS="boot1h"
44stage1LoaderFAT="boot1f32"
45stage2Loader="boot"
46
47targetVolumeTemp=$3
48targetDeviceTemp=$( df "${targetVolumeTemp}" | sed -n '2p' | awk '{print $1}' )
49
50targetVolume="/Volumes/EFI"
51targetDevice=${targetDeviceTemp%s*}s1
52targetDeviceRaw=${targetDevice/disk/rdisk}
53targetDisk=${targetDevice%s*}
54targetDiskRaw=${targetDisk/disk/rdisk}
55targetSlice=${targetDevice#*disk*s}
56targetResources="${targetVolume%/*}" # - is this needed?
57
58
59
60#echo "==============================================="
61#echo "DEBUG: display script variables"
62#echo "***************************"
63
64#echo "DEBUG: stage0Loader: Disk loader is ${stage0Loader}"
65#echo "DEBUG: stage0LoaderDualBoot: Disk loader is ${stage0LoaderDualBoot}"
66#echo "DEBUG: stage1LoaderHFS: Partition loader is ${stage1LoaderHFS}"
67#echo "DEBUG: stage1LoaderFat: Partition loader is ${stage1LoaderFAT}"
68#echo "DEBUG: stage2Loader: Filesystem loader is ${stage2Loader}"
69#echo "DEBUG: targetVolumeTemp: Volume is ${targetVolumeTemp}"
70#echo "DEBUG: targetDeviceTemp: Volume device is ${targetDeviceTemp}"
71#echo "DEBUG: targetVolume: Volume is ${targetVolume}"
72#echo "DEBUG: targetDevice: Volume device is ${targetDevice}"
73#echo "DEBUG: targetDeviceRaw: Volume raw device is ${targetDeviceRaw}"
74#echo "DEBUG: targetDisk: Disk device is ${targetDisk}"
75#echo "DEBUG: targetDiskRaw: Disk raw device is ${targetDiskRaw}"
76#echo "DEBUG: targetSlice: Volume slice is ${targetSlice}"
77#echo "DEBUG: targetResources: Boot Resources is ${targetResources} - ????????????"
78#echo "DEBUG: targetName: Volume name to look for is ${targetName} - ????????????"
79#echo "-----------------------------------------------"
80#echo ""
81
82
83# Check to see if the selected disk uses a GPT
84
85bootuuid=$( diskutil info "$targetDeviceTemp" | grep Volume\ UUID | awk {'print $3'} )
86partitiontable=$( diskutil list ${targetDeviceTemp%s*} | sed -n '3p' | awk '{print $2}' )
87
88if [ ${partitiontable} = "GUID_partition_scheme" ]; then
89echo "Confirm this is a GPT partitioned disk."
90
91# Double check we can see the selected partition and it's of the right type
92
93"$scriptDir"CheckProceed.sh "${targetVolumeTemp}" "${targetDeviceTemp}"
94returnValue=$?
95if [ ${returnValue} = 0 ]; then
96# OK to proceed
97
98
99# Does a GRUB or Linux loader already exist in the disk's MBR?
100# The script returns 1 if yes, 0 if no.
101
102"$scriptDir"CheckGRUBLinuxLoader.sh "${targetDisk}"
103returnValue=$?
104if [ ${returnValue} = 0 ]; then
105# OK to proceed
106
107
108# check for a 4-byte Windows disk signature in the disk's MBR.
109# the following script returns 1 if a Windows disk signature exists, and 0 if not.
110
111"$scriptDir"CheckWindowsDiskSignature.sh "${targetDisk}"
112diskSigCheck=$?
113
114
115# check for existing bootloaders in the disk's MBR
116# and find out if we can write the Chameleon boot files.
117# the following script returns 0 if we can proceed
118# with writing the boot files, and 1 for not.
119
120"$scriptDir"CheckDiskMicrocode.sh "${targetDisk}" "${diskSigCheck}"
121diskupdate=$?
122
123
124# check the format of the selected partition.
125# the following script returns 1 if HFS
126# the following script returns 2 if MSDOS
127# the following script returns 0 if nothing
128
129"$scriptDir"CheckFormat.sh "${targetDevice}"
130espformat=$?
131
132
133# Determine the partition scheme of the selected disk
134# is it GPT or a hybrid GPT/MBR
135
136"$scriptDir"CheckPartitionScheme.sh "${targetDisk}"
137
138
139# Unmount ALL mounted volumes named EFI
140# the following script returns 0 if it succeeds
141# the following script returns 1 if it fails to un-mount any EFI volume
142
143"$scriptDir"UnMountEFIvolumes.sh
144returnValue=$?
145if [ ${returnValue} = 0 ]; then
146# OK to proceed
147
148
149# If diskupdate is flagged as 0 then the stage 0 loader can be written to the MBR
150if [ ${diskupdate} = 0 ]; then
151"$scriptDir"WriteChameleonStage0.sh "${diskupdate}" "${diskSigCheck}" "${stage0Loader}" "${stage0LoaderDualBoot}" "${targetDisk}" "${targetVolumeTemp}"
152fi
153
154# Write the stage 1 loader to the partition boot sector
155"$scriptDir"WriteChameleonStage1.sh "${espformat}" "${stage1LoaderHFS}" "${stage1LoaderFAT}" "${targetVolumeTemp}" "${targetDeviceRaw}" "${targetVolume}"
156
157# Write the stage 2 loader to the root of the selected partition
158"$scriptDir"WriteChameleonStage2.sh "${espformat}" "${stage2Loader}" "${targetVolumeTemp}" "${targetDevice}" "${targetVolume}"
159
160# Set the active partition ONLY if Windows is not installed
161"$scriptDir"SetActivePartition.sh "${espformat}" "${diskSigCheck}" "${targetDiskRaw}" "${targetSlice}" "${targetVolumeTemp}"
162
163fi
164else
165# Write error to Chameleon_Error_Log file
166"$scriptDir"WriteInstallerLog.sh "${targetVolumeTemp}" "Error: Target drive has existing GRUB / Linux loader in the MBR - Not sure how to continue"
167fi
168fi
169else
170echo "ERROR Volume is not on a GPT partitioned disc."
171# Write error to Chameleon_Error_Log file
172"$scriptDir"WriteInstallerLog.sh "${targetVolumeTemp}" "Error: ${targetVolumeTemp} is not on a GPT partitioned disc."
173fi
174else
175echo "Error: User selected both locations for installation"
176# Write error to Chameleon_Error_Log file
177"$scriptDir"WriteInstallerLog.sh "${3}" "Error: User selected both locations for installation. Exiting the script for installing to the EFI system partition"
178fi
179
180exit 0
181

Archive Download this file

Revision: 255