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}
56
57
58
59echo "==============================================="
60echo "DEBUG: display script variables"
61echo "***************************"
62
63echo "DEBUG: stage0Loader: Disk loader is ${stage0Loader}"
64echo "DEBUG: stage0LoaderDualBoot: Disk loader is ${stage0LoaderDualBoot}"
65echo "DEBUG: stage1LoaderHFS: Partition loader is ${stage1LoaderHFS}"
66echo "DEBUG: stage1LoaderFat: Partition loader is ${stage1LoaderFAT}"
67echo "DEBUG: stage2Loader: Filesystem loader is ${stage2Loader}"
68echo "DEBUG: targetVolumeTemp: Volume is ${targetVolumeTemp}"
69echo "DEBUG: targetDeviceTemp: Volume device is ${targetDeviceTemp}"
70echo "DEBUG: targetVolume: Volume is ${targetVolume}"
71echo "DEBUG: targetDevice: Volume device is ${targetDevice}"
72echo "DEBUG: targetDeviceRaw: Volume raw device is ${targetDeviceRaw}"
73echo "DEBUG: targetDisk: Disk device is ${targetDisk}"
74echo "DEBUG: targetDiskRaw: Disk raw device is ${targetDiskRaw}"
75echo "DEBUG: targetSlice: Volume slice is ${targetSlice}"
76echo "-----------------------------------------------"
77echo ""
78
79
80# Check to see if the selected disk uses a GPT
81
82bootuuid=$( diskutil info "$targetDeviceTemp" | grep Volume\ UUID | awk {'print $3'} )
83partitiontable=$( diskutil list ${targetDeviceTemp%s*} | sed -n '3p' | awk '{print $2}' )
84
85if [ ${partitiontable} = "GUID_partition_scheme" ]; then
86echo "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}"
91returnValue=$?
92if [ ${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}"
100returnValue=$?
101if [ ${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}"
109diskSigCheck=$?
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}"
118diskupdate=$?
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}"
127espformat=$?
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
141returnValue=$?
142if [ ${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
147if [ ${diskupdate} = 0 ]; then
148"$scriptDir"WriteChameleonStage0.sh "${diskupdate}" "${diskSigCheck}" "${stage0Loader}" "${stage0LoaderDualBoot}" "${targetDisk}" "${targetVolumeTemp}"
149fi
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
160fi
161else
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"
164fi
165fi
166else
167echo "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."
170fi
171else
172echo "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"
175fi
176
177exit 0
178

Archive Download this file

Revision: 257