Chameleon Applications

Chameleon Applications Svn Source Tree

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

  • Property svn:executable set to *
1#!/bin/bash
2
3echo "==============================================="
4echo "Main Standard 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
18# Check to see if the user selected both the standard and the
19# EFI system partition install options. If they did then let's
20# remove the nullESP file the installer would have added to the
21# temporary folder to stop the Stage 2 script trying to mount
22# /Volumes/EFI.
23
24if [ -f "${3}"/.Chameleon/nullESP ]; then
25echo "Note: User selected both install options - Removing temporary nullESP file to stop Stage 2 script trying to mount /Volumes/EFI"
26rm "${3}"/.Chameleon/nullESP
27echo ""
28fi
29
30
31
32#echo "==============================================="
33#echo "Apple Installer Package Variables"
34#echo "*********************************"
35#echo "DEBUG: $ 1 = Full path to the installation package the installer app is processing: " $1
36#echo "DEBUG: $ 2 = Full path to the installation destination: " $2
37#echo "DEBUG: $ 3 = Installation volume (mountpoint) to receive the payload: " $3
38#echo "DEBUG: $ 4 = Root directory for the system: " $4
39#echo "DEBUG: Script Name: " $SCRIPT_NAME
40#echo "DEBUG: Package Path: " $PACKAGE_PATH
41#echo "DEBUG: Installer Temp: " $INSTALLER_TEMP
42#echo "DEBUG: Full path to the temp directory containing the operation executable: " $RECEIPT_PATH
43#echo "-----------------------------------------------"
44#echo ""
45
46
47
48# Initialise Script Globals
49
50stage0Loader="boot0"
51stage0LoaderDualBoot="boot0hfs"
52stage1LoaderHFS="boot1h"
53stage1LoaderFAT="boot1f32"
54stage2Loader="boot"
55
56targetVolume=$3
57targetDevice=$( df "${targetVolume}" | sed -n '2p' | awk '{print $1}' )
58targetDeviceRaw=${targetDevice/disk/rdisk}
59targetDisk=${targetDevice%s*}
60targetDiskRaw=${targetDisk/disk/rdisk}
61targetSlice=${targetDevice#*disk*s}
62
63
64
65echo "==============================================="
66echo "DEBUG: display script variables"
67echo "*******************************"
68
69echo "DEBUG: stage0Loader: Disk loader is ${stage0Loader}"
70echo "DEBUG: stage0LoaderDualBoot: Disk loader is ${stage0LoaderDualBoot}"
71echo "DEBUG: stage1LoaderHFS: Partition loader is ${stage1LoaderHFS}"
72echo "DEBUG: stage1LoaderFat: Partition loader is ${stage1LoaderFAT}"
73echo "DEBUG: stage2Loader: Filesystem loader is ${stage2Loader}"
74echo "DEBUG: targetVolume: Volume is ${targetVolume}"
75echo "DEBUG: targetDevice: Volume device is ${targetDevice}"
76echo "DEBUG: targetDeviceRaw: Volume raw device is ${targetDeviceRaw}"
77echo "DEBUG: targetDisk: Disk device is ${targetDisk}"
78echo "DEBUG: targetDiskRaw: Disk raw device is ${targetDiskRaw}"
79echo "DEBUG: targetSlice: Volume slice is ${targetSlice}"
80echo "DEBUG: targetResources: Boot Resources is ${targetResources}"
81echo "-----------------------------------------------"
82echo ""
83
84
85
86# Double check we can see the selected partition and it's of the right type
87# if not the following script returns to indicate failure.
88
89"$scriptDir"CheckProceed.sh "${targetVolume}" "${targetDevice}"
90returnValue=$?
91if [ ${returnValue}=0 ]; then
92# OK to proceed
93
94
95# Does a GRUB or Linux loader already exist in the disk's MBR?
96# The script returns 1 if yes, 0 if no.
97
98"$scriptDir"CheckGRUBLinuxLoader.sh "${targetDisk}"
99returnValue=$?
100if [ ${returnValue} = 0 ]; then
101# OK to proceed
102
103
104# check for a 4-byte Windows disk signature in the disk's MBR.
105# the following script returns 1 if a Windows disk signature exists, and 0 if not.
106
107"$scriptDir"CheckWindowsDiskSignature.sh "${targetDisk}"
108diskSigCheck=$?
109
110
111# check for existing bootloaders in the disk's MBR
112# and find out if we can write the Chameleon boot files.
113# the following script returns 0 if we can proceed
114# with writing the boot files, and 1 for not.
115
116"$scriptDir"CheckDiskMicrocode.sh "${targetDisk}" "${diskSigCheck}"
117diskupdate=$?
118
119
120# check the format of the selected partition.
121# the following script returns 1 if HFS
122# the following script returns 2 if MSDOS
123# the following script returns 0 if nothing
124
125"$scriptDir"CheckFormat.sh "${targetDevice}"
126espformat=$?
127
128
129# check the partition scheme used for the selected disk.
130# the following script returns 1 if GPT
131# the following script returns 2 if GPT/MBR
132# the following script returns 3 if MBR
133# the following script returns 0 if nothing
134
135"$scriptDir"CheckPartitionScheme.sh "${targetDisk}"
136partitionTable=$?
137if [ ${partitionTable} = 3 ]; then
138# If MBR partition scheme then check for FAT16 or FAT32
139
140# the following script returns 1 if FAT16
141# the following script returns 2 if FAT32
142# the following script returns 0 if nothing
143
144"$scriptDir"CheckFatType.sh "${targetDeviceRaw}"
145fatType=$?
146fi
147
148if [ "${fatType}" = 1 ] && [ "${partitionTable}" = 3 ]; then
149echo "ERROR: - Can't install to a device using FAT16"
150# Write error to Chameleon_Error_Log file
151"$scriptDir"WriteInstallerLog.sh "${3}" "${3} is a FAT16 device - Chameleon boot files not written"
152else
153# Continue if the selected device is not a FAT16 format device
154
155# If diskupdate is flagged as 0 then the stage 0 loader can be written to the MBR
156if [ ${diskupdate} = 0 ]; then
157"$scriptDir"WriteChameleonStage0.sh "${diskupdate}" "${diskSigCheck}" "${stage0Loader}" "${stage0LoaderDualBoot}" "${targetDisk}" "${targetVolume}"
158fi
159
160# Write the stage 1 loader to the partition boot sector
161"$scriptDir"WriteChameleonStage1.sh "${espformat}" "${stage1LoaderHFS}" "${stage1LoaderFAT}" "${3}" "${targetDeviceRaw}" "${targetVolume}"
162
163# Write the stage 2 loader to the root of the selected partition
164"$scriptDir"WriteChameleonStage2.sh "${espformat}" "${stage2Loader}" "${3}" "${targetDevice}" "${targetVolume}"
165
166# Set the active partition ONLY if Windows is not installed
167"$scriptDir"SetActivePartition.sh "${espformat}" "${diskSigCheck}" "${targetDiskRaw}" "${targetSlice}" "${targetVolume}"
168fi
169else
170# Write error to Chameleon_Error_Log file
171"$scriptDir"WriteInstallerLog.sh "${targetVolume}" "Error: Target drive has existing GRUB / Linux loader in the MBR - Not sure how to continue"
172fi
173else
174# Write error to Chameleon_Error_Log file
175"$scriptDir"WriteInstallerLog.sh "${targetVolume}" "Error: ${targetVolume} couldn't be found or the disk doesn't use slices"
176fi
177
178exit 0
179

Archive Download this file

Revision: 258