Chameleon

Chameleon Svn Source Tree

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

  • Property svn:executable set to *
1#!/bin/bash
2
3echo "==============================================="
4echo "Check Previous Chameleon: Will there be problems?"
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 targetDevice: Stores device number, for example /dev/disk2s1.
13# Receives installerVolume: Volume to write the installer log to.
14# Receives scriptDir: The location of the main script dir.
15
16if [ "$#" -eq 5 ]; then
17targetDisk="$1"
18targetDeviceRaw="$2"
19targetDevice="$3"
20installerVolume="$4"
21scriptDir="$5"
22echo "DEBUG: passed argument for targetDisk = $targetDisk"
23echo "DEBUG: passed argument for targetDeviceRaw = $targetDeviceRaw"
24echo "DEBUG: passed argument for targetDevice = $targetDevice"
25echo "DEBUG: passed argument for installerVolume = $installerVolume"
26echo "DEBUG: passed argument for scriptDir = $scriptDir"
27else
28echo "Error - wrong number of values passed"
29exit 9
30fi
31
32
33# Check for existing Chameleon installations on a different
34# partition of the same target disk.
35#echo "DEBUG: Checking for existing Chameleon installations on ${targetDisk#/dev/}..."
36
37sliceNumber=$( echo ${targetDeviceRaw#*disk*s} )
38# strip slice from end
39targetDiskRawNoSlice=$( echo ${targetDeviceRaw%$sliceNumber} )
40
41# Are there any other partitions on the disk?
42# How many actual partitions are there?
43numSlices=$(( $( diskutil list | grep $( echo ${targetDisk#/dev/} ) | sed -n '$=' ) -2 ))
44
45# Only check the disk for Chameleon installations if there is more than one partition.
46if [ $numSlices -gt 1 ]; then
47
48#Scan all partitions for Chameleon code
49for (( i=1; i <= $numSlices; i++ ));
50do
51stageExistence=0
52stage0FirstBootable=0
53previousExistence="NONE"
54targetDiskRaw=$targetDiskRawNoSlice$i
55
56# Check for existing stage 0 boot file (same code as CheckDiskMicrocode.sh script)
57stage0type=$( dd 2>/dev/null if="$targetDisk" count=3 bs=1 skip=105 | xxd | awk '{print $2$3}' )
58if [ "${stage0type}" == "0b807c" ] || [ "${stage0type}" == "0a803c" ] || [ "${stage0type}" == "ee7505" ] || [ "${stage0type}" == "742b80" ]; then
59#echo "DEBUG: boot0 found on $targetDisk"
60(( stageExistence++ ))
61
62# While here, check just for either existing boot0hfs, boot0md or boot0md (dmazar's boot0workV2)
63if [ "${stage0type}" == "0a803c" ] || [ "${stage0type}" == "ee7505" ] || [ "${stage0type}" == "742b80" ]; then
64stage0FirstBootable=1
65fi
66fi
67
68# Check for existence of a bootable partition boot sector containing either boot1h or boot1f32
69boot1Search=$( dd 2>/dev/null if="$targetDiskRaw" count=1 | perl -ne '@a=split"";for(@a){printf"%02x",ord}' )
70if [ "${boot1Search:0:16}" == "fa31c08ed0bcf0ff" ] && [ "${boot1Search:1020:2}" == "55" ]; then
71#echo "DEBUG: boot1h found on "$targetDiskRaw
72(( stageExistence++ ))
73previousExistence="boot1"
74elif [ "${boot1Search:0:4}" == "e962" ] && [ "${boot1Search:180:12}" == "424f4f542020" ] && [ "${boot1Search:1020:2}" == "55" ]; then
75#echo "DEBUG: boot1f32 found on "$targetDiskRaw
76(( stageExistence++ ))
77previousExistence="boot1f32"
78fi
79
80# Check for existing stage 2 boot file also
81# NOTE: This will fail to find /boot on /Volumes/EFI as it won't be mounted!
82if [ -e "$( df | grep ${targetDisk}s${i} | awk '{ print $6 }' )"/boot ]; then
83#echo "DEBUG: boot found on $targetDiskRaw"
84(( stageExistence++ ))
85fi
86
87#if [ $stageExistence == 3 ] && [ $i -ne $sliceNumber ]; then
88#echo "DEBUG: STOP: There is already an existing Chameleon installation on $targetDiskRaw"
89#"$scriptDir"InstallLog.sh "${installerVolume}" "STOP: There is already an existing Chameleon installation on $targetDiskRaw."
90#"$scriptDir"InstallLog.sh "${installerVolume}" "NOTE: This is allowed and does work as long as you aren't dual booting Windows"
91#"$scriptDir"InstallLog.sh "${installerVolume}" "NOTE: from the same disk and are happy to control which partition is used by"
92#"$scriptDir"InstallLog.sh "${installerVolume}" "NOTE: flagging the required partition active. General use doesn't require two"
93#"$scriptDir"InstallLog.sh "${installerVolume}" "NOTE: Chameleon installs on the same disk, though might be done by advanced users."
94#"$scriptDir"InstallLog.sh "${installerVolume}" "NOTE: If you still want to do this then proceed by installing Chameleon manually."
95#exit 1
96#fi
97
98if [ $stageExistence -ge 2 ] && [ "$previousExistence" != "NONE" ] && [ $i -ne $sliceNumber ]; then
99# There is previous Chameleon stage 1 code on a partition boot sector,
100# and either a complete or incomplete installation (ie. boot0 or boot are missing).
101if [ $stageExistence == 3 ]; then
102"$scriptDir"InstallLog.sh "${installerVolume}" "WARN: There is already an existing Chameleon installation on $targetDiskRaw."
103else
104"$scriptDir"InstallLog.sh "${installerVolume}" "NOTE: $previousExistence already exists at ${targetDisk}s${i}"
105fi
106
107# This could prove problematic and result in either a b1f:error or boot0:error
108# if the following conditions are true:
109# A) Boot0hfs, Boot0md or Boot0md (dmazar's Boot0workV2) is being used.
110# B) The previous stage 1 code is on a lower partiton than the one being installed to now.
111
112# stage0FirstBootable=1 is used to know if 'A' is true.
113if [ $stage0FirstBootable == 1 ]; then
114# i = current slice we're checking, slicenumber = slice trying to install to.
115if [ $i -lt $sliceNumber ]; then
116"$scriptDir"InstallLog.sh "${installerVolume}" "WARN: Conditions point to you receiving a boot failure"
117# Fix by making previous paritionboot sector un-bootable
118# Change Byte 01FExh to 00 (510 decimal)
119"$scriptDir"InstallLog.sh "${installerVolume}" "---"
120"$scriptDir"InstallLog.sh "${installerVolume}" "FIX: Make ${targetDisk}s${i} boot sector un-bootable by changing byte 1FEh to 00."
121"$scriptDir"InstallLog.sh "${installerVolume}" "NOTE: Any Extra folder you had there will still be there. If you want to use"
122"$scriptDir"InstallLog.sh "${installerVolume}" "NOTE: ${targetDisk}s${i} again as your boot partition then re-run this installer"
123"$scriptDir"InstallLog.sh "${installerVolume}" "NOTE: selecting it as the target, ONLY choosing the 'Chameleon Bootloader' option"
124"$scriptDir"InstallLog.sh "${installerVolume}" "NOTE: and NONE of the other options."
125"$scriptDir"InstallLog.sh "${installerVolume}" "---"
126dd if=${targetDisk}s${i} count=1 bs=512 of=/tmp/originalBootSector
127cp /tmp/originalBootSector /tmp/newBootSector
128dd if="$scriptDir/patch" of=/tmp/newBootSector bs=1 count=1 seek=510 conv=notrunc
129dd if=/tmp/newBootSector of=${targetDisk}s${i} count=1 bs=512
130else
131"$scriptDir"InstallLog.sh "${installerVolume}" "NOTE: but won't interfere as you're installing to an earlier partition."
132fi
133else
134"$scriptDir"InstallLog.sh "${installerVolume}" "NOTE: so select to boot that partition (if used) with active flag."
135fi
136fi
137done
138
139#else
140#echo "DEBUG: Just one slice"
141fi
142
143exit 0

Archive Download this file

Revision: 1631