Chameleon

Chameleon Commit Details

Date:2011-09-26 17:31:24 (8 years 1 month ago)
Author:blackosx
Commit:1579
Parents: 1578
Message:Restructure Scripts folder.
Changes:
D/branches/blackosx/package/Scripts/Install
R/branches/blackosx/package/Scripts/Standard → /branches/blackosx/package/Scripts/Main/Standard
R/branches/blackosx/package/Scripts/EFI → /branches/blackosx/package/Scripts/Main/EFI
R/branches/blackosx/package/Scripts/Post → /branches/blackosx/package/Scripts/Main/Post
A/branches/blackosx/package/Scripts/Sub/SetActivePartition.sh
A/branches/blackosx/package/Scripts/Main
A/branches/blackosx/package/Scripts/Sub/CheckWindowsDiskSignature.sh
A/branches/blackosx/package/Scripts/Sub/CheckFormat.sh
A/branches/blackosx/package/Scripts/Sub
A/branches/blackosx/package/Scripts/Sub/CheckPartitionScheme.sh
A/branches/blackosx/package/Scripts/Sub/CheckGRUBLinuxLoader.sh
A/branches/blackosx/package/Scripts/Sub/UnMountEFIvolumes.sh
A/branches/blackosx/package/Scripts/Sub/InstallLog.sh
A/branches/blackosx/package/Scripts/Sub/WriteChameleonStage0.sh
A/branches/blackosx/package/Scripts/Sub/CheckFatType.sh
A/branches/blackosx/package/Scripts/Sub/WriteChameleonStage1.sh
A/branches/blackosx/package/Scripts/Sub/WriteChameleonStage2.sh
A/branches/blackosx/package/Scripts/Sub/CheckDiskMicrocode.sh
A/branches/blackosx/package/Scripts/Sub/CheckProceed.sh
M/branches/blackosx/package/buildpkg.sh

File differences

