#!/bin/bash echo "===============================================" echo "Pre-Install Script" echo "*********************************" echo "-----------------------------------------------" echo "" # Creates text file named '@LOG_FILENAME@' # at the root of the target volume. This is to give the user # a record of the installation process and also to show why # possibly the installation process failed (even though the # package installer ends reading 'Installation Successful'). # This script also prepares, then backs up any previous # stage2 boot file, /Extra folder and install log if they exist. # 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 # 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 logName="@LOG_FILENAME@" logFile="${targetVolume}/$logName" # --------------------------------------------- # Preparing Backing up of Chameleon files # --------------------------------------------- backupRootDir="${targetVolume}/Chameleon.Backups" backupDir="${backupRootDir}/"$( date -j "+%F-%Hh%M" ) # Create the backup directory mkdir -p "$backupDir" [[ -f "$logFile" ]] && mv "$logFile" "${backupDir}/${logName}" # Backup old log file # Setup Chameleon Log file # by writing header and diskutil list echo "Chameleon installer log - $( date ) Installer version: %CHAMELEONVERSION% %CHAMELEONREVISION% ======================================================" >"${logFile}" diskutil list >>"${logFile}" echo "======================================================" >>"${logFile}" # --------------------------------------------- # Backup Chameleon files # --------------------------------------------- echo "Backup Chameleon files" >>"${logFile}" # Backup stage2 if [[ -f "${targetVolume}/boot" ]];then echo "Backup stage2 file ${targetVolume}/boot to ${backupDir}/boot" >>"${logFile}" cp -p "${targetVolume}/boot" "${backupDir}/boot" fi # Backup /Extra directory if [[ -d "${targetVolume}/Extra" ]];then echo "Backing up ${targetVolume}/Extra folder to ${backupDir}/Extra" >>"${logFile}" cp -pR "${targetVolume}/Extra" "${backupDir}/Extra" fi chflags -R nohidden "$backupDir" # Remove the invisible flag of files in the backups find "${backupRootDir}" -type d -depth -empty -exec rmdir {} \; # Remove empty directories echo "======================================================" >>"${logFile}" # Check existing plist name for old naming convention and change to new convention. if [[ -f "${targetVolume}/Extra/com.apple.Boot.plist" ]]; then echo "Renaming existing com.apple.Boot.plist to org.chameleon.Boot.plist" >>"${logFile}" mv "${targetVolume}/Extra/com.apple.Boot.plist" "${targetVolume}/Extra/org.chameleon.Boot.plist" fi # --------------------------------------------- # Clearing options that Chameleon can managed # --------------------------------------------- echo "Clearing options..." >>"${logFile}" "${PWD}/clean_bootplist.pl" "${targetVolume}" 2>&1 | grep -v 'Does Not Exist' >>"${logFile}" echo "======================================================" >>"${logFile}" echo "===============================================" echo "END - Pre-Install Script" echo "*********************************" echo "-----------------------------------------------" echo "" exit 0