Chameleon

Chameleon Svn Source Tree

Root/branches/ErmaC/Trunk/package/Scripts/Sub/CheckProceed.sh

  • Property svn:executable set to *
1#!/bin/bash
2
3echo "==============================================="
4echo "Check Proceed: Can the installation continue?"
5echo "***********************************************"
6
7# Checks the selected volume is present and the disk is partitioned
8# Now also check for another existing Chameleon installation on the same disk.
9
10# Receives targetDisk: for example, /dev/disk3.
11# Receives targetDeviceRaw: for example, /dev/rdisk3s1.
12# Receives targetVolume: Volume to install to (will be '/Volumes/EFI' if EFI install)
13# Receives targetDevice: Stores device number, for example /dev/disk2s1.
14# Receives installerVolume: Volume to write the installer log to.
15# Receives scriptDir: The location of the main script dir.
16
17if [ "$#" -eq 6 ]; then
18targetDisk="$1"
19targetDeviceRaw="$2"
20targetVolume="$3"
21targetDevice="$4"
22installerVolume="$5"
23scriptDir="$6"
24echo "DEBUG: passed argument for targetDisk = $targetDisk"
25echo "DEBUG: passed argument for targetDeviceRaw = $targetDeviceRaw"
26echo "DEBUG: passed argument for targetVolume = $targetVolume"
27echo "DEBUG: passed argument for targetDevice = $targetDevice"
28echo "DEBUG: passed argument for installerVolume = $installerVolume"
29echo "DEBUG: passed argument for scriptDir = $scriptDir"
30else
31echo "Error - wrong number of values passed"
32exit 9
33fi
34
35
36# Does target volume exist?
37if [ -z "$targetVolume" ]; then
38echo "*** Cannot find the volume. Exiting."
39"$scriptDir"InstallLog.sh "${installerVolume}" "FAIL: Cannot file the volume: $targetVolume."
40exit 1
41#else
42#echo "DEBUG: Confirming target volume exists"
43fi
44
45
46# Does target volume use slices?
47if [ "$targetDevice" = "$targetDevice#*disk*s" ]; then
48echo "*** ERROR Volume does not use slices. Exiting."
49"$scriptDir"InstallLog.sh "${installerVolume}" "FAIL: $targetVolume doesn't use slices."
50exit 1
51#else
52#echo "DEBUG: Confirming target device uses slices"
53fi
54
55
56# Add check for installing to a 'small' HFS device like a
57# 1GB USB flash drive which won't have an EFI System Partition.
58if [ "$targetVolume" = "/Volumes/EFI" ]; then
59# Take target device and check slice 1 matches partition named "EFI"
60stripped=$( echo ${targetDevice#/dev/} )
61if [ ! $(echo ${stripped#*disk*s}) = 1 ]; then
62stripped=$( echo ${stripped%s*})"s1"
63fi
64if [ ! $( diskutil list | grep ${stripped} | awk {'print $2'} ) = "EFI" ]; then
65#echo "DEBUG: *** The selected volume doesn't have an EFI System Partition. Exiting."
66"$scriptDir"InstallLog.sh "${installerVolume}" "FAIL: Selected disk does not have an EFI System Partition."
67exit 1
68fi
69fi
70
71
72# Check for existing Chameleon installations on a different
73# partition of the same target disk.
74#echo "DEBUG: Checking for existing Chameleon installations on ${targetDisk#/dev/}..."
75
76sliceNumber=$( echo ${targetDeviceRaw#*disk*s} )
77# strip slice from end
78targetDiskRawNoSlice=$( echo ${targetDeviceRaw%$sliceNumber} )
79
80# Are there any other partitions on the disk?
81# How many actual partitions are there?
82numSlices=$(( $( diskutil list | grep $( echo ${targetDisk#/dev/} ) | sed -n '$=' ) -2 ))
83
84# Only check the disk for Chameleon installations if there is more than one partition.
85if [ $numSlices -gt 1 ]; then
86
87#Scan all partitions for Chameleon code
88for (( i=1; i <= $numSlices; i++ ));
89do
90stageExistence=0
91targetDiskRaw=$targetDiskRawNoSlice$i
92
93# Check for existing stage 0 boot file from CheckDiskMicrocode.sh script
94stage0type=$( dd 2>/dev/null if="$targetDisk" count=3 bs=1 skip=105 | xxd | awk '{print $2$3}' )
95if [ "${stage0type}" == "0b807c" ] || [ "${stage0type}" == "0a803c" ] || [ "${stage0type}" == "ee7505" ]; then
96#echo "DEBUG: boot0 found on $targetDisk"
97(( stageExistence++ ))
98fi
99
100# Check for boot1h and boot1f32
101boot1hSearch=$( dd 2>/dev/null if="$targetDiskRaw" count=1 | perl -ne '@a=split"";for(@a){printf"%02x",ord}' )
102if [ "${boot1hSearch:0:16}" == "fa31c08ed0bcf0ff" ]; then
103#echo "DEBUG: boot1h found on "$targetDiskRaw
104(( stageExistence++ ))
105elif [ "${boot1hSearch:0:4}" == "e962" ] && [ "${boot1hSearch:180:12}" == "424f4f542020" ]; then
106#echo "DEBUG: boot1f32 found on "$targetDiskRaw
107(( stageExistence++ ))
108fi
109
110# Check for existing stage 2 boot file also
111if [ -e "$( df | grep $targetDisk"s"$i | awk '{ print $6 }' )"/boot ]; then
112#echo "DEBUG: boot found on $targetDiskRaw"
113(( stageExistence++ ))
114fi
115
116if [ $stageExistence == 3 ] && [ $i -ne $sliceNumber ]; then
117#echo "DEBUG: STOP: There is already an existing Chameleon installation on $targetDiskRaw"
118"$scriptDir"InstallLog.sh "${installerVolume}" "STOP: There is already an existing Chameleon installation on $targetDiskRaw."
119"$scriptDir"InstallLog.sh "${installerVolume}" "NOTE: This is allowed and does work as long as you aren't dual booting Windows"
120"$scriptDir"InstallLog.sh "${installerVolume}" "NOTE: from the same disk and are happy to control which partition is used by"
121"$scriptDir"InstallLog.sh "${installerVolume}" "NOTE: flagging the required partition active. General use doesn't require two"
122"$scriptDir"InstallLog.sh "${installerVolume}" "NOTE: Chameleon installs on the same disk, though might be done by advanced users."
123"$scriptDir"InstallLog.sh "${installerVolume}" "NOTE: If you still want to do this then proceed by installing Chameleon manually."
124exit 1
125fi
126done
127
128#else
129#echo "DEBUG: Just one slice"
130fi
131
132#"$scriptDir"InstallLog.sh "${installerVolume}" "CheckProceed: PASS"
133
134exit 0
135

Archive Download this file

Revision: 1622