#!/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" # If target volume root of current system then replace # / with volume name. if [ "$3" == "/" ] then targetVolume="/Volumes/"$( ls -1F /Volumes | sed -n 's:@$::p' ) else targetVolume="$3" fi 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/" updateStage1=1 # by default update partition boot sector efiPartitionExist=0 # target volume does not have EFI system partition. 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 "$scriptDir"InstallLog.sh "${targetVolume}" "Running Standard postinstall script" "$scriptDir"InstallLog.sh "${targetVolume}" "Target volume = ${targetVolume} on ${targetDevice}" # Double check we can see the selected partition and it's of the right type. # The following script returns either 0 or 1 to proceed, or 2 to indicate failure. "$scriptDir"CheckProceed.sh "${targetVolume}" "${targetDevice}" "${targetVolume}" "${scriptDir}" returnValue=$? if [ ${returnValue} -ne 2 ]; then # OK to proceed # Remember if the target volume has an EFI system partition. if [ ${returnValue} -ne 1 ]; then efiPartitionExist=1 fi # 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}" diskupdate=$? if [ ${diskupdate} -ne 0 ]; then "$scriptDir"InstallLog.sh "${targetVolume}" "Found an existing GRUB/LILO bootloader in the MBR." "$scriptDir"InstallLog.sh "${targetVolume}" "MBR and partition boot sector will not be modified." updateStage1=0 else # 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=$? fi # 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 the format of the selected partition. # result should be either hfs or msdos # Should really check to make sure! targetFormat=$( fstyp "$targetDevice" ) # 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}" partitionScheme=$? if [ ${partitionScheme} = 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 ] && [ "${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 # Append a line break to the installer log "$scriptDir"InstallLog.sh "${targetVolume}" "LineBreak" if [ ${diskupdate} -eq 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 if [ ${updateStage1} -eq 1 ]; then # Write the stage 1 loader to the partition boot sector "$scriptDir"WriteChameleonStage1.sh "${targetFormat}" "${stage1LoaderHFS}" "${stage1LoaderFAT}" "${3}" "${targetDeviceRaw}" "${targetVolume}" "${scriptDir}" else "$scriptDir"InstallLog.sh "${targetVolume}" "Partition boot sector not written to ${targetDevice}." fi # 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. "$scriptDir"InstallLog.sh "${targetVolume}" "LineBreak" "$scriptDir"InstallLog.sh "${targetVolume}" "Preparing to check target disk for previous installations." if [ ${efiPartitionExist} -ne 0 ]; then # volume has an EFI system partition "$scriptDir"InstallLog.sh "${targetVolume}" "Going to check the EFI system partition also." # Unmount ALL mounted volumes named EFI. Returns 0=success, 1=fail "$scriptDir"UnMountEFIvolumes.sh "${targetVolume}" "${scriptDir}" returnValue=$? if [ ${returnValue} = 0 ]; then # Mount the EFI system partition "$scriptDir"MountESP.sh "${targetDisk}" "${targetVolume}" "${efiPartitionExist}" "${scriptDir}" fi fi # Check for another existing Chameleon installation on the same disk "$scriptDir"CheckPreviousChameleon.sh "${targetDisk}" "${targetDeviceRaw}" "${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}" fi fi "$scriptDir"InstallLog.sh "${targetVolume}" "LineBreak" "$scriptDir"InstallLog.sh "${targetVolume}" "Standard script complete" "$scriptDir"InstallLog.sh "${targetVolume}" "LineBreak" echo "===============================================" echo "END - Standard Post-Install Script" echo "*********************************" echo "-----------------------------------------------" echo "" exit 0