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

Archive Download this file

Revision: 257