Index: branches/blackosx/package/Scripts/Main/Standard/postinstall =================================================================== --- branches/blackosx/package/Scripts/Main/Standard/postinstall (revision 1636) +++ branches/blackosx/package/Scripts/Main/Standard/postinstall (revision 1637) @@ -74,9 +74,6 @@ "$scriptDir"InstallLog.sh "${targetVolume}" "Running Standard postinstall script" "$scriptDir"InstallLog.sh "${targetVolume}" "Target volume = ${targetVolume} on ${targetDevice}" -# Added from EFI post script as this is now sent to CheckPreviousChameleon.sh -partitiontable=$( diskutil list ${targetDevice%s*} | sed -n '3p' | awk '{print $2}' ) - # Double check we can see the selected partition and it's of the right type. # If the following script finds anything, it returns 1 to indicate failure. @@ -125,8 +122,8 @@ # the following script returns 0 if nothing "$scriptDir"CheckPartitionScheme.sh "${targetDisk}" "${targetVolume}" "${scriptDir}" - partitionTable=$? - if [ ${partitionTable} = 3 ]; then + partitionScheme=$? + if [ ${partitionScheme} = 3 ]; then # If MBR partition scheme then check for FAT16 or FAT32 # the following script returns 1 if FAT16 @@ -137,47 +134,56 @@ fatType=$? fi - if [ "${fatType}" = 1 ] && [ "${partitionTable}" = 3 ]; then - echo "ERROR: - Can't install to a device using FAT16" + if [ "${fatType}" = 1 ] && [ "${partitionScheme}" = 3 ]; then # 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 - # Now also check for another existing Chameleon installation on the same disk. - # If the following script finds anything, it returns 1 to indicate failure. - # It returns 2 to indicate failure to unmount any Volumes named "EFI" + # Append a line break to the installer log + "$scriptDir"InstallLog.sh "${targetVolume}" "LineBreak" - "$scriptDir"CheckPreviousChameleon.sh "${targetDisk}" "${targetDeviceRaw}" "${targetDevice}" "${targetVolume}" "${partitiontable}" "${scriptDir}" - returnValue=$? - if [ ${returnValue} = 0 ] || [ ${returnValue} = 2 ]; then - # OK to proceed + if [ ${diskupdate} = "0" ]; then + + # Write the stage 0 loader to the MBR + "$scriptDir"WriteChameleonStage0.sh "${diskSigCheck}" "${stage0Loader}" "${stage0LoaderDualBoot}" "${targetDisk}" "${targetResources}" "${targetVolume}" "${scriptDir}" + else + "$scriptDir"InstallLog.sh "${targetVolume}" "Stage 0 loader not written to ${targetDisk}." + fi - # Append a line break to the installer log - "$scriptDir"InstallLog.sh "${targetVolume}" "LineBreak" + # Write the stage 1 loader to the partition boot sector + "$scriptDir"WriteChameleonStage1.sh "${targetFormat}" "${stage1LoaderHFS}" "${stage1LoaderFAT}" "${3}" "${targetDeviceRaw}" "${targetVolume}" "${scriptDir}" - if [ ${diskupdate} = "0" ]; then + # Write the stage 2 loader to the root of the selected partition + "$scriptDir"WriteChameleonStage2.sh "${stage2Loader}" "${3}" "${targetDevice}" "${targetVolume}" "${scriptDir}" + + + # Next we look to check for existing Chameleon installations. + # But as it will check /Volumes/EFI for the stage 2 loader, + # we need to make sure it's mounted. - # Write the stage 0 loader to the MBR - "$scriptDir"WriteChameleonStage0.sh "${diskSigCheck}" "${stage0Loader}" "${stage0LoaderDualBoot}" "${targetDisk}" "${targetResources}" "${targetVolume}" "${scriptDir}" - else - "$scriptDir"InstallLog.sh "${targetVolume}" "Stage 0 loader not written to ${targetDisk}." + # Unmount ALL mounted volumes named EFI. + # Returns 0=success, 1=fail + + "$scriptDir"UnMountEFIvolumes.sh "${targetVolume}" "${scriptDir}" + returnValue=$? + if [ ${returnValue} = 0 ]; then + # OK to proceed + + if [ ${partitionScheme} = 1 ] || [ ${partitionScheme} = 2 ]; then + # Mount the EFI system partition + "$scriptDir"MountESP.sh "${targetDisk}" "${targetVolume}" "${scriptDir}" fi + + # Check for another existing Chameleon installation on the same disk + "$scriptDir"CheckPreviousChameleon.sh "${targetDisk}" "${targetDeviceRaw}" "${targetDevice}" "${targetVolume}" "${scriptDir}" + fi - # Write the stage 1 loader to the partition boot sector - "$scriptDir"WriteChameleonStage1.sh "${targetFormat}" "${stage1LoaderHFS}" "${stage1LoaderFAT}" "${3}" "${targetDeviceRaw}" "${targetVolume}" "${scriptDir}" + # Append a line break to the installer log + "$scriptDir"InstallLog.sh "${targetVolume}" "LineBreak" - # Write the stage 2 loader to the root of the selected partition - "$scriptDir"WriteChameleonStage2.sh "${stage2Loader}" "${3}" "${targetDevice}" "${targetVolume}" "${scriptDir}" - - # Append a line break to the installer log - "$scriptDir"InstallLog.sh "${targetVolume}" "LineBreak" - - # Set the active partition ONLY if Windows is not installed - "$scriptDir"SetActivePartition.sh "${diskSigCheck}" "${targetDiskRaw}" "${targetSlice}" "${targetVolume}" "${scriptDir}" - else - echo "Stop" >"${targetVolumeChosenByUser}"/.ChameleonExists - fi + # Set the active partition ONLY if Windows is not installed + "$scriptDir"SetActivePartition.sh "${diskSigCheck}" "${targetDiskRaw}" "${targetSlice}" "${targetVolume}" "${scriptDir}" fi fi fi Index: branches/blackosx/package/Scripts/Main/EFI/postinstall =================================================================== --- branches/blackosx/package/Scripts/Main/EFI/postinstall (revision 1636) +++ branches/blackosx/package/Scripts/Main/EFI/postinstall (revision 1637) @@ -91,6 +91,7 @@ # Double check we can see the selected partition and it's of the right type. # If the following script finds anything, it returns 1 to indicate failure. + "$scriptDir"CheckProceed.sh "${targetVolume}" "${targetDeviceChosenByUser}" "${targetVolumeChosenByUser}" "${scriptDir}" returnValue=$? if [ ${returnValue} = 0 ]; then @@ -129,45 +130,45 @@ targetFormat=$( fstyp "$targetDevice" ) - # Determine the partition scheme of the selected disk - # is it GPT or a hybrid GPT/MBR + # Append a LineBreak to the installer log + "$scriptDir"InstallLog.sh "${targetVolumeChosenByUser}" "LineBreak" - "$scriptDir"CheckPartitionScheme.sh "${targetDisk}" "${targetVolumeChosenByUser}" "${scriptDir}" + if [ ${diskupdate} = "0" ]; then + + # Write the stage 0 loader to the MBR + "$scriptDir"WriteChameleonStage0.sh "${diskSigCheck}" "${stage0Loader}" "${stage0LoaderDualBoot}" "${targetDisk}" "${targetResources}" "${targetVolumeChosenByUser}" "${scriptDir}" + else + "$scriptDir"InstallLog.sh "${targetVolumeChosenByUser}" "Stage 0 loader not written to ${targetDisk}." + fi - # Now also check for another existing Chameleon installation on the same disk. - # This also unmounts all volumes named EFI and then mounts the EFI system partition. - # If the following script finds anything, it returns 1 to indicate failure. - # It returns 2 to indicate failure to unmount any Volumes named "EFI" - "$scriptDir"CheckPreviousChameleon.sh "${targetDisk}" "${targetDeviceRaw}" "${targetDevice}" "${targetVolumeChosenByUser}" "${partitiontable}" "${scriptDir}" + # Write the stage 1 loader to the partition boot sector + "$scriptDir"WriteChameleonStage1.sh "${targetFormat}" "${stage1LoaderHFS}" "${stage1LoaderFAT}" "${targetVolumeChosenByUser}" "${targetDeviceRaw}" "${targetVolumeChosenByUser}" "${scriptDir}" + + + # Unmount ALL mounted volumes named EFI. + # Returns 0=success, 1=fail + + "$scriptDir"UnMountEFIvolumes.sh "${targetVolumeChosenByUser}" "${scriptDir}" returnValue=$? - if [ ${returnValue} = 0 ] && [ ${returnValue} -ne 2 ]; then + if [ ${returnValue} = 0 ]; then # OK to proceed - - # Append a LineBreak to the installer log - "$scriptDir"InstallLog.sh "${targetVolumeChosenByUser}" "LineBreak" - - if [ ${diskupdate} = "0" ]; then - # Write the stage 0 loader to the MBR - "$scriptDir"WriteChameleonStage0.sh "${diskSigCheck}" "${stage0Loader}" "${stage0LoaderDualBoot}" "${targetDisk}" "${targetResources}" "${targetVolumeChosenByUser}" "${scriptDir}" - else - "$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 "${targetFormat}" "${stage1LoaderHFS}" "${stage1LoaderFAT}" "${targetVolumeChosenByUser}" "${targetDeviceRaw}" "${targetVolumeChosenByUser}" "${scriptDir}" - + # Mount the EFI system partition + "$scriptDir"MountESP.sh "${targetDisk}" "${targetVolumeChosenByUser}" "${scriptDir}" + # Write the stage 2 loader to the root of the selected partition "$scriptDir"WriteChameleonStage2.sh "${stage2Loader}" "${targetVolume}" "${targetDevice}" "${targetVolumeChosenByUser}" "${scriptDir}" - # Append a LineBreak to the installer log - "$scriptDir"InstallLog.sh "${targetVolumeChosenByUser}" "LineBreak" + # Check for another existing Chameleon installation on the same disk + "$scriptDir"CheckPreviousChameleon.sh "${targetDisk}" "${targetDeviceRaw}" "${targetDevice}" "${targetVolumeChosenByUser}" "${scriptDir}" + fi - # Set the active partition ONLY if Windows is not installed - "$scriptDir"SetActivePartition.sh "${diskSigCheck}" "${targetDiskRaw}" "${targetSlice}" "${targetVolumeChosenByUser}" "${scriptDir}" - else - echo "Stop" >"${targetVolumeChosenByUser}"/.ChameleonExists - fi + # Append a LineBreak to the installer log + "$scriptDir"InstallLog.sh "${targetVolumeChosenByUser}" "LineBreak" + + # Set the active partition ONLY if Windows is not installed + "$scriptDir"SetActivePartition.sh "${diskSigCheck}" "${targetDiskRaw}" "${targetSlice}" "${targetVolumeChosenByUser}" "${scriptDir}" + fi fi else Index: branches/blackosx/package/Scripts/Sub/CheckPreviousChameleon.sh =================================================================== --- branches/blackosx/package/Scripts/Sub/CheckPreviousChameleon.sh (revision 1636) +++ branches/blackosx/package/Scripts/Sub/CheckPreviousChameleon.sh (revision 1637) @@ -8,72 +8,32 @@ # and tries to make sure the user doesn't end up with an un-bootable # system due to having installed Chameleon previously elsewhere. +# Called from the Standard/postinstall and EFI/postinstall scripts +# /Volumes/EFI should already be mounted before this is called. + # Receives targetDisk: for example, /dev/disk3. # Receives targetDeviceRaw: for example, /dev/rdisk3s1. # Receives targetDevice: Stores device number, for example /dev/disk2s1. # Receives installerVolume: Volume to write the installer log to. -# Receives partitiontable: for example, GUID_partition_scheme # Receives scriptDir: The location of the main script dir. -if [ "$#" -eq 6 ]; then +if [ "$#" -eq 5 ]; then targetDisk="$1" targetDeviceRaw="$2" targetDevice="$3" installerVolume="$4" - partitiontable="$5" - scriptDir="$6" + scriptDir="$5" echo "DEBUG: passed argument for targetDisk = $targetDisk" echo "DEBUG: passed argument for targetDeviceRaw = $targetDeviceRaw" echo "DEBUG: passed argument for targetDevice = $targetDevice" echo "DEBUG: passed argument for installerVolume = $installerVolume" - echo "DEBUG: passed argument for partitiontable = $partitiontable" echo "DEBUG: passed argument for scriptDir = $scriptDir" else echo "Error - wrong number of values passed" exit 9 fi -# =============================================== -# Functions -# =============================================== -mountESP() -{ - if [ "${partitiontable}" = "GUID_partition_scheme" ]; then - # 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 "${installerVolume}" "${scriptDir}" - returnValue=$? - if [ ${returnValue} = 0 ]; then - # OK to proceed - - if [ ! -e "/Volumes/EFI" ]; then - #echo "DEBUG: Executing Command: mkdir -p ${/Volumes/EFI}" - mkdir -p "/Volumes/EFI" - #else - #echo "DEBUG: folder /Volumes/EFI already exists" - fi - - # Mount '/Volumes/EFI' using the correct format type - if [ "$( fstyp "${targetDisk}"s1 | grep hfs )" ]; then - #echo "Executing command: mount_hfs ${targetDevice} ${targetVolume}" - "$scriptDir"InstallLog.sh "${installerVolume}" "Mounting ${targetDisk}s1 as /Volumes/EFI" - mount_hfs "${targetDisk}"s1 "/Volumes/EFI" - fi - if [ "$( fstyp "${targetDisk}"s1 | grep msdos )" ]; then - #echo "Executing command: mount_msdos -u 0 -g 0 ${targetDevice} ${/Volumes/EFI}" - "$scriptDir"InstallLog.sh "${installerVolume}" "Mounting ${targetDisk}s1 as /Volumes/EFI" - mount_msdos -u 0 -g 0 "${targetDisk}"s1 "/Volumes/EFI" - fi - else - # quit out and notify EFI post script not to write Chameleon files. - exit 2 - fi - fi -} - - # =============================================== # Prepare some vars # =============================================== @@ -92,46 +52,37 @@ # if there is more than one partition on the disk. # =============================================== if [ $numSlices -gt 1 ]; then - - #echo "DEBUG: Checking for existing Chameleon installations on ${targetDisk#/dev/}..." "$scriptDir"InstallLog.sh "${installerVolume}" "LineBreak" "$scriptDir"InstallLog.sh "${installerVolume}" "Checking for previous chameleon installations on ${targetDisk#/dev/}" # If a GPT is used then we are going to have the check the EFI system partition - # for the stage 2 'boot' file. As this script is called from the Main EFI - # postinstall script, so lets mount the EFI system partition here instead. - + # for the stage 2 'boot' file so lets mount the EFI system partition. mountESP + # Check the disk's MBR for existing stage 0 boot code (code from CheckDiskMicrocode.sh script) + stage0type=$( dd 2>/dev/null if="$targetDisk" count=3 bs=1 skip=105 | xxd | awk '{print $2$3}' ) + if [ "${stage0type}" == "0a803c" ] || [ "${stage0type}" == "ee7505" ] || [ "${stage0type}" == "742b80" ]; then + (( stagesFound++ )) + stage0type=2 + elif [ "${stage0type}" == "0b807c" ]; then + (( stagesFound++ )) + stage0type=1 + fi + #Scan all partitions for Chameleon code for (( i=1; i <= $numSlices; i++ )); do stagesFound=0 - stage0type=0 stage1Existence="NONE" stage2Existence=0 targetDiskRaw=$targetDiskRawNoSlice$i - - # Check for existing stage 0 boot file (code from CheckDiskMicrocode.sh script) - stage0type=$( dd 2>/dev/null if="$targetDisk" count=3 bs=1 skip=105 | xxd | awk '{print $2$3}' ) - if [ "${stage0type}" == "0a803c" ] || [ "${stage0type}" == "ee7505" ] || [ "${stage0type}" == "742b80" ]; then - #echo "DEBUG: stage 0 (hfs) loader found on $targetDisk" - (( stagesFound++ )) - stage0type=2 - elif [ "${stage0type}" == "0b807c" ]; then - #echo "DEBUG: stage 0 (active) loader found on $targetDisk" - (( stagesFound++ )) - stage0type=1 - fi - + # Check for existence of a bootable partition boot sector containing either boot1h or boot1f32 boot1Search=$( dd 2>/dev/null if="$targetDiskRaw" count=1 | perl -ne '@a=split"";for(@a){printf"%02x",ord}' ) if [ "${boot1Search:0:16}" == "fa31c08ed0bcf0ff" ] && [ "${boot1Search:1020:2}" == "55" ]; then - #echo "DEBUG: boot1h found on "$targetDiskRaw (( stagesFound++ )) stage1Existence="boot1h" elif [ "${boot1Search:0:4}" == "e962" ] && [ "${boot1Search:180:12}" == "424f4f542020" ] && [ "${boot1Search:1020:2}" == "55" ]; then - #echo "DEBUG: boot1f32 found on "$targetDiskRaw (( stagesFound++ )) stage1Existence="boot1f32" fi @@ -139,7 +90,6 @@ # Check for existing stage 2 boot file. # Include checking the EFI system partition if it exists and is mounted. if [ -e "$( df | grep ${targetDisk}s${i} | awk '{ print $6 }' )"/boot ]; then - #echo "DEBUG: boot found on $targetDiskRaw" (( stagesFound++ )) stage2Existence=1 fi @@ -167,6 +117,7 @@ "$scriptDir"InstallLog.sh "${installerVolume}" "${message}" fi + # User could see a b1f:error or boot0:error if the following conditions are true: # A) Boot0hfs, Boot0md or Boot0md (dmazar's Boot0workV2) is being used. # B) The previous stage 1 code is on a lower partiton than the one being installed to now. @@ -175,7 +126,7 @@ if [ $stagesFound == 2 ] && [ $stage2Existence == 0 ]; then # Exisitng boot0 and boot1 only found - missing boot "$scriptDir"InstallLog.sh "${installerVolume}" "INFO: Found $stage1Existence installed to ${targetDisk}s${i}" - + # stage0type=2 is used to know if 'A' is true. if [ $stage0type == 2 ]; then # i = current slice we're checking, slicenumber = slice trying to install to. @@ -193,27 +144,30 @@ ---" "$scriptDir"InstallLog.sh "${installerVolume}" "${message}" + # /Volumes/EFI needs unmounting before changing partition boot sector if [ $i == 1 ]; then umount /Volumes/EFI - fi - if [ "$( fstyp "${targetDisk}"s1 | grep hfs )" ]; then - #echo "DEBUG: HFS - changing byte 1FEh to 00" - dd if=${targetDisk}s${i} count=2 bs=512 of=originalBootSector - cp originalBootSector newBootSector - dd if="patch" of=newBootSector bs=1 count=1 seek=510 conv=notrunc - dd if=newBootSector of=${targetDisk}s${i} count=2 bs=510 + if [ "$( fstyp "${targetDisk}"s1 | grep hfs )" ]; then + #echo "DEBUG: HFS - changing byte 1FEh to 00" + dd if=${targetDisk}s${i} count=2 bs=512 of=originalBootSector + cp originalBootSector newBootSector + dd if="patch" of=newBootSector bs=1 count=1 seek=510 conv=notrunc + dd if=newBootSector of=${targetDisk}s${i} count=2 bs=510 + fi + if [ "$( fstyp "${targetDisk}"s1 | grep msdos )" ]; then + #echo "DEBUG: MSDOS - changing byte 1FEh to 00" + dd if=${targetDisk}s${i} count=1 bs=512 of=/tmp/originalBootSector + cp /tmp/originalBootSector /tmp/newBootSector + dd if="$scriptDir/patch" of=/tmp/newBootSector bs=1 count=1 seek=510 conv=notrunc + dd if=/tmp/newBootSector of=${targetDisk}s${i} count=1 bs=512 + fi + + # /Volumes/EFI needs re-mounting so EFI/postinstall script can use it. + # Don't check for a GPT as wouldn't have got here if it wasn't + "$scriptDir"MountESP.sh "${targetDisk}" "${installerVolume}" "${scriptDir}" fi - if [ "$( fstyp "${targetDisk}"s1 | grep msdos )" ]; then - #echo "DEBUG: MSDOS - changing byte 1FEh to 00" - dd if=${targetDisk}s${i} count=1 bs=512 of=/tmp/originalBootSector - cp /tmp/originalBootSector /tmp/newBootSector - dd if="$scriptDir/patch" of=/tmp/newBootSector bs=1 count=1 seek=510 conv=notrunc - dd if=/tmp/newBootSector of=${targetDisk}s${i} count=1 bs=512 - fi - mountESP - else "$scriptDir"InstallLog.sh "${installerVolume}" "INFO: but won't interfere as you're installing to an earlier partition." fi Index: branches/blackosx/package/Scripts/Sub/MountESP.sh =================================================================== --- branches/blackosx/package/Scripts/Sub/MountESP.sh (revision 0) +++ branches/blackosx/package/Scripts/Sub/MountESP.sh (revision 1637) @@ -0,0 +1,42 @@ +#!/bin/bash + +echo "===============================================" +echo "MountESP: Mount the EFI system partition" +echo "***********************************************" + +# Creates a mountpoint and mounts /Volumes/EFI of the +# supplied disk which would have been pre-checked as using a GPT + +# Receives targetDisk: for example /dev/disk2. +# Receives installerVolume: Volume to write the installer log to. +# Receives scriptDir: The location of the main script dir. + +if [ "$#" -eq 3 ]; then + targetDisk="$1" + installerVolume="$2" + scriptDir="$3" + echo "DEBUG: passed argument for targetDisk = $targetDisk" + 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 + + +# Does the mountpoint exist? +if [ ! -e "/Volumes/EFI" ]; then + mkdir -p "/Volumes/EFI" +fi + +# Mount '/Volumes/EFI' using the correct format type +if [ "$( fstyp "${targetDisk}"s1 | grep hfs )" ]; then + "$scriptDir"InstallLog.sh "${installerVolume}" "Mounting ${targetDisk}s1 as /Volumes/EFI" + mount_hfs "${targetDisk}"s1 "/Volumes/EFI" +fi +if [ "$( fstyp "${targetDisk}"s1 | grep msdos )" ]; then + "$scriptDir"InstallLog.sh "${installerVolume}" "Mounting ${targetDisk}s1 as /Volumes/EFI" + mount_msdos -u 0 -g 0 "${targetDisk}"s1 "/Volumes/EFI" +fi + +exit 0 \ No newline at end of file Property changes on: branches/blackosx/package/Scripts/Sub/MountESP.sh ___________________________________________________________________ Added: svn:executable + * Index: branches/blackosx/package/Scripts/Sub/UnMountEFIvolumes.sh =================================================================== --- branches/blackosx/package/Scripts/Sub/UnMountEFIvolumes.sh (revision 1636) +++ branches/blackosx/package/Scripts/Sub/UnMountEFIvolumes.sh (revision 1637) @@ -6,7 +6,7 @@ # loop through and un-mount ALL mounted 'EFI' system partitions - Thanks kizwan -# Receives targetVolumeChosenByUser: Stores original target if EFI install selected. +# Receives targetVolumeChosenByUser: To write install log to. # Receives scriptDir: The location of the main script dir. if [ "$#" -eq 2 ]; then @@ -23,14 +23,12 @@ # be unmounted in which case the loop would run forever. attempts=1 while [ "$( df | grep EFI )" ] && [ $attempts -lt 5 ]; do - #echo "DEBUG: Unmounting $( df | grep EFI | awk '{print $1}' )" "$scriptDir"InstallLog.sh "${targetVolumeChosenByUser}" "Volume named 'EFI' is mounted..." "$scriptDir"InstallLog.sh "${targetVolumeChosenByUser}" "Unmounting $( df | grep EFI | awk '{print $1}' )" umount -f $( df | grep EFI | awk '{print $1}' ) (( attempts++ )) done if [ $attempts = 5 ]; then - #echo "DEBUG: failed to unmount 'EFI' System Partition." "$scriptDir"InstallLog.sh "${targetVolumeChosenByUser}" "Failed to unmount 'EFI' System Partition." exit 1 fi