␊ |
␊ |
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␊ |