branches/blackosx/package/Scripts/Main/Standard/postinstall
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#!/bin/bash
echo "==============================================="
echo "Main Standard Post-Install Script"
echo "*********************************"
echo "-----------------------------------------------"
echo ""
# Find location of this script in the package installer
# so we know where all the other scripts are located.
MYLOCATION="${PWD}/${BASH_ARGV[0]}"
export MYLOCATION="${MYLOCATION%/*}"
scriptDir=$MYLOCATION
#echo "==============================================="
#echo "Apple Installer Package Variables"
#echo "*********************************"
#echo "DEBUG: $ 1 = Full path to the installation package the installer app is processing: " $1
#echo "DEBUG: $ 2 = Full path to the installation destination: " $2
#echo "DEBUG: $ 3 = Installation volume (mountpoint) to receive the payload: " $3
#echo "DEBUG: $ 4 = Root directory for the system: " $4
#echo "DEBUG: Script Name: " $SCRIPT_NAME
#echo "DEBUG: Package Path: " $PACKAGE_PATH
#echo "DEBUG: Installer Temp: " $INSTALLER_TEMP
#echo "DEBUG: Full path to the temp directory containing the operation executable: " $RECEIPT_PATH
#echo "-----------------------------------------------"
#echo ""
# Initialise Script Globals
stage0Loader="boot0"
stage0LoaderDualBoot="boot0md"
stage1LoaderHFS="boot1h"
stage1LoaderFAT="boot1f32"
stage2Loader="boot"
targetVolume=$3
targetDevice=$( df "${targetVolume}" | sed -n '2p' | awk '{print $1}' )
targetDeviceRaw=${targetDevice/disk/rdisk}
targetDisk=${targetDevice%s*}
targetDiskRaw=${targetDisk/disk/rdisk}
targetSlice=${targetDevice#*disk*s}
targetResources="${targetVolume}/usr/local/bin/"
echo "==============================================="
echo "DEBUG: display script variables"
echo "*******************************"
echo "DEBUG: stage0Loader: Disk loader is ${stage0Loader}"
echo "DEBUG: stage0LoaderDualBoot: Disk loader is ${stage0LoaderDualBoot}"
echo "DEBUG: stage1LoaderHFS: Partition loader is ${stage1LoaderHFS}"
echo "DEBUG: stage1LoaderFat: Partition loader is ${stage1LoaderFAT}"
echo "DEBUG: stage2Loader: Filesystem loader is ${stage2Loader}"
echo "DEBUG: targetVolume: Volume is ${targetVolume}"
echo "DEBUG: targetDevice: Volume device is ${targetDevice}"
echo "DEBUG: targetDeviceRaw: Volume raw device is ${targetDeviceRaw}"
echo "DEBUG: targetDisk: Disk device is ${targetDisk}"
echo "DEBUG: targetDiskRaw: Disk raw device is ${targetDiskRaw}"
echo "DEBUG: targetSlice: Volume slice is ${targetSlice}"
echo "DEBUG: targetResources: Boot Resources is ${targetResources}"
echo "-----------------------------------------------"
echo ""
# Write some information to the Install Log
versionNumber=`cat "${scriptDir}"/Resources/version`
revisionNumber=`cat "${scriptDir}"/Resources/revision`
"$scriptDir"InstallLog.sh "${targetVolume}" "Installer version: ${versionNumber} ${revisionNumber}"
"$scriptDir"InstallLog.sh "${targetVolume}" "Running Standard postinstall script
Target volume = ${targetVolume}"
# Double check we can see the selected partition and it's of the right type
# if not the following script returns to indicate failure.
"$scriptDir"CheckProceed.sh "${targetVolume}" "${targetDevice}" "${targetVolume}" "${scriptDir}"
returnValue=$?
if [ ${returnValue}=0 ]; then
# OK to proceed
# Does a GRUB or Linux loader already exist in the disk's MBR?
# The script returns 1 if yes, 0 if no.
"$scriptDir"CheckGRUBLinuxLoader.sh "${targetDisk}" "${targetVolume}" "${scriptDir}"
returnValue=$?
if [ ${returnValue} = 0 ]; then
# OK to proceed
# check for a 4-byte Windows disk signature in the disk's MBR.
# the following script returns 1 if a Windows disk signature exists, and 0 if not.
"$scriptDir"CheckWindowsDiskSignature.sh "${targetDisk}" "${targetVolume}" "${scriptDir}"
diskSigCheck=$?
# check for existing bootloaders in the disk's MBR
# and find out if we can write the Chameleon boot files.
# the following script returns 0 if we can proceed
# with writing the boot files, and 1 for not.
"$scriptDir"CheckDiskMicrocode.sh "${targetDisk}" "${diskSigCheck}" "${targetVolume}" "${scriptDir}"
diskupdate=$?
# check the format of the selected partition.
# the following script returns 1 if HFS
# the following script returns 2 if MSDOS
# the following script returns 0 if nothing
"$scriptDir"CheckFormat.sh "${targetDevice}" "${targetVolume}" "${scriptDir}"
espformat=$?
# check the partition scheme used for the selected disk.
# the following script returns 1 if GPT
# the following script returns 2 if GPT/MBR
# the following script returns 3 if MBR
# the following script returns 0 if nothing
"$scriptDir"CheckPartitionScheme.sh "${targetDisk}" "${targetVolume}" "${scriptDir}"
partitionTable=$?
if [ ${partitionTable} = 3 ]; then
# If MBR partition scheme then check for FAT16 or FAT32
# the following script returns 1 if FAT16
# the following script returns 2 if FAT32
# the following script returns 0 if nothing
"$scriptDir"CheckFatType.sh "${targetDeviceRaw}" "${targetVolume}" "${scriptDir}"
fatType=$?
fi
if [ "${fatType}" = 1 ] && [ "${partitionTable}" = 3 ]; then
echo "ERROR: - Can't install to a device using FAT16"
# Write error to Chameleon_Error_Log file
"$scriptDir"InstallLog.sh "${targetVolume}" "FAIL: Cannot install to a device using FAT16"
else
# Continue if the selected device is not a FAT16 format device
# Append a line break to the installer log
"$scriptDir"InstallLog.sh "${targetVolume}" "Line Break"
if [ ${diskupdate} = "0" ]; then
# Write the stage 0 loader to the MBR
"$scriptDir"WriteChameleonStage0.sh "${diskSigCheck}" "${stage0Loader}" "${stage0LoaderDualBoot}" "${targetDisk}" "${targetResources}" "${targetVolume}" "${scriptDir}"
else
#echo "Diskupdate = false, so didn't write the stage 0 loader to the MBR."
"$scriptDir"InstallLog.sh "${targetVolume}" "Stage 0 loader not written to ${targetDisk}."
fi
# Write the stage 1 loader to the partition boot sector
"$scriptDir"WriteChameleonStage1.sh "${espformat}" "${stage1LoaderHFS}" "${stage1LoaderFAT}" "${3}" "${targetDeviceRaw}" "${targetVolume}" "${scriptDir}"
# Write the stage 2 loader to the root of the selected partition
"$scriptDir"WriteChameleonStage2.sh "${espformat}" "${stage2Loader}" "${3}" "${targetDevice}" "${targetVolume}" "${scriptDir}"
# Append a line break to the installer log
"$scriptDir"InstallLog.sh "${targetVolume}" "Line Break"
# Set the active partition ONLY if Windows is not installed
"$scriptDir"SetActivePartition.sh "${espformat}" "${diskSigCheck}" "${targetDiskRaw}" "${targetSlice}" "${targetVolume}" "${scriptDir}"
fi
fi
fi
"$scriptDir"InstallLog.sh "${targetVolume}" "Line Break"
"$scriptDir"InstallLog.sh "${targetVolume}" "Standard script complete"
echo "==============================================="
echo "END - Standard Post-Install Script"
echo "*********************************"
echo "-----------------------------------------------"
echo ""
exit 0
branches/blackosx/package/Scripts/Main/EFI/postinstall
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
#!/bin/bash
echo "==============================================="
echo "Main EFI System Partition Post-Install Script"
echo "*********************************************"
echo "-----------------------------------------------"
echo ""
# Find location of this script in the package installer
# so we know where all the other scripts are located.
MYLOCATION="${PWD}/${BASH_ARGV[0]}"
export MYLOCATION="${MYLOCATION%/*}"
scriptDir=$MYLOCATION
#echo "==============================================="
#echo "Apple Installer Package Variables"
#echo "*********************************"
#echo "DEBUG: $ 1 = Full path to the installation package the installer app is processing: " $1
#echo "DEBUG: $ 2 = Full path to the installation destination: " $2
#echo "DEBUG: $ 3 = Installation volume (mountpoint) to receive the payload: " $3
#echo "DEBUG: $ 4 = Root directory for the system: " $4
#echo "DEBUG: Script Name: " $SCRIPT_NAME
#echo "DEBUG: Package Path: " $PACKAGE_PATH
#echo "DEBUG: Installer Temp: " $INSTALLER_TEMP
#echo "DEBUG: Full path to the temp directory containing the operation executable: " $RECEIPT_PATH
#echo "-----------------------------------------------"
#echo ""
# Initialise Script Globals
stage0Loader="boot0"
stage0LoaderDualBoot="boot0md"
stage1LoaderHFS="boot1h"
stage1LoaderFAT="boot1f32"
stage2Loader="boot"
targetVolumeChosenByUser=$3
targetDeviceChosenByUser=$( df "${targetVolumeChosenByUser}" | sed -n '2p' | awk '{print $1}' )
targetVolume="/Volumes/EFI"
targetDevice=${targetDeviceChosenByUser%s*}s1
targetDeviceRaw=${targetDevice/disk/rdisk}
targetDisk=${targetDevice%s*}
targetDiskRaw=${targetDisk/disk/rdisk}
targetSlice=${targetDevice#*disk*s}
targetResources="${targetVolumeChosenByUser}/usr/local/bin/"
echo "==============================================="
echo "DEBUG: display script variables"
echo "***************************"
echo "DEBUG: stage0Loader: Disk loader is ${stage0Loader}"
echo "DEBUG: stage0LoaderDualBoot: Disk loader is ${stage0LoaderDualBoot}"
echo "DEBUG: stage1LoaderHFS: Partition loader is ${stage1LoaderHFS}"
echo "DEBUG: stage1LoaderFat: Partition loader is ${stage1LoaderFAT}"
echo "DEBUG: stage2Loader: Filesystem loader is ${stage2Loader}"
echo "DEBUG: targetVolumeChosenByUser: Volume is ${targetVolumeChosenByUser}"
echo "DEBUG: targetDeviceChosenByUser: Volume device is ${targetDeviceChosenByUser}"
echo "DEBUG: targetVolume: Volume is ${targetVolume}"
echo "DEBUG: targetDevice: Volume device is ${targetDevice}"
echo "DEBUG: targetDeviceRaw: Volume raw device is ${targetDeviceRaw}"
echo "DEBUG: targetDisk: Disk device is ${targetDisk}"
echo "DEBUG: targetDiskRaw: Disk raw device is ${targetDiskRaw}"
echo "DEBUG: targetSlice: Volume slice is ${targetSlice}"
echo "DEBUG: targetResources: Boot Resources is ${targetResources}"
echo "-----------------------------------------------"
echo ""
# Write some information to the Install Log
versionNumber=`cat "${scriptDir}"/Resources/version`
revisionNumber=`cat "${scriptDir}"/Resources/revision`
"$scriptDir"InstallLog.sh "${targetVolumeChosenByUser}" "Installer version: ${versionNumber} ${revisionNumber}"
"$scriptDir"InstallLog.sh "${targetVolumeChosenByUser}" "Running EFI postinstall script
Target volume selected by user = ${targetVolumeChosenByUser}
Target volume = ${targetVolume}"
# Check to see if the selected disk uses a GPT
bootuuid=$( diskutil info "$targetDeviceChosenByUser" | grep Volume\ UUID | awk {'print $3'} )
partitiontable=$( diskutil list ${targetDeviceChosenByUser%s*} | sed -n '3p' | awk '{print $2}' )
if [ ${partitiontable} = "GUID_partition_scheme" ]; then
echo "Confirm this is a GPT partitioned disk."
# Double check we can see the selected partition, it's of the right type and /Volumes/TempChamESP exists.
"$scriptDir"CheckProceed.sh "${targetVolume}" "${targetDeviceChosenByUser}" "${targetVolumeChosenByUser}" "${scriptDir}"
returnValue=$?
if [ ${returnValue} = 0 ]; then
# OK to proceed
# Does a GRUB or Linux loader already exist in the disk's MBR?
# The script returns 1 if yes, 0 if no.
"$scriptDir"CheckGRUBLinuxLoader.sh "${targetDisk}" "${targetVolumeChosenByUser}" "${scriptDir}"
returnValue=$?
if [ ${returnValue} = 0 ]; then
# OK to proceed
# check for a 4-byte Windows disk signature in the disk's MBR.
# the following script returns 1 if a Windows disk signature exists, and 0 if not.
"$scriptDir"CheckWindowsDiskSignature.sh "${targetDisk}" "${targetVolumeChosenByUser}" "${scriptDir}"
diskSigCheck=$?
# check for existing bootloaders in the disk's MBR
# and find out if we can write the Chameleon boot files.
# the following script returns 0 if we can proceed
# with writing the boot files, and 1 for not.
"$scriptDir"CheckDiskMicrocode.sh "${targetDisk}" "${diskSigCheck}" "${targetVolumeChosenByUser}" "${scriptDir}"
diskupdate=$?
# check the format of the selected partition.
# the following script returns 1 if HFS
# the following script returns 2 if MSDOS
# the following script returns 0 if nothing - **** the script shouldn't continue here??? as the partition is not formatted as either HFS or msdos??? ****
"$scriptDir"CheckFormat.sh "${targetDevice}" "${targetVolumeChosenByUser}" "${scriptDir}"
espformat=$?
# Determine the partition scheme of the selected disk
# is it GPT or a hybrid GPT/MBR
"$scriptDir"CheckPartitionScheme.sh "${targetDisk}" "${targetVolumeChosenByUser}" "${scriptDir}"
# Unmount ALL mounted volumes named EFI
# the following script returns 0 if it succeeds
# the following script returns 1 if it fails to un-mount any EFI volume
"$scriptDir"UnMountEFIvolumes.sh "${targetVolumeChosenByUser}" "${scriptDir}"
returnValue=$?
if [ ${returnValue} = 0 ]; then
# OK to proceed
# Append a line break to the installer log
"$scriptDir"InstallLog.sh "${targetVolumeChosenByUser}" "Line Break"
if [ ${diskupdate} = "0" ]; then
#echo "Diskupdate = true, so the stage 0 loader can be written to the MBR"
# Write the stage 0 loader to the MBR
"$scriptDir"WriteChameleonStage0.sh "${diskSigCheck}" "${stage0Loader}" "${stage0LoaderDualBoot}" "${targetDisk}" "${targetResources}" "${targetVolumeChosenByUser}" "${scriptDir}"
else
#echo "Diskupdate = false, so didn't write the stage 0 loader to the MBR."
"$scriptDir"InstallLog.sh "${targetVolumeChosenByUser}" "Stage 0 loader not written to ${targetDisk}."
fi
# Write the stage 1 loader to the partition boot sector
"$scriptDir"WriteChameleonStage1.sh "${espformat}" "${stage1LoaderHFS}" "${stage1LoaderFAT}" "${targetVolumeChosenByUser}" "${targetDeviceRaw}" "${targetVolumeChosenByUser}" "${scriptDir}"
# Write the stage 2 loader to the root of the selected partition
"$scriptDir"WriteChameleonStage2.sh "${espformat}" "${stage2Loader}" "${targetVolume}" "${targetDevice}" "${targetVolumeChosenByUser}" "${scriptDir}"
# Append a line break to the installer log
"$scriptDir"InstallLog.sh "${targetVolumeChosenByUser}" "Line Break"
# Set the active partition ONLY if Windows is not installed
"$scriptDir"SetActivePartition.sh "${espformat}" "${diskSigCheck}" "${targetDiskRaw}" "${targetSlice}" "${targetVolumeChosenByUser}" "${scriptDir}"
fi
fi
fi
else
#echo "ERROR Volume is not on a GPT partitioned disc."
"$scriptDir"InstallLog.sh "${targetVolumeChosenByUser}" "ERROR Volume is not on a GPT partitioned disc."
fi
# remove the temporary boot sector files if they exist
if [ -d /tmp/newbs ]; then
echo "Executing command: rm /tmp/newbs"
rm /tmp/newbs
fi
if [ -d /tmp/origbs ]; then
echo "Executing command: rm /tmp/origbs"
rm /tmp/origbs
fi
# Check for mounted volumes named EFI and if found, unmount
#"$scriptDir"UnMountEFIvolumes.sh - ***** commented out to allow the boot option scripts to function ****
# Create temporary file on target volume to notify
# boot option scripts than EFI (ESP) option was chosen
echo "EFI" >"${targetVolumeChosenByUser}"/.ChameleonEFI
"$scriptDir"InstallLog.sh "${targetVolumeChosenByUser}" "Line Break"
"$scriptDir"InstallLog.sh "${targetVolumeChosenByUser}" "EFI script complete"
echo "==============================================="
echo "END - Main EFI System Partition Post-Install Script"
echo "*********************************************"
echo "-----------------------------------------------"
echo ""
exit 0
branches/blackosx/package/Scripts/Main/Post/postinstall
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/bin/bash
#
# $1: the full path to the installation package; for example:
# /Volumes/Projects/Testing/Simple_Carbon_App.pkg
#
# $2: the full path to the installation destination; for example:
# /Applications
#
# $3: the mountpoint of the destination volume; for example:
# / or /Volumes/External_Drive
#
# $4: the root directory for the current System folder:
# /
echo "preinstall: Path to installer....... $1"
echo "preinstall: Path to destination..... $2"
echo "preinstall: Path to dest volume..... $3"
echo "preinstall: Root of system folder... $4"
#set -x # Useful for echoing everything the script does to the installer log!!
if [ ! -e "$3" ]
then
echo "$3 volume does not exist!"
exit 1
fi
# clean up what would otherwise turn into "//" paths
if [ "$3" == "/" ]
then
dest_vol=""
else
dest_vol="$3"
fi
# set temporary directory
chamTemp="$dest_vol/usr/local/chamTemp" #blackosx added
# Check for temporary directory/Extra folder.
if [ ! -d "$chamTemp"/Extra ]; then
mkdir "$chamTemp"/Extra
fi
# ---------------------------------------------
# Blackosx - Build boot options / Kernel Flags.
# NEEDS MORE WORK!!!!!!!!!!!!
# ---------------------------------------------
# All options selected are now dummy files with
# the filename of the option and value residing
# in /usr/local/chamTemp/options/
# for example. Boot Banner=Yes
# Create template for org.chameleon.Boot.plist"
tempOCBP="$chamTemp"/Extra/org.chameleon.Boot.plist
cp "$dest_vol"/Library/Preferences/SystemConfiguration/com.apple.Boot.plist "$tempOCBP"
# Read list of all boot options the user added.
arrayCount=0
find ${chamTemp}/options | while read FILE
do
options[arrayCount]="${FILE##*/}"
keyRead="${options[$arrayCount]%=*}"
value="${options[$arrayCount]#*=}"
# Check keyRead for 'KF' at beginning to
# indicate that should be a kernel flag
if [ ${keyRead:0:2} = "KF" ];then
kernelflag=${keyRead#*F }=$value
# write value to org.chameleon.Boot.plist
# but skip first one as that will be 'options'
if [ $arrayCount -gt 0 ]; then
sudo /usr/libexec/plistbuddy -c "Add :Kernel\ Flags string $kernelflag" "$tempOCBP"
fi
else
# escape any spaces
keyToUse=$( echo $keyRead | sed 's/ /\\ /g' )
# write value to org.chameleon.Boot.plist
# but skip first one as that will be 'options'
if [ $arrayCount -gt 0 ]; then
sudo /usr/libexec/plistbuddy -c "Add :$keyToUse string $value" "$tempOCBP"
fi
fi
arrayCount=$(( ${arrayCount} + 1 ))
done
# ---------------------------------------------
# Copy temp Extra folder to target destination
# ---------------------------------------------
# Extra folder now resides in /usr/local/chamTemp/
# Copy /usr/local/chamTemp/Extra to correct location.
if [ ! -f "$dest_vol"/.ChameleonEFI ]; then
if [ ! -f "$dest_vol"/Extra ]; then
mkdir "$dest_vol"/Extra
fi
cp -R "$chamTemp"/Extra/* "$dest_vol"/Extra
else
if [ ! -f "/Volumes/EFI/Extra" ]; then
mkdir "/Volumes/EFI/Extra"
fi
cp -R "$chamTemp"/Extra/* /Volumes/EFI/Extra
# unmount /Volumes/EFI
attempts=1
while [ "$( df | grep EFI )" ] && [ "${attempts}" -lt 5 ]; do
echo "Unmounting $( df | grep EFI | awk '{print $1}' )"
umount -f $( df | grep EFI | awk '{print $1}' )
attempts=$(( ${attempts} + 1 ))
done
fi
# ---------------------------------------------
# Cleanup
# ---------------------------------------------
# Remove /.ChameleonEFI file
if [ -f "$dest_vol"/.ChameleonEFI ]; then
echo "Removing /.ChameleonEFI file"
rm "$dest_vol"/.ChameleonEFI
fi
# Remove /.ChameleonLogFlag file
if [ -f "$dest_vol"/.ChameleonLogFlag ]; then
echo "Removing /.ChameleonLogFlag file"
rm "$dest_vol"/.ChameleonLogFlag
fi
# delete the temporary Chameleon folder
echo "Removing $chamTemp file"
rm -rf "$chamTemp"
echo "Done..."
branches/blackosx/package/Scripts/Sub/CheckFormat.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/bash
echo "==============================================="
echo "CheckFormat: Is target HFS or MSDOS?"
echo "**********************************************"
# if the selected partition is formatted as HFS then exit with 1
# if the selected partition is formatted as MSDOS then exit with 2
# if fstyp doesn't return a value then exit with 0
# Receives targetDevice: for example, /dev/disk0s2
# Receives targetVolume: Volume to install to.
# Receives scriptDir: The location of the main script dir.
if [ "$#" -eq 3 ]; then
targetDevice="$1"
targetVolume="$2"
scriptDir="$3"
echo "DEBUG: passed argument for targetDevice = $targetDevice"
echo "DEBUG: passed argument for targetVolume = $targetVolume"
echo "DEBUG: passed argument for scriptDir = $scriptDir"
else
echo "Error - wrong number of values passed"
exit 9
fi
if [ "$( fstyp "$targetDevice" | grep hfs )" ]; then
echo "${targetDevice} is currently formatted as HFS"
echo "-----------------------------------------------"
echo ""
#"$scriptDir"InstallLog.sh "${targetVolume}" "${targetDevice} is currently formatted as HFS"
exit 1
fi
if [ "$( fstyp "$targetDevice" | grep msdos )" ]; then
echo "${targetDevice} is currently formatted as msdos"
echo "-----------------------------------------------"
echo ""
#"$scriptDir"InstallLog.sh "${targetVolume}" "${targetDevice} is currently formatted as msdos"
exit 2
fi
echo "WARNING: ${targetDevice} is currently not formatted as either HFS or msdos"
echo "-----------------------------------------------"
echo ""
"$scriptDir"InstallLog.sh "${targetVolume}" "WARNING: ${targetDevice} is currently not formatted as either HFS or msdos"
exit 0
branches/blackosx/package/Scripts/Sub/InstallLog.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/bin/bash
echo "==============================================="
echo "InstallLog: Create/Append installation log"
echo "**********************************************"
# Creates text file named 'Chameleon_Installer_Log.txt'
# at the root of the target volume. This is to help show the
# user why the installation process failed (even though the
# package installer ends reading 'Installation Successful'.
# Receives two parameters
# $1 = selected volume for location of the install log
# $2 = text to write to the installer log
if [ "$#" -eq 2 ]; then
logLocation="$1"
verboseText="$2"
echo "DEBUG: passed argument = $logLocation"
echo "DEBUG: passed argument = $verboseText"
else
echo "Error - wrong number of values passed"
exit 9
fi
logName="Chameleon_Installer_Log.txt"
logFile="${logLocation}"/$logName
# On first run, create a file named .ChameleonLogFlag at
# the root of the target volume. Then check for this file
# on subsequent runs to know the initialisation sequence
# has been done.
if [ ! -f "${logLocation}"/.ChameleonLogFlag ]; then
# This is the first run, so setup
# Chameleon_Installer_Log.txt file
# by writing header.
# Also include the first message that this script
# would be called with which will be version/revision
# of Chameleon package.
echo "Chameleon installer log - $( date )
${verboseText}
======================================================
" >"${logFile}"
diskutil list >>"${logFile}"
echo "
======================================================
" >>"${logFile}"
# Create /.ChameleonLogFlag file.
echo "Log" >"${logLocation}"/.ChameleonLogFlag
else
# Append messages to the log as passed by other scripts.
if [ "${verboseText}" = "Line Break" ]; then
echo "
======================================================
" >>"${logFile}"
fi
if [[ "${verboseText}" == *fdisk* ]]; then
targetDiskRaw="${verboseText#fdisk *}"
fdisk $targetDiskRaw >>"${logFile}"
echo " " >>"${logFile}"
fi
if [ "${verboseText}" != "Line Break" ] && [[ "${verboseText}" != *fdisk* ]]; then
echo "${verboseText}" >> "${logFile}"
fi
fi
exit 0
branches/blackosx/package/Scripts/Sub/CheckFatType.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/bin/bash
echo "==============================================="
echo "CheckFatType: Do we have FAT16 or FAT32?"
echo "****************************************"
# Looks for the following in the partition boot sector
# Byte number 19 to see if it's either 00 or 02
# Byte number 22 to see if it's either F8 or F0
# Byte number 25 to see if it's either 3F or 20
#
# Exit with value 1 for FAT16, 2 for FAT32
# Exit with value 0 if nothing is found - this shouldn't happen.?
# Receives targetDeviceRaw: for example, /dev/rdisk0s2.
# Receives targetVolume: Volume to install to.
# Receives scriptDir: The location of the main script dir.
if [ "$#" -eq 3 ]; then
targetDeviceRaw="$1"
targetVolume="$2"
scriptDir="$3"
echo "DEBUG: passed argument = $targetDeviceRaw"
echo "DEBUG: passed argument for targetVolume = $targetVolume"
echo "DEBUG: passed argument for scriptDir = $scriptDir"
else
echo "Error - wrong number of values passed"
exit 9
fi
partitionBootSector=$( dd 2>/dev/null if="$targetDeviceRaw" count=1 | perl -ne '@a=split"";for(@a){printf"%02x",ord}' )
if [ "${partitionBootSector:36:2}" == "00" ] && [ "${partitionBootSector:42:2}" == "f8" ] && [ "${partitionBootSector:48:2}" == "3f" ]; then
echo "Found a FAT32 device formatted by Windows Explorer"
echo "--------------------------------------------------"
echo ""
"$scriptDir"InstallLog.sh "${targetVolume}" "${targetDeviceRaw} is on a FAT32 volume formatted by Windows Explorer"
exit 2
fi
if [ "${partitionBootSector:36:2}" == "02" ] && [ "${partitionBootSector:42:2}" == "f8" ] && [ "${partitionBootSector:48:2}" == "3f" ]; then
echo "Found a FAT16 device formatted by Windows Explorer"
echo "--------------------------------------------------"
echo ""
"$scriptDir"InstallLog.sh "${targetVolume}" "${targetDeviceRaw} is on a FAT16 volume formatted by Windows Explorer"
exit 1
fi
if [ "${partitionBootSector:36:2}" == "00" ] && [ "${partitionBootSector:42:2}" == "f0" ] && [ "${partitionBootSector:48:2}" == "20" ]; then
echo "Found a FAT32 device formatted by OS X Snow Leopard Disk Utility"
echo "----------------------------------------------------------------"
echo ""
"$scriptDir"InstallLog.sh "${targetVolume}" "${targetDeviceRaw} is on a FAT32 volume formatted by OS X Snow Leopard Disk Utility"
exit 2
fi
if [ "${partitionBootSector:36:2}" == "02" ] && [ "${partitionBootSector:42:2}" == "f0" ] && [ "${partitionBootSector:48:2}" == "20" ]; then
echo "Found a FAT16 device formatted by OS X Snow Leopard Disk Utility"
echo "----------------------------------------------------------------"
echo ""
"$scriptDir"InstallLog.sh "${targetVolume}" "${targetDeviceRaw} is on a FAT16 volume formatted by OS X Snow Leopard Disk Utility"
exit 1
fi
if [ "${partitionBootSector:36:2}" == "00" ] && [ "${partitionBootSector:42:2}" == "f8" ] && [ "${partitionBootSector:48:2}" == "20" ]; then
echo "Found a FAT32 device formatted by OS X Lion Disk Utility"
echo "--------------------------------------------------------"
echo ""
"$scriptDir"InstallLog.sh "${targetVolume}" "${targetDeviceRaw} is on a FAT32 volume formatted by OS X Lion Disk Utility"
exit 2
fi
if [ "${partitionBootSector:36:2}" == "02" ] && [ "${partitionBootSector:42:2}" == "f8" ] && [ "${partitionBootSector:48:2}" == "20" ]; then
echo "Found a FAT16 device formatted by OS X Lion Disk Utility"
echo "--------------------------------------------------------"
echo ""
"$scriptDir"InstallLog.sh "${targetVolume}" "${targetDeviceRaw} is on a FAT16 volume formatted by OS X Lion Disk Utility"
exit 1
fi
echo "-----------------------------------------------"
echo ""
exit 0
branches/blackosx/package/Scripts/Sub/WriteChameleonStage0.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/bash
echo "==============================================="
echo "Write Chameleon Stage 0 Loader:"
echo "*******************************"
# Writes Chameleon stage 0 loader.
# Receives disksignature: 0 = Windows not found, 1 = Windows Found
# Receives stage0Loader: for example, boot0
# Receives stage0Loaderdualboot: for example, boot0md
# Receives targetDisk: for example, /dev/disk3
# Receives targetResources: location of fdisk440
# Receives targetVolume: for example, /Volumes/USB
# Receives scriptDir: The location of the main script dir.
if [ "$#" -eq 7 ]; then
disksignature="$1"
stage0Loader="$2"
stage0Loaderdualboot="$3"
targetDisk="$4"
targetResources="$5"
targetVolume="$6"
scriptDir="$7"
echo "DEBUG: passed argument for disksignature = $disksignature"
echo "DEBUG: passed argument for stage0Loader = $stage0Loader"
echo "DEBUG: passed argument for stage0Loaderdualboot = $stage0Loaderdualboot"
echo "DEBUG: passed argument for targetDisk = $targetDisk"
echo "DEBUG: passed argument for targetResources = $targetResources"
echo "DEBUG: passed argument for targetVolume = $targetVolume"
echo "DEBUG: passed argument for scriptDir = $scriptDir"
else
echo "Error - wrong number of values passed"
exit 9
fi
if [ ${disksignature} = "0" ]; then
echo "Executing command: ${targetResources}fdisk440 -u -f /usr/standalone/i386/${stage0Loader} -y ${targetDisk}"
"${targetResources}"fdisk440 -u -f "${targetVolume}"/usr/standalone/i386/${stage0Loader} -y ${targetDisk}
"$scriptDir"InstallLog.sh "${targetVolume}" "Written ${stage0Loader} to ${targetDisk}."
else
# Windows is also installed on the HDD so we need to write boot0md
echo "Executing command: ${targetResources}fdisk440 -u -f /usr/standalone/i386/${stage0Loaderdualboot} -y ${targetDisk}"
"${targetResources}"fdisk440 -u -f "${targetVolume}"/usr/standalone/i386/${stage0Loaderdualboot} -y ${targetDisk}
"$scriptDir"InstallLog.sh "${targetVolume}" "Written ${stage0Loaderdualboot} to ${targetDisk}."
fi
echo "-----------------------------------------------"
echo ""
echo ""
exit 0
branches/blackosx/package/Scripts/Sub/WriteChameleonStage1.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/bash
echo "==============================================="
echo "Write Chameleon Stage 1 Loader:"
echo "*******************************"
# Writes Chameleon stage 1 loader.
# Receives espformat: 1 for HFS, 2 for MSDOS, 0 for unknown
# Receives stage1LoaderHFS: Name of file - boot1h
# Receives stage1LoaderFAT: Name of file - boot1f32
# Receives selectedDestination: for example, /Volumes/USB
# Receives targetDeviceRaw: for example, /dev/disk3s1
# Receives targetVolume: for example, /Volumes/USB
# Receives scriptDir: The location of the main script dir.
if [ "$#" -eq 7 ]; then
espformat="$1"
stage1LoaderHFS="$2"
stage1LoaderFAT="$3"
selectedDestination="$4"
targetDeviceRaw="$5"
targetVolume="$6"
scriptDir="$7"
echo "DEBUG: passed argument for espformat = $espformat"
echo "DEBUG: passed argument for stage1LoaderHFS = $stage1LoaderHFS"
echo "DEBUG: passed argument for stage1LoaderFAT = $stage1LoaderFAT"
echo "DEBUG: passed argument for selectedDestination = $selectedDestination"
echo "DEBUG: passed argument for targetDeviceRaw = $targetDeviceRaw"
echo "DEBUG: passed argument for targetVolume = $targetVolume"
echo "DEBUG: passed argument for scriptDir = $scriptDir"
else
echo "Error - wrong number of values passed"
exit 9
fi
if [ ${espformat} = "1" ]; then
# the selected partition is HFS formatted
echo "Executing command: dd if=${selectedDestination}/usr/standalone/i386/${stage1LoaderHFS} of=${targetDeviceRaw}"
dd if="${selectedDestination}"/usr/standalone/i386/${stage1LoaderHFS} of=${targetDeviceRaw}
"$scriptDir"InstallLog.sh "${targetVolume}" "Written ${stage1LoaderHFS} to ${targetDeviceRaw}."
fi
if [ ${espformat} = "2" ]; then
# the selected partition FAT formatted
echo "Executing command: dd if=${targetDeviceRaw} count=1 bs=512 of=/tmp/origbs"
dd if=${targetDeviceRaw} count=1 bs=512 of=/tmp/origbs
echo "Executing command: cp "${selectedDestination}"/usr/standalone/i386/${stage1LoaderFAT} /tmp/newbs"
cp "${selectedDestination}"/usr/standalone/i386/${stage1LoaderFAT} /tmp/newbs
echo "Executing command: dd if=/tmp/origbs of=/tmp/newbs skip=3 seek=3 bs=1 count=87 conv=notrunc"
dd if=/tmp/origbs of=/tmp/newbs skip=3 seek=3 bs=1 count=87 conv=notrunc
echo "Executing command: dd of=${targetDeviceRaw} count=1 bs=512 if=/tmp/newbs"
dd if=/tmp/newbs of="${targetDeviceRaw}" count=1 bs=512
"$scriptDir"InstallLog.sh "${targetVolume}" "Written ${stage1LoaderFAT} to ${targetDeviceRaw}."
fi
echo "-----------------------------------------------"
echo ""
exit 0
branches/blackosx/package/Scripts/Sub/CheckPartitionScheme.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/bash
echo "==============================================="
echo "Check the Partition Scheme: GPT, GPT/MBR or MBR?"
echo "************************************************"
# Looks for the first 8 bytes of the GPTdiskGPTHeader to identify a GUID partition table.
# Byte number 450 of the GPTdiskProtectiveMBR to identify ID of 'EE' to identify a GPT partition.
# Byte numbers 466, 482 & 498 of the GPTdiskProtectiveMBR to identify further partitions.
#
# Exit with value 1 for GPT, 2 for GPT/MBR and 3 for MBR.
# Exit with value 0 if nothing is found - this shouldn't happen.?
# Receives targetDisk: for example, /dev/disk0s2
# Receives targetVolume: Volume to install to.
# Receives scriptDir: The location of the main script dir.
if [ "$#" -eq 3 ]; then
targetDisk="$1"
targetVolume="$2"
scriptDir="$3"
echo "DEBUG: passed argument = $targetDisk"
echo "DEBUG: passed argument for targetVolume = $targetVolume"
echo "DEBUG: passed argument for scriptDir = $scriptDir"
else
echo "Error - wrong number of values passed"
exit 9
fi
partitiontable=$( dd 2>/dev/null if="$targetDisk" count=1 skip=1 | dd 2>/dev/null count=8 bs=1 | perl -ne '@a=split"";for(@a){printf"%02x",ord}' )
if [ "${partitiontable:0:16}" == "4546492050415254" ]; then
partitiontable=$( dd 2>/dev/null if="$targetDisk" count=1 | dd 2>/dev/null count=64 bs=1 skip=446 | perl -ne '@a=split"";for(@a){printf"%02x",ord}' )
if [ "${partitiontable:8:2}" == "ee" ]; then
echo "Found System ID 'EE' to identify GPT Partition"
if [ "${partitiontable:40:2}" == "00" ] && [ "${partitiontable:72:2}" == "00" ] && [ "${partitiontable:104:2}" == "00" ]; then
echo "Found System ID '00' for each remaining possible partition"
partitiontable="GPT"
echo "${partitiontable} found."
echo "-----------------------------------------------"
echo ""
#"$scriptDir"InstallLog.sh "${targetVolume}" "${targetDisk} is using a GPT."
exit 1
else
partitiontable="GPT/MBR"
echo "${partitiontable} found."
echo "-----------------------------------------------"
echo ""
#"$scriptDir"InstallLog.sh "${targetVolume}" "${targetDisk} is using a GPT/MBR."
exit 2
fi
fi
else
partitiontable="MBR"
echo "${partitiontable} found."
echo "-----------------------------------------------"
echo ""
#"$scriptDir"InstallLog.sh "${targetVolume}" "${targetDisk} is using MBR."
exit 3
fi
echo "No partition table found."
echo "-----------------------------------------------"
echo ""
"$scriptDir"InstallLog.sh "${targetVolume}" "NOTE: No partition table found."
exit 0
branches/blackosx/package/Scripts/Sub/WriteChameleonStage2.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/bash
echo "==============================================="
echo "Write Chameleon Stage 2 Loader:"
echo "*******************************"
# Writes Chameleon stage 2 loader.
# Receives espformat: 1 for HFS, 2 for MSDOS, 0 for unknown
# Receives stage2Loader: Name of file - boot
# Receives selectedDestination: for example, /Volumes/USB
# Receives targetDevice: for example, /dev/disk3s1
# Receives targetVolume: for example, /Volumes/USB
# Receives scriptDir: The location of the main script dir.
if [ "$#" -eq 6 ]; then
espformat="$1"
stage2Loader="$2"
selectedDestination="$3"
targetDevice="$4"
targetVolume="$5"
scriptDir="$6"
echo "DEBUG: passed argument for espformat = $espformat"
echo "DEBUG: passed argument for stage2Loader = $stage2Loader"
echo "DEBUG: passed argument for selectedDestination = $selectedDestination"
echo "DEBUG: passed argument for targetDevice = $targetDevice"
echo "DEBUG: passed argument for targetVolume = $targetVolume"
echo "DEBUG: passed argument for scriptDir = $scriptDir"
else
echo "Error - wrong number of values passed"
exit 9
fi
# check to see if install to EFI system partition was selected
if [ "${selectedDestination}" = "/Volumes/EFI" ]; then
echo "DEBUG: EFI install chosen"
if [ ! -d "${selectedDestination}" ]; then
echo "Executing Command: mkdir -p ${selectedDestination}"
mkdir -p "${targetVolume}"
else
echo "DEBUG: folder /Volumes/EFI already exists"
fi
#if the EFI system partition was selected then
# mount '/Volumes/EFI' with the correct format type
if [ ${espformat} = 1 ]; then
echo "Executing command: mount_hfs ${targetDevice} ${targetVolume}"
mount_hfs "${targetDevice}" "${targetVolume}"
fi
if [ ${espformat} = 2 ]; then
[ -d "${selectedDestination}" ] || mkdir -p "${selectedDestination}"
echo "Executing command: mount_msdos -u 0 -g 0 ${targetDevice} ${selectedDestination}"
mount_msdos -u 0 -g 0 "${targetDevice}" "${selectedDestination}"
fi
echo "Executing command: cp "${targetVolume}"/usr/standalone/i386/${stage2Loader} ${selectedDestination}"
cp "${targetVolume}"/usr/standalone/i386/"${stage2Loader}" "${selectedDestination}"
"$scriptDir"InstallLog.sh "${targetVolume}" "Written boot to ${selectedDestination}."
else
echo "Executing command: cp "${targetVolume}"/usr/standalone/i386/${stage2Loader} ${targetVolume}"
cp "${targetVolume}"/usr/standalone/i386/"${stage2Loader}" "${targetVolume}"
"$scriptDir"InstallLog.sh "${targetVolume}" "Written boot to ${targetVolume}."
fi
#if [ -f "${selectedDestination}"/.Chameleon/nullhideboot ]; then
#echo "Executing command: SetFile -a V ${targetVolume}/${stage2Loader}"
#"${selectedDestination}"/.Chameleon/Resources/SetFile -a V "${targetVolume}"/"${stage2Loader}"
#fi
echo "-----------------------------------------------"
echo ""
echo ""
exit 0
branches/blackosx/package/Scripts/Sub/CheckDiskMicrocode.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/bin/bash
echo "==============================================="
echo "CheckDiskMicrocode: Any existing bootloaders?"
echo "*********************************************"
# Reads the GPTdiskProtectiveMBR and searches for an existing
# Windows bootloader and also for an existing Chameleon stage 0 loader
# which might be better changed depending on whether or not a Windows
# signature is found or not.
# The script then exits with the value 0 to indicate that Chameleon stage0
# loader can be written, or 1 to indicate not to write the stage0 loader.
# Receives targetDisk: for example, /dev/disk2.
# Receives diskSigCheck: 0 = Windows not installed / 1 = Windows installed.
# Receives targetVolume: Volume to install to.
# Receives scriptDir: The location of the main script dir.
if [ "$#" -eq 4 ]; then
targetDisk="$1"
diskSigCheck="$2"
targetVolume="$3"
scriptDir="$4"
echo "DEBUG: passed argument for targetDisk = $targetDisk"
echo "DEBUG: passed argument for diskSigCheck = $diskSigCheck"
echo "DEBUG: passed argument for targetVolume = $targetVolume"
echo "DEBUG: passed argument for scriptDir = $scriptDir"
else
echo "Error - wrong number of values passed - Exiting"
exit 9
fi
# read the first 437 bytes of the MBR
mbr437=$( dd 2>/dev/null if="$targetDisk" count=1 | dd 2>/dev/null count=1 bs=437 | perl -ne '@a=split"";for(@a){printf"%02x",ord}' )
#mbr437md5=$( dd 2>/dev/null if="$targetDisk" count=1 | dd 2>/dev/null count=1 bs=437 | md5 )
#echo "DEBUG: ${mbr437}"
if [ $( echo "${mbr437}" | awk -F0 '{print NF-1}' ) = 874 ]; then
echo "The first 437 bytes of the MBR Disk Sector is blank - Updating"
#"$scriptDir"InstallLog.sh "${targetVolume}" "Target has no bootcode in the MBR disk sector."
else
# There is already something on the MBR
# See if a Windows bootloader already exists
# Check bytes 440-443 of the GPTdiskProtectiveMBR for a Windows Disk Signature
windowsloader=$( dd 2>/dev/null if="$targetDisk" count=4 bs=1 | xxd | awk '{print $2$3}' )
if [ "${windowsloader}" == "33c08ed0" ] ; then
echo "Found existing Windows Boot Loader so will replace with Chameleon boot0md"
"$scriptDir"InstallLog.sh "${targetVolume}" "Target has existing Windows boot loader - Will replace with boot0md"
fi
# See if a Chameleon stage0 boot file already exists
# Note: The checks for Boot0 and Boot0hfs assume the code stays the same.
# if the code changes then the hex values 0b807c, 0a803c and ee7505 used for matching
# need to be checked to see if they are the same or not.
stage0type=$( dd 2>/dev/null if="$targetDisk" count=3 bs=1 skip=105 | xxd | awk '{print $2$3}' )
if [ "${stage0type}" == "0b807c" ]; then
echo "Target has existing Chameleon stage 0 loader - Boot0hfs"
"$scriptDir"InstallLog.sh "${targetVolume}" "Target has existing Chameleon stage 0 loader - boot0hfs"
# Script CheckDiskSignature.sh returned 0 if a Windows installation was NOT found
if [ "$diskSigCheck" == "0" ]; then
echo "Found no existing Windows installation so will replace stage 0 loader with Boot0"
"$scriptDir"InstallLog.sh "${targetVolume}" "Will replace boot0hfs with boot0 as Windows is not on target disk."
exit 0
fi
fi
if [ "${stage0type}" == "0a803c" ]; then
echo "Found existing Chameleon stage 0 loader - Boot0"
"$scriptDir"InstallLog.sh "${targetVolume}" "Target has existing Chameleon stage 0 loader - boot0"
# Script CheckDiskSignature.sh returned 1 if a Windows installation was found
if [ "$diskSigCheck" = "1" ]; then
echo "Found existing Windows installation so will replace stage 0 loader with boot0md"
"$scriptDir"InstallLog.sh "${targetVolume}" "Will replace boot0 with boot0md as Windows is on target disk."
exit 0
fi
fi
if [ "${stage0type}" == "ee7505" ]; then
echo "Found existing Chameleon stage 0 loader - Boot0md"
echo "And will leave boot0md installed."
"$scriptDir"InstallLog.sh "${targetVolume}" "Target has existing Chameleon stage 0 loader - boot0md. Leaving as is."
exit 1
fi
if [ "${stage0type}" != "0b807c" ] && [ "${stage0type}" != "0a803c" ] && [ "${stage0type}" != "ee7505" ] && [ "${windowsloader}" != "33c08ed0" ] ; then
echo "Something other than Chameleon or a Windows bootloader was found"
test=$(echo "${mbr437}" | awk -F0 '{print NF-1}' )
echo "Disk microcode found: ${test} - Preserving."
echo "diskupdate is set to false"
echo "-----------------------------------------------"
"$scriptDir"InstallLog.sh "${targetVolume}" "NOTE: Target has existing unrecognised bootcode in the MBR. Leaving as is."
echo ""
exit 1
fi
fi
echo "diskupdate is now set to true."
echo "-----------------------------------------------"
echo ""
exit 0
branches/blackosx/package/Scripts/Sub/CheckProceed.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/bash
echo "==============================================="
echo "Check Proceed: Can the script continue?"
echo "***************************************"
# Checks the selected volume is present and the disk is partitioned.
# Receives targetVolume: Volume to install to (will be '/Volumes/EFI' if EFI install)
# Receives targetDevice: Stores device number, for example /dev/disk2s1.
# Receives installerVolume: Volume to write the installer log to.
# Receives scriptDir: The location of the main script dir.
if [ "$#" -eq 4 ]; then
targetVolume="$1"
targetDevice="$2"
installerVolume="$3"
scriptDir="$4"
echo "DEBUG: passed argument for targetVolume = $targetVolume"
echo "DEBUG: passed argument for targetDevice = $targetDevice"
echo "DEBUG: passed argument for installerVolume = $installerVolume"
echo "DEBUG: passed argument for scriptDir = $scriptDir"
else
echo "Error - wrong number of values passed"
exit 9
fi
if [ -z "$targetVolume" ]; then
echo "*** Cannot find the volume. Exiting."
"$scriptDir"InstallLog.sh "${installerVolume}" "FAIL: Cannot file the volume: $targetVolume."
exit 1
else
echo "Confirming target volume exists"
fi
if [ "$targetDevice" = "$targetDevice#*disk*s" ]; then
echo "*** ERROR Volume does not use slices. Exiting."
"$scriptDir"InstallLog.sh "${installerVolume}" "FAIL: $targetVolume doesn't use slices."
exit 1
else
echo "Confirming target device uses slices"
fi
# Add check for installing to a 'small' HFS device like a
# 1GB USB flash drive which won't have an EFI System Partition.
if [ "$targetVolume" = "/Volumes/EFI" ]; then
# Take target device and check slice 1 matches partition named "EFI"
stripped=$( echo ${targetDevice#/dev/} )
if [ ! $(echo ${stripped#*disk*s}) = 1 ]; then
stripped=$( echo ${stripped%s*})"s1"
fi
if [ ! $( diskutil list | grep ${stripped} | awk {'print $2'} ) = "EFI" ]; then
echo "*** The selected volume doesn't have an EFI System Partition. Exiting."
"$scriptDir"InstallLog.sh "${installerVolume}" "FAIL: Selected disk does not have an EFI System Partition."
exit 1
fi
fi
echo "-----------------------------------------------"
echo ""
#"$scriptDir"InstallLog.sh "${installerVolume}" "CheckProceed: PASS"
exit 0
branches/blackosx/package/Scripts/Sub/SetActivePartition.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/bash
echo "==============================================="
echo "Set Active Partition ONLY if Windows is not installed"
echo "*****************************************************"
# Sets partition active if Windows is not installed.
# Receives efiformat: code is 1 for HFS, 2 for MSDOS, 0 for unknown
# Receives diskSigCheck: code is 1 for a Windows install, 0 for no Windows install
# Receives targetDiskRaw: for example, /dev/rdisk1
# Receives targetSlice: for example, 1
# Receives targetVolume: Volume to install to.
# Receives scriptDir: The location of the main script dir.
if [ "$#" -eq 6 ]; then
efiformat="$1"
diskSigCheck="$2"
targetDiskRaw="$3"
targetSlice="$4"
targetVolume="$5"
scriptDir="$6"
echo "DEBUG: passed argument for efiformat = $efiformat"
echo "DEBUG: passed argument for diskSigCheck = $diskSigCheck"
echo "DEBUG: passed argument for targetDiskRaw = $targetDiskRaw"
echo "DEBUG: passed argument for targetSlice = $targetSlice"
echo "DEBUG: passed argument for targetVolume = $targetVolume"
echo "DEBUG: passed argument for scriptDir = $scriptDir"
else
echo "Error - wrong number of values passed"
exit 9
fi
# Append fdisk output to the installer log
"$scriptDir"InstallLog.sh "${targetVolume}" "fdisk ${targetDiskRaw}"
if [ ${diskSigCheck} == "0" ]; then
#Windows is not installed so let's change the active partition"
partitionactive=$( fdisk -d ${targetDiskRaw} | grep -n "*" | awk -F: '{print $1}')
if [ "${partitionactive}" ] && [ "${partitionactive}" = "${targetSlice}" ]; then
"$scriptDir"InstallLog.sh "${targetVolume}" "${targetDiskRaw#/dev/r}, slice "${targetSlice}" is already set active. No need to change it."
else
"$scriptDir"InstallLog.sh "${targetVolume}" "Setting ${targetVolume} partition active."
# BadAxe requires EFI partition to be flagged active.
# but it doesn't' hurt to do it for any non-windows partition.
fdisk -e ${targetDiskRaw} <<-MAKEACTIVE
print
flag ${targetSlice}
write
y
quit
MAKEACTIVE
fi
else
# TO DO
# Add check to make sure that the active partition is actually the Windows partition
# before printing next statement.
#echo "Windows is installed so we let that remain the active partition"
"$scriptDir"InstallLog.sh "${targetVolume}" "Windows is installed so that can remain the active partition"
fi
echo "-----------------------------------------------"
echo ""
echo ""
exit 0
branches/blackosx/package/Scripts/Sub/CheckGRUBLinuxLoader.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/bash
echo "==============================================="
echo "CheckGRUBLinuxLoader: Does GRUB or LILO exist?"
echo "**********************************************"
# This reads the MBR of the disk in the attempt to find the
# signature for either the GRUB or Linux bootloaders.
# The script returns 1 if either is found, or 0 if none found.
# Receives targetdisk: for example, /dev/disk2.
# Receives targetVolume: Volume to install to.
# Receives scriptDir: The location of the main script dir.
if [ "$#" -eq 3 ]; then
targetDisk="$1"
targetVolume="$2"
scriptDir="$3"
echo "DEBUG: passed argument for targetDisk = $targetDisk"
echo "DEBUG: passed argument for targetVolume = $targetVolume"
echo "DEBUG: passed argument for scriptDir = $scriptDir"
else
echo "Error - wrong number of values passed"
exit 9
fi
diskmicrocodetype[1]="GRUB,47525542"
diskmicrocodetype[2]="LILO,4c494c4f"
diskmicrocode=$( dd 2>/dev/null if="$targetDisk" count=1 | dd 2>/dev/null count=1 bs=437 | perl -ne '@a=split"";for(@a){printf"%02x",ord}' )
#echo "${diskmicrocode}"
diskmicrocodetypecounter=0
while [ ${diskmicrocodetypecounter} -lt ${#diskmicrocodetype[@]} ]; do
diskmicrocodetypecounter=$(( ${diskmicrocodetypecounter} + 1 ))
diskmicrocodetypeid=${diskmicrocodetype[${diskmicrocodetypecounter}]#*,}
if [ ! "${diskmicrocode}" = "${diskmicrocode/${diskmicrocodetypeid}/}" ]; then
echo "${diskmicrocodetype[${diskmicrocodetypecounter}]%,*} found."
"$scriptDir"InstallLog.sh "${targetVolume}" "FAIL: Found an exisitng GRUB/LILO bootloader in the MBR."
exit 1
else
echo "Didn't find a match for ${diskmicrocodetype[${diskmicrocodetypecounter}]%,*}"
fi
done
echo "-----------------------------------------------"
echo ""
#"$scriptDir"InstallLog.sh "${targetVolume}" "GRUB/LILO: PASS"
exit 0
branches/blackosx/package/Scripts/Sub/UnMountEFIvolumes.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/bash
echo "==============================================="
echo "Unmount all volumes named EFI"
echo "*****************************"
# loop through and un-mount ALL mounted 'EFI' system partitions - Thanks kizwan
# Receives scriptDir: The location of the main script dir.
# Receives targetVolumeTemp: Stores original target if EFI install selected.
if [ "$#" -eq 2 ]; then
targetVolumeTemp="$1"
scriptDir="$2"
echo "DEBUG: passed argument for targetVolumeTemp = $targetVolumeTemp"
echo "DEBUG: passed argument for scriptDir = $scriptDir"
else
echo "Error - wrong number of values passed"
exit 9
fi
attempts=1
while [ "$( df | grep EFI )" ] && [ "${attempts}" -lt 5 ]; do
echo "Unmounting $( df | grep EFI | awk '{print $1}' )"
umount -f $( df | grep EFI | awk '{print $1}' )
attempts=$(( ${attempts} + 1 ))
done
if [ ${attempts} = 5 ]; then
echo "failed to unmount 'EFI' System Partition."
echo "-----------------------------------------------"
"$scriptDir"InstallLog.sh "${targetVolumeTemp}" "Failed to unmount 'EFI' System Partition."
echo ""
echo ""
echo ""
exit 1
fi
echo "-----------------------------------------------"
echo ""
echo ""
echo ""
exit 0
branches/blackosx/package/Scripts/Sub/CheckWindowsDiskSignature.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/bin/bash
echo "==============================================="
echo "CheckWindowsDiskSignature: Is Windows installed?"
echo "************************************************"
# Checks the disk sector for a 4-byte Windows disk signature
# if one is found then it exits with 1, otherwise it exits with 0
# Receives targetdisk: for example, /dev/disk0
# Receives targetVolume: Volume to install to.
# Receives scriptDir: The location of the main script dir.
if [ "$#" -eq 3 ]; then
targetDisk="$1"
targetVolume="$2"
scriptDir="$3"
echo "DEBUG: passed argument for targetDisk = $targetDisk"
echo "DEBUG: passed argument for targetVolume = $targetVolume"
echo "DEBUG: passed argument for scriptDir = $scriptDir"
else
echo "Error - wrong number of values passed - Exiting"
exit 9
fi
disksignature=$( dd 2>/dev/null if="$targetDisk" count=1 | dd 2>/dev/null count=4 bs=1 skip=440 | perl -ne '@a=split"";for(@a){printf"%02x",ord}' )
#echo "${disksignature}"
if [ "${disksignature}" = "00000000" ]; then
echo "No Windows installation detected."
echo "-----------------------------------------------"
echo ""
exit 0
else
echo "Detected an existing Windows installation"
echo "-----------------------------------------------"
echo ""
"$scriptDir"InstallLog.sh "${targetVolume}" "Detected a Windows installation on this volume."
exit 1
fi
echo "-----------------------------------------------"
echo ""
exit 0
branches/blackosx/package/buildpkg.sh
8787
8888
8989
90
91
90
91
9292
9393
9494
......
9999
100100
101101
102
103
102
103
104104
105105
106106
......
286286
287287
288288
289
289
290290
291291
292292
# build standard package
mkdir -p ${1}/Standard/Root
mkdir -p ${1}/Standard/Scripts/Resources
cp -f ${pkgroot}/Scripts/Standard/* ${1}/Standard/Scripts
cp -f ${pkgroot}/Scripts/Install/* ${1}/Standard/Scripts
cp -f ${pkgroot}/Scripts/Main/Standard/* ${1}/Standard/Scripts
cp -f ${pkgroot}/Scripts/Sub/* ${1}/Standard/Scripts
ditto --arch i386 `which SetFile` ${1}/Standard/Scripts/Resources/SetFile
ditto --noextattr --noqtn ${1%/*/*}/revision ${1}/Standard/Scripts/Resources/revision
ditto --noextattr --noqtn ${1%/*/*}/version ${1}/Standard/Scripts/Resources/version
# build efi package
mkdir -p ${1}/EFI/Root
mkdir -p ${1}/EFI/Scripts/Resources
cp -f ${pkgroot}/Scripts/EFI/* ${1}/EFI/Scripts
cp -f ${pkgroot}/Scripts/Install/* ${1}/EFI/Scripts
cp -f ${pkgroot}/Scripts/Main/EFI/* ${1}/EFI/Scripts
cp -f ${pkgroot}/Scripts/Sub/* ${1}/EFI/Scripts
ditto --arch i386 `which SetFile` ${1}/EFI/Scripts/Resources/SetFile
ditto --noextattr --noqtn ${1%/*/*}/revision ${1}/EFI/Scripts/Resources/revision
ditto --noextattr --noqtn ${1%/*/*}/version ${1}/EFI/Scripts/Resources/version
echo "================= Post ================="
mkdir -p ${1}/Post/Root
mkdir -p ${1}/Post/Scripts
cp -f ${pkgroot}/Scripts/Post/* ${1}/Post/Scripts
cp -f ${pkgroot}/Scripts/Main/Post/* ${1}/Post/Scripts
echo "[BUILD] Post "
buildpackage "${1}/Post" "/" "" "start_visible=\"false\" start_selected=\"true\"" >/dev/null 2>&1
outline[$((outlinecount++))]="${indent[$xmlindent]}</choices-outline>"

Archive Download the corresponding diff file

Revision: 1579