Chameleon Applications

Chameleon Applications Commit Details

Date:2010-10-29 00:06:47 (13 years 5 months ago)
Author:blackosx
Commit:195
Parents: 194
Message:After some reading and learning I have made some annotations, changes and additions to the standard install script. It will now install boot0 or boot0hfs dependent on what it finds on your hard drive. Only tested so far on GPT and GPT/MBR, with both OSX and Windows installations. This is still a work in progress but it's working so far.
Changes:
M/branches/blackosx/trunk/package/Resources/English.lproj/Localizable.strings
M/branches/blackosx/trunk/package/buildpkg
M/branches/blackosx/trunk/package/Scripts/Standard/postinstall

File differences

branches/blackosx/trunk/package/buildpkg
7575
7676
7777
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
11178
11279
11380
buildpackage "${1}/Standard" "/" "${coresize}" "start_enabled=\"true\" start_selected=\"upgrade_allowed()\" selected=\"exclusive(choices['EnhancedHFS']) && exclusive(choices['Standardhfs']) && exclusive(choices['EnhancedFAT']) && exclusive(choices['noboot'])\""
# End build standard package
# build standard package with boot0hfs
mkdir -p ${1}/Standardhfs/Root
mkdir -p ${1}/Standardhfs/Scripts/Tools
cp -f ${pkgroot}/Scripts/Standardhfs/* ${1}/Standardhfs/Scripts
ditto --arch i386 `which SetFile` ${1}/Standardhfs/Scripts/Tools/SetFile
echo "Building boot0hfs package"
buildpackage "${1}/Standardhfs" "/" "${coresize}" "start_enabled=\"true\" start_selected=\"false\" selected=\"exclusive(choices['EnhancedHFS']) && exclusive(choices['Standard']) && exclusive(choices['EnhancedFAT']) && exclusive(choices['noboot'])\""
# End build standard package with boot0hfs
# build efi fat32 package
mkdir -p ${1}/EnhancedFAT/Root
mkdir -p ${1}/EnhancedFAT/Scripts/Tools
cp -f ${pkgroot}/Scripts/FAT/* ${1}/EnhancedFAT/Scripts
ditto --arch i386 `which SetFile` ${1}/EnhancedFAT/Scripts/Tools/SetFile
echo "Building efi fat32 package"
buildpackage "${1}/EnhancedFAT" "/" "${coresize}" "start_visible=\"systemHasGPT()\" start_selected=\"false\" selected=\"exclusive(choices['Standard']) && exclusive(choices['Standardhfs']) && exclusive(choices['EnhancedHFS']) && exclusive(choices['noboot'])\""
# End build efi fat32 package
# build efi hfs package
mkdir -p ${1}/EnhancedHFS/Root
mkdir -p ${1}/EnhancedHFS/Scripts/Tools
cp -f ${pkgroot}/Scripts/HFS/* ${1}/EnhancedHFS/Scripts
ditto --arch i386 `which SetFile` ${1}/EnhancedHFS/Scripts/Tools/SetFile
echo "Building efi hfs package"
buildpackage "${1}/EnhancedHFS" "/" "${coresize}" "start_visible=\"systemHasGPT()\" start_selected=\"false\" selected=\"exclusive(choices['Standard']) && exclusive(choices['Standardhfs']) && exclusive(choices['EnhancedFAT']) && exclusive(choices['noboot'])\""
# End build efi hfs package
# build reset choice package
mkdir -p ${1}/noboot/Root
echo "Building reset choice package"
buildpackage "${1}/noboot" "/binaries" "" "start_visible=\"true\" start_selected=\"false\" selected=\"exclusive(choices['Standard']) && exclusive(choices['Standardhfs']) && exclusive(choices['EnhancedFAT']) && exclusive(choices['EnhancedHFS'])\""
# End build reset choice package
((xmlindent--))
outline[$((outlinecount++))]="${indent[$xmlindent]}\t</line>"
# End build Chameleon package
branches/blackosx/trunk/package/Scripts/Standard/postinstall
22
33
44
5
56
67
78
......
3839
3940
4041
41
42
43
44
45
46
47
48
49
50
51
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
5258
5359
5460
5561
62
63
64
65
5666
57
5867
5968
6069
6170
6271
6372
73
74
6475
6576
77
78
79
6680
6781
82
83
6884
6985
86
87
88
89
90
91
7092
7193
7294
7395
7496
97
98
7599
100
76101
77102
78103
104
79105
80106
81107
82108
109
83110
84
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
85149
86
150
151
87152
88153
89154
155
156
157
90158
91159
160
92161
93162
163
164
165
166
94167
95168
96
97
169
170
171
172
98173
99
100
174
101175
176
177
178
102179
103180
181
182
104183
105184
185
186
187
188
106189
107190
108191
109192
110193
194
195
111196
197
112198
113199
114200
......
128214
129215
130216
217
218
219
220
131221
132222
133
134
135
136223
137
138
139
140
141
224
142225
143
144226
145
227
228
229
146230
147
148
149
150
151
152231
153232
154233
155234
235
156236
237
157238
158239
159240
......
164245
165246
166247
248
249
250
167251
252
168253
169254
255
256
170257
171258
172
173259
174
175260
261
262
263
264
265
266
176267
177
178
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
179286
180287
181288
......
187294
188295
189296
190
191
192
193
194
195
196
197
198
297
298
299
199300
200
201
202
203
204301
205
206
207
208
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
209324
325
326
327
210328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
211348
212
213
214
215
349
350
351
352
353
354
355
216356
217357
218358
359
360
361
219362
220
363
221364
222
365
223366
224367
225368
diskloader="boot0"
diskloaderdualboot="boot0hfs"
partitionloader="boot1h"
filesystemloader="boot"
bootrdisk=${bootdisk/disk/rdisk}
bootslice=${bootdev#*disk*s}
echo "Volume is ${bootvolume}"
echo "Volume device is ${bootdev}"
echo "Volume raw device is ${bootrdev}"
echo "Volume slice is ${bootslice}"
echo "Disk device is ${bootdisk}"
echo "Disk raw device is ${bootrdisk}"
echo "Disk loader is ${diskloader}"
echo "Partition loader is ${partitionloader}"
echo "Filesystem loader is ${filesystemloader}"
echo "Boot Resources is ${bootresources}"
echo "==============================================="
echo "Installer Variables:"
echo "********************"
echo "bootvolume: Volume is ${bootvolume}"
echo "bootdev: Volume device is ${bootdev}"
echo "bootrdev: Volume raw device is ${bootrdev}"
echo "bootslice: Volume slice is ${bootslice}"
echo "bootdisk: Disk device is ${bootdisk}"
echo "bootrdisk: Disk raw device is ${bootrdisk}"
echo "diskloader: Disk loader is ${diskloader}"
echo "partitionloader: Partition loader is ${partitionloader}"
echo "filesystemloader: Filesystem loader is ${filesystemloader}"
echo "bootresources: Boot Resources is ${bootresources}"
echo "-----------------------------------------------"
echo ""
echo ""
}
checkdiskmicrocodetype ()
{
echo "==============================================="
echo "Diskmicrocodetype:"
echo "******************"
diskmicrocode=$( dd 2>/dev/null if=${bootdisk} count=1 | dd 2>/dev/null count=1 bs=437 | perl -ne '@a=split"";for(@a){printf"%02x",ord}' )
diskmicrocodetypecounter=0
while [ ${diskmicrocodetypecounter} -lt ${#diskmicrocodetype[@]} ]; do
diskmicrocodetypecounter=$(( ${diskmicrocodetypecounter} + 1 ))
diskmicrocodetypeid=${diskmicrocodetype[${diskmicrocodetypecounter}]#*,}
if [ ! "${diskmicrocode}" = "${diskmicrocode/${diskmicrocodetypeid}/}" ]; then
echo "${diskmicrocodetype[${diskmicrocodetypecounter}]%,*} found."
else
echo "Didn't find a match for ${diskmicrocodetype[${diskmicrocodetypecounter}]%,*}"
fi
done
echo "-----------------------------------------------"
echo ""
echo ""
}
checkdiskmicrocode ()
{
echo "==============================================="
echo "Diskmicrocode:"
echo "*************"
# Note: The checks for Boot0 and Boot0hfs assume the code doesn't change!!
# 1 action ( check or set )
diskmicrocode=$( dd 2>/dev/null if=${bootdisk} count=1 | dd 2>/dev/null count=1 bs=437 | perl -ne '@a=split"";for(@a){printf"%02x",ord}' )
diskmicrocodemd5=$( dd 2>/dev/null if=${bootdisk} count=1 | dd 2>/dev/null count=1 bs=437 | md5 )
#echo "${diskmicrocode}"
if [ $( echo "${diskmicrocode}" | awk -F0 '{print NF-1}' ) = 874 ]; then
echo "Diskmicrocode = 874 (Which means the first 437 bytes of the MBR Disk Sector is blank)"
if [ "${1}" = "set" ]; then
echo "No disk microcode found. Updating."
diskupdate=true
echo "diskupdate is now set to true."
else
echo "No disk microcode found."
fi
else
# There is already something on the MBR
if [ ${1} = set ]; then
echo "Disk microcode found. Preserving."
# See if a Windows bootloader already exists
windowsloader=$( dd 2>/dev/null if=${bootdisk} count=4 bs=1 | xxd | awk '{print $2$3}' )
if [ "${windowsloader}" == "33c08ed0" ] ; then
echo "Found existing Windows Boot Loader"
echo "Will replace loader with Boot0hfs"
diskupdate=true
echo "diskupdate is now set to true."
fi
# See if a Chameleon stage0 boot file already exists
stage0type=$( dd 2>/dev/null if=${bootdisk} count=3 bs=1 skip=105 | xxd | awk '{print $2$3}' )
if [ "${stage0type}" == "0b807c" ] || [ "${stage0type}" == "0a803c" ] ; then
echo "Found existing Chameleon Stage 0 Loader"
# if found Boot0HFS without a Windows installation set diskupdate to true
if [ "${stage0type}" == "0b807c" ] && [ "${disksignature}" == "00000000" ]; then
echo "Found existing Chameleon Boot0HFS without a Windows installation"
echo "Will replace loader with Boot0"
diskupdate=true
echo "diskupdate is now set to true."
fi
# if found Boot0 with a Windows installation set diskupdate to true
if [ "${stage0type}" == "0a803c" ] && [ "${disksignature}" != "00000000" ]; then
echo "Found existing Chameleon Boot0 with a Windows installation"
echo "Will replace loader with Boot0hfs"
diskupdate=true
echo "diskupdate is now set to true."
fi
fi
# If neither a Windows or Chameleon Boot Loader exists
if [ "${stage0type}" != "0b807c" ] && [ "${stage0type}" != "0a803c" ] && [ "${windowsloader}" != "33c08ed0" ] ; then
test=$(echo "${diskmicrocode}" | awk -F0 '{print NF-1}' )
echo "Disk microcode found: ${test} - Preserving."
echo "diskupdate is left at false"
fi
else
echo "Disk microcode found."
test=$(echo "${diskmicrocode}" | awk -F0 '{print NF-1}' )
echo "Disk microcode found: ${test}"
fi
echo "Disk microcode MD5 is ${diskmicrocodemd5}"
fi
echo "-----------------------------------------------"
echo ""
echo ""
}
checkdisksignature ()
{
echo "==============================================="
echo "Find Disk Signature:"
echo "*************"
disksignature=$( dd 2>/dev/null if=${bootdisk} count=1 | dd 2>/dev/null count=4 bs=1 skip=440 | perl -ne '@a=split"";for(@a){printf"%02x",ord}' )
if [ $( echo "${disksignature}" | awk -F0 '{print NF-1}' ) = 8 ]; then
echo "No disk signature found."
echo "${disksignature}"
if [ $disksignature = "00000000" ]; then
echo "Just Zero's found meaning Windows isn't installed."
else
echo "Disk signature found."
echo "Disk signature is 0x${disksignature}"
echo "Non Zero means we've found a Windows installation"
fi
echo "-----------------------------------------------"
echo ""
echo ""
}
checkpartitionbootcode ()
{
echo "==============================================="
echo "Find Partition Bootcode:"
echo "************************"
# 1 action ( check or set )
partitionbootcode=$( dd if=${bootrdev} count=1 2>/dev/null | perl -ne '@a=split"";for(@a){printf"%02x",ord}' )
partitionbootcodeextended=$( dd if=${bootrdev} count=1 skip=1 2>/dev/null | perl -ne '@a=split"";for(@a){printf"%02x",ord}' )
echo "${partitionbootcode}"
if [ $( echo "${partitionbootcode}" | awk -F0 '{print NF-1}' ) = 1024 ]; then
echo "partitionbootcode = 1024 (Which means the whole 512 bytes of the MBR Disk Sector is blank)"
if [ "${1}" = "set" ]; then
echo "No partition bootcode found. Updating."
else
fi
echo "Partition bootcode MD5 is ${partitionbootcodemd5}"
fi
echo "-----------------------------------------------"
echo ""
echo ""
}
checkpartitionactive ()
{
partitionactive=$( fdisk440 -d ${bootrdisk} | grep -n "*" | awk -F: '{print $1}')
if [ -n "${partitionactive}" ]; then
echo "Partition flagged active is ${partitionactive}"
else
echo "No partition flagged active."
fi
start ${3}
}
start ${3}
echo "==============================================="
echo "Determine Partition Scheme:"
echo "***************************"
#partitiontable=$( diskutil list ${bootdisk} | sed -n '3p' | awk '{print $2}' )
#[ "${partitiontable}" = "GUID_partition_scheme" ] && echo "GPT found."
#[ "${partitiontable}" = "FDisk_partition_scheme" ] && echo "MBR found."
#[ "${partitiontable}" = "Apple_partition_scheme" ] && echo "APT found." && exit
partitiontable=$( dd 2>/dev/null if=${bootdisk} 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=${bootdisk} 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"
else
partitiontable="GPT/MBR"
fi
echo "${partitiontable} found."
echo "-----------------------------------------------"
echo ""
echo ""
diskupdate=false
checkdisksignature
checkdiskmicrocodetype
checkdiskmicrocode set
checkdisksignature
checkpartitionbootcode set
checkpartitionactive
echo "==============================================="
echo "Can we install the Chameleon bootloader files?"
echo "**********************************************"
if ${diskupdate}; then
echo "Executing command: fdisk -u -f /usr/standalone/i386/${diskloader} -y ${bootdisk}"
fdisk -u -f "${bootvolume}/usr/standalone/i386/${diskloader}" -y ${bootdisk}
echo "Diskupdate = true, so yes"
#---------------------------------------------------------------------
# Check bytes 438-446 of the GPTdiskProtectiveMBR for a Windows Disk Signature
#---------------------------------------------------------------------
if [ ${disksignature} == "00000000" ]; then
echo "Executing command: fdisk440 -u -f /usr/standalone/i386/${diskloader} -y ${bootdisk}"
fdisk440 -u -f "${bootvolume}/usr/standalone/i386/${diskloader}" -y ${bootdisk}
else
#---------------------------------------------------------------------
# If it exists then Windows is also installed on the HDD and we need to write boot0hfs
#---------------------------------------------------------------------
echo "Executing command: fdisk440 -u -f /usr/standalone/i386/${diskloaderdualboot} -y ${bootdisk}"
fdisk440 -u -f "${bootvolume}/usr/standalone/i386/${diskloaderdualboot}" -y ${bootdisk}
fi
else
echo "Diskupdate is false, so no stage 0 file was written"
fi
echo "Executing command: dd if=/usr/standalone/i386/${partitionloader} of=${bootrdev}"
echo "Executing command: ${bootresources}/Tools/SetFile -a V ${bootvolume}/${filesystemloader}"
"${bootresources}/Tools/SetFile" -a V "${bootvolume}/${filesystemloader}"
# If table is GPT make the first partition active (BadAxe compatibility).
#[ "${partitiontable}" = "GPT" ] && bootslice=1
fdisk440 -e ${bootdisk} <<-MAKEACTIVE
print
flag ${bootslice}
write
y
quit
MAKEACTIVE
echo "-----------------------------------------------"
echo ""
echo ""
checkdiskmicrocode check
checkdisksignature
checkpartitionbootcode check
checkpartitionactive
# Check efi partition
if [ -d /Volumes/EFI ]; then
umount -f /Volumes/EFI
rm -R -f /Volumes/EFI
echo "==============================================="
echo "Set Active Partition ONLY if Windows is not installed"
echo "*****************************************************"
if [ ${disksignature} == "00000000" ]; then
partitionactive=$( fdisk440 -d ${bootrdisk} | grep -n "*" | awk -F: '{print $1}')
echo "${partitionactive}"
if [ -n "${partitionactive}" ]; then
echo "${bootvolume} is flagged as active"
else
echo "${bootvolume} is not flagged as active, so let's do it."
# // If table is GPT make the first partition active (BadAxe compatibility).
fdisk440 -e ${bootrdisk} <<-MAKEACTIVE
print
flag ${bootslice}
write
y
quit
MAKEACTIVE
fi
fi
echo "-----------------------------------------------"
echo ""
echo ""
#checkdiskmicrocode check - why check as it would have changed after writing boot0?
#checkdisksignature - This should still be the same, but if it's changed then it's too late - unless we backed it up?
#checkpartitionbootcode check - why check as it would have changed after writing boot0?
echo "==============================================="
echo "Check EFI Partition:"
echo "***************************"
echo "Skipping for now"
# Check efi partition
#if [ -d /Volumes/EFI ]; then
#umount -f /Volumes/EFI
#rm -R -f /Volumes/EFI
#fi
echo "-----------------------------------------------"
echo ""
echo ""
if [ -d "${bootvolume}/Extra/Extensions" ]; then
#echo "Executing command: mkdir -p ${bootvolume}/Extra/Extensions"
mkdir -p "${bootvolume}/ExtraBackup"
cp -f -R "${bootvolume}/Extra" "${bootvolume}/ExtraBackup"
rm -f -R "${bootvolume}/Extra"
echo "-----------------------------------------------"
echo "Duplicating Extra to ExtraBackup Folder, then removing Extra"
echo "-----------------------------------------------"
echo "Executing command: mkdir -p ${bootvolume}/Extra/Extensions"
#mkdir -p "${bootvolume}/ExtraBackup"
#cp -f -R "${bootvolume}/Extra" "${bootvolume}/ExtraBackup"
#rm -f -R "${bootvolume}/Extra"
fi
# unpack any existing Extensions.mkext already on the booter volume
if [ -f "${2}/ExtraBackup/Extensions.mkext" ]; then
echo "-----------------------------------------------"
echo "Mkext section"
echo "-----------------------------------------------"
echo "Executing command: mkextunpack -d ${2}/Extra/Extensions ${2}/ExtraBackup/Extensions.mkext"
mkextunpack -d "${2}/.Chameleon/Extra/Extensions" "${2}/.Chameleon/ExtraBackup/Extensions.mkext"
#mkextunpack -d "${2}/.Chameleon/Extra/Extensions" "${2}/.Chameleon/ExtraBackup/Extensions.mkext"
echo "Executing command: rm -R -f ${2}/ExtraBackup/Extensions.mkext"
rm -R -f "${2}/ExtraBackup/Extensions.mkext"
#rm -R -f "${2}/ExtraBackup/Extensions.mkext"
fi
# setup link for extras

Archive Download the corresponding diff file

Revision: 195