Chameleon

Chameleon Svn Source Tree

Root/branches/ErmaC/Modules/package/Scripts/Sub/CheckDiskMicrocode.sh

  • Property svn:executable set to *
1#!/bin/bash
2
3echo "==============================================="
4echo "CheckDiskMicrocode: Any existing bootloaders?"
5echo "*********************************************"
6
7# Reads the GPTdiskProtectiveMBR and searches for an existing
8# Windows bootloader and also for an existing Chameleon stage 0 loader
9# which might be better changed depending on whether or not a Windows
10# signature is found or not.
11# The script then exits with the value 0 to indicate that Chameleon stage0
12# loader can be written, or 1 to indicate not to write the stage0 loader.
13
14# Receives targetDisk: for example, /dev/disk2.
15# Receives diskSigCheck: 0 = Windows not installed / 1 = Windows installed.
16# Receives targetVolume: Volume to install to.
17# Receives scriptDir: The location of the main script dir.
18
19
20if [ "$#" -eq 4 ]; then
21targetDisk="$1"
22diskSigCheck="$2"
23targetVolume="$3"
24scriptDir="$4"
25echo "DEBUG: passed argument for targetDisk = $targetDisk"
26echo "DEBUG: passed argument for diskSigCheck = $diskSigCheck"
27echo "DEBUG: passed argument for targetVolume = $targetVolume"
28echo "DEBUG: passed argument for scriptDir = $scriptDir"
29else
30echo "Error - wrong number of values passed - Exiting"
31exit 9
32fi
33
34
35# read the first 437 bytes of the MBR
36
37mbr437=$( dd 2>/dev/null if="$targetDisk" count=1 | dd 2>/dev/null count=1 bs=437 | perl -ne '@a=split"";for(@a){printf"%02x",ord}' )
38#mbr437md5=$( dd 2>/dev/null if="$targetDisk" count=1 | dd 2>/dev/null count=1 bs=437 | md5 )
39
40if [ $( echo "${mbr437}" | awk -F0 '{print NF-1}' ) != 874 ]; then
41# There is already something on the MBR
42
43# See if a Windows bootloader already exists
44# Check bytes 440-443 of the GPTdiskProtectiveMBR for a Windows Disk Signature
45windowsloader=$( dd 2>/dev/null if="$targetDisk" count=4 bs=1 | xxd | awk '{print $2$3}' )
46if [ "${windowsloader}" == "33c08ed0" ] ; then
47#echo "DEBUG: Found existing Windows Boot Loader so will replace with Chameleon boot0md"
48"$scriptDir"InstallLog.sh "${targetVolume}" "Target disk has existing Windows boot loader - Will replace with boot0md"
49fi
50
51# See if a Chameleon stage0 boot file already exists
52
53# Note: The checks for Boot0, Boot0hfs, Boot0md and Boot0md (dmazar's Boot0workV2) assume the code stays the same.
54# if the code changes then the hex values 0b807c, 0a803c, ee7505 and 742b80 used for matching
55# need to be checked to see if they are the same or not.
56
57stage0type=$( dd 2>/dev/null if="$targetDisk" count=3 bs=1 skip=105 | xxd | awk '{print $2$3}' )
58if [ "${stage0type}" == "0b807c" ]; then
59#echo "DEBUG: Target has existing Chameleon stage 0 loader - Boot0hfs"
60"$scriptDir"InstallLog.sh "${targetVolume}" "Target disk already has existing Chameleon stage 0 loader - boot0hfs"
61
62# Script CheckDiskSignature.sh returned 0 if a Windows installation was NOT found
63if [ "$diskSigCheck" == "0" ]; then
64#echo "DEBUG: Found no existing Windows installation so will replace stage 0 loader with Boot0"
65"$scriptDir"InstallLog.sh "${targetVolume}" "Will replace boot0hfs with boot0 as Windows is not on target disk."
66exit 0
67fi
68exit 1
69fi
70
71if [ "${stage0type}" == "0a803c" ]; then
72#echo "DEBUG: Found existing Chameleon stage 0 loader - Boot0"
73"$scriptDir"InstallLog.sh "${targetVolume}" "Target disk already has existing Chameleon stage 0 loader - boot0"
74
75# Script CheckDiskSignature.sh returned 1 if a Windows installation was found
76if [ "$diskSigCheck" = "1" ]; then
77#echo "DEBUG: Found existing Windows installation so will replace stage 0 loader with boot0md"
78"$scriptDir"InstallLog.sh "${targetVolume}" "Will replace boot0 with boot0md (boot0workV2) as Windows is on target disk."
79exit 0
80fi
81exit 1
82fi
83
84if [ "${stage0type}" == "ee7505" ]; then
85#echo "DEBUG: Found existing Chameleon stage 0 loader - Boot0md"
86#echo "DEBUG: And will leave boot0md installed."
87"$scriptDir"InstallLog.sh "${targetVolume}" "Target disk already has existing Chameleon stage 0 loader - boot0md."
88exit 1
89fi
90
91if [ "${stage0type}" == "742b80" ]; then
92#echo "DEBUG: Found existing Chameleon stage 0 loader - Boot0workV2"
93#echo "DEBUG: And will leave Boot0workV2 installed."
94"$scriptDir"InstallLog.sh "${targetVolume}" "Target disk already has existing Chameleon stage 0 loader - Boot0workV2."
95exit 1
96fi
97
98if [ "${stage0type}" != "0b807c" ] && [ "${stage0type}" != "0a803c" ] && [ "${stage0type}" != "ee7505" ] && [ "${stage0type}" != "742b80" ] && [ "${windowsloader}" != "33c08ed0" ] ; then
99#echo "DEBUG: Something other than Chameleon or a Windows bootloader was found"
100test=$(echo "${mbr437}" | awk -F0 '{print NF-1}' )
101#echo "DEBUG: Disk microcode found: ${test} - Preserving."
102#echo "DEBUG: diskupdate is set to false"
103#echo "DEBUG: -----------------------------------------------"
104"$scriptDir"InstallLog.sh "${targetVolume}" "NOTE: Target has existing unrecognised bootcode in the MBR. Leaving as is."
105exit 1
106fi
107#else
108#echo "DEBUG: The first 437 bytes of the MBR Disk Sector is blank - Updating"
109#"$scriptDir"InstallLog.sh "${targetVolume}" "Target has no bootcode in the MBR disk sector."
110fi
111
112echo "diskupdate is now set to true."
113echo "-----------------------------------------------"
114echo ""
115
116exit 0
117

Archive Download this file

Revision: 1631