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#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# Initialise Script Globals
32
33stage0Loader="boot0" #diskloader
34stage0LoaderDualBoot="boot0hfs" #was stage0Loaderdualboot
35stage1LoaderHFS="boot1h" #was stage1LoaderHFS
36stage1LoaderFAT="boot1f32" #was partitionloaderfat
37stage2Loader="boot" #was filesystemloader
38
39targetVolumeTemp=$3 #was bootvolume
40targetDeviceTemp=$( df "${targetVolumeTemp}" | sed -n '2p' | awk '{print $1}' ) #was bootdev
41
42targetVolume="/Volumes/EFI"
43targetDevice=${targetDeviceTemp%s*}s1
44targetDeviceRaw=${targetDevice/disk/rdisk} #was bootrdev
45targetDisk=${targetDevice%s*} #was bootdisk
46targetDiskRaw=${targetDisk/disk/rdisk} #was bootrdisk
47targetSlice=${targetDevice#*disk*s} #was bootslice
48targetResources="${targetVolume%/*}" #was bootresources - is this needed?
49
50
51
52echo "==============================================="
53echo "DEBUG: display script variables"
54echo "***************************"
55
56echo "DEBUG: stage0Loader: Disk loader is ${stage0Loader}"
57echo "DEBUG: stage0LoaderDualBoot: Disk loader is ${stage0LoaderDualBoot}"
58echo "DEBUG: stage1LoaderHFS: Partition loader is ${stage1LoaderHFS}"
59echo "DEBUG: stage1LoaderFat: Partition loader is ${stage1LoaderFAT}"
60echo "DEBUG: stage2Loader: Filesystem loader is ${stage2Loader}"
61echo "DEBUG: targetVolumeTemp: Volume is ${targetVolumeTemp}"
62echo "DEBUG: targetDeviceTemp: Volume device is ${targetDeviceTemp}"
63echo "DEBUG: targetVolume: Volume is ${targetVolume}"
64echo "DEBUG: targetDevice: Volume device is ${targetDevice}"
65echo "DEBUG: targetDeviceRaw: Volume raw device is ${targetDeviceRaw}"
66echo "DEBUG: targetDisk: Disk device is ${targetDisk}"
67echo "DEBUG: targetDiskRaw: Disk raw device is ${targetDiskRaw}"
68echo "DEBUG: targetSlice: Volume slice is ${targetSlice}"
69echo "DEBUG: targetResources: Boot Resources is ${targetResources} - ????????????"
70echo "DEBUG: targetName: Volume name to look for is ${targetName} - ????????????"
71echo "-----------------------------------------------"
72echo ""
73
74
75# Check to see if the selected disk uses a GPT
76
77bootuuid=$( diskutil info "$targetDeviceTemp" | grep Volume\ UUID | awk {'print $3'} )
78partitiontable=$( diskutil list ${targetDeviceTemp%s*} | sed -n '3p' | awk '{print $2}' )
79
80if [ ${partitiontable} = "GUID_partition_scheme" ]; then
81echo "Confirm this is a GPT partitioned disk."
82
83# Double check we can see the selected partition and it's of the right type
84
85"$scriptDir"CheckProceed.sh "${targetVolumeTemp}" "${targetDeviceTemp}"
86returnValue=$?
87if [ ${returnValue} = 0 ]; then
88# OK to proceed
89
90
91# Does a GRUB or Linux loader already exist in the disk's MBR?
92
93"$scriptDir"CheckDiskMicrocodeType.sh "${targetDisk}"
94returnValue=$?
95if [ ${returnValue} = 0 ]; then
96# OK to proceed
97
98
99# check for a 4-byte Windows disk signature in the disk's MBR.
100# the following script returns 1 if a Windows disk signature exists, and 0 if not.
101
102"$scriptDir"CheckDiskSignature.sh "${targetDisk}"
103diskSigCheck=$?
104
105
106# check for existing bootloaders in the disk's MBR
107# and find out if we can write the Chameleon boot files.
108# the following script returns 1 if we can proceed
109# with writing the boot files, and 0 for not.
110
111"$scriptDir"CheckDiskMicrocode.sh "${targetDisk}" "${diskSigCheck}"
112diskupdate=$?
113
114
115# Cancelled this as all it does is read the GPTdiskProtectiveMBR
116# and the GPTdiskGPTHeader and look to see if they're blank
117
118
119#"$scriptDir"FindPartitionBootcode.sh "${targetDeviceRaw}"
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 1 then the stage 0 loader can be written to the MBR
148if [ ${diskupdate} = 1 ]; 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
162fi
163fi
164else
165echo
166echo "ERROR Volume is not on a GPT partitioned disc."
167echo
168fi
169
170exit 0
171

Archive Download this file

Revision: 232