| 1 | #!/bin/bash␊ |
| 2 | ␊ |
| 3 | echo "==============================================="␊ |
| 4 | echo "Write Chameleon Stage 2 Loader:"␊ |
| 5 | echo "*******************************"␊ |
| 6 | ␊ |
| 7 | # Writes Chameleon stage 2 loader.␊ |
| 8 | ␊ |
| 9 | # Receives espformat: 1 for HFS, 2 for MSDOS, 0 for unknown␊ |
| 10 | # Receives stage2Loader: Name of file - boot␊ |
| 11 | # Receives selectedDestination: for example, /Volumes/USB␊ |
| 12 | # Receives targetDevice: for example, /dev/disk3s1␊ |
| 13 | # Receives targetVolume: for example, /Volumes/USB␊ |
| 14 | # Receives scriptDir: The location of the main script dir.␊ |
| 15 | ␊ |
| 16 | ␊ |
| 17 | if [ "$#" -eq 6 ]; then␊ |
| 18 | ␉espformat="$1"␊ |
| 19 | ␉stage2Loader="$2"␊ |
| 20 | ␉selectedDestination="$3"␊ |
| 21 | ␉targetDevice="$4"␊ |
| 22 | ␉targetVolume="$5"␊ |
| 23 | ␉scriptDir="$6"␊ |
| 24 | ␉echo "DEBUG: passed argument for espformat = $espformat"␊ |
| 25 | ␉echo "DEBUG: passed argument for stage2Loader = $stage2Loader"␊ |
| 26 | ␉echo "DEBUG: passed argument for selectedDestination = $selectedDestination"␊ |
| 27 | ␉echo "DEBUG: passed argument for targetDevice = $targetDevice"␊ |
| 28 | ␉echo "DEBUG: passed argument for targetVolume = $targetVolume"␊ |
| 29 | ␉echo "DEBUG: passed argument for scriptDir = $scriptDir"␊ |
| 30 | else␊ |
| 31 | ␉echo "Error - wrong number of values passed"␊ |
| 32 | ␉exit 9␊ |
| 33 | fi␊ |
| 34 | ␊ |
| 35 | # check to see if install to EFI system partition was selected␊ |
| 36 | if [ "${selectedDestination}" = "/Volumes/EFI" ]; then␊ |
| 37 | ␉echo "DEBUG: EFI install chosen"␊ |
| 38 | ␊ |
| 39 | ␉if [ ! -d "${selectedDestination}" ]; then␊ |
| 40 | ␉␉echo "Executing Command: mkdir -p ${selectedDestination}"␊ |
| 41 | ␉␉mkdir -p "${targetVolume}"␊ |
| 42 | ␉else␊ |
| 43 | ␉␉echo "DEBUG: folder /Volumes/EFI already exists"␊ |
| 44 | ␉fi␊ |
| 45 | ␊ |
| 46 | ␉#if the EFI system partition was selected then␊ |
| 47 | ␉# mount '/Volumes/EFI' with the correct format type␊ |
| 48 | ␊ |
| 49 | ␉if [ ${espformat} = 1 ]; then␊ |
| 50 | ␊ |
| 51 | ␉␉echo "Executing command: mount_hfs ${targetDevice} ${targetVolume}"␊ |
| 52 | ␉␉mount_hfs "${targetDevice}" "${targetVolume}"␊ |
| 53 | ␉fi␊ |
| 54 | ␉if [ ${espformat} = 2 ]; then␊ |
| 55 | ␉␉[ -d "${selectedDestination}" ] || mkdir -p "${selectedDestination}"␊ |
| 56 | ␉␉echo "Executing command: mount_msdos -u 0 -g 0 ${targetDevice} ${selectedDestination}"␊ |
| 57 | ␉␉mount_msdos -u 0 -g 0 "${targetDevice}" "${selectedDestination}"␊ |
| 58 | ␉fi␊ |
| 59 | ␊ |
| 60 | ␉echo "Executing command: cp "${targetVolume}"/usr/standalone/i386/${stage2Loader} ${selectedDestination}"␊ |
| 61 | ␉cp "${targetVolume}"/usr/standalone/i386/"${stage2Loader}" "${selectedDestination}"␊ |
| 62 | ␉"$scriptDir"InstallLog.sh "${targetVolume}" "Written boot to ${selectedDestination}."␊ |
| 63 | else␊ |
| 64 | ␉echo "Executing command: cp "${targetVolume}"/usr/standalone/i386/${stage2Loader} ${targetVolume}"␊ |
| 65 | ␉cp "${targetVolume}"/usr/standalone/i386/"${stage2Loader}" "${targetVolume}"␊ |
| 66 | ␉"$scriptDir"InstallLog.sh "${targetVolume}" "Written boot to ${targetVolume}."␊ |
| 67 | fi␊ |
| 68 | ␊ |
| 69 | |
| 70 | #if [ -f "${selectedDestination}"/.Chameleon/nullhideboot ]; then␊ |
| 71 | #␉echo "Executing command: SetFile -a V ${targetVolume}/${stage2Loader}"␊ |
| 72 | #␉"${selectedDestination}"/.Chameleon/Resources/SetFile -a V "${targetVolume}"/"${stage2Loader}"␊ |
| 73 | #fi␊ |
| 74 | ␊ |
| 75 | echo "-----------------------------------------------"␊ |
| 76 | echo ""␊ |
| 77 | echo ""␊ |
| 78 | ␊ |
| 79 | exit 0 |