Chameleon

Chameleon Svn Source Tree

Root/branches/blackosx/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
40#echo "DEBUG: ${mbr437}"
41
42if [ $( echo "${mbr437}" | awk -F0 '{print NF-1}' ) = 874 ]; then
43echo "The first 437 bytes of the MBR Disk Sector is blank - Updating"
44#"$scriptDir"InstallLog.sh "${targetVolume}" "Target has no bootcode in the MBR disk sector."
45else
46# There is already something on the MBR
47
48# See if a Windows bootloader already exists
49# Check bytes 440-443 of the GPTdiskProtectiveMBR for a Windows Disk Signature
50windowsloader=$( dd 2>/dev/null if="$targetDisk" count=4 bs=1 | xxd | awk '{print $2$3}' )
51if [ "${windowsloader}" == "33c08ed0" ] ; then
52#echo "DEBUG: Found existing Windows Boot Loader so will replace with Chameleon boot0md"
53"$scriptDir"InstallLog.sh "${targetVolume}" "Target has existing Windows boot loader - Will replace with boot0md"
54fi
55
56# See if a Chameleon stage0 boot file already exists
57
58# Note: The checks for Boot0 and Boot0hfs assume the code stays the same.
59# if the code changes then the hex values 0b807c, 0a803c and ee7505 used for matching
60# need to be checked to see if they are the same or not.
61
62stage0type=$( dd 2>/dev/null if="$targetDisk" count=3 bs=1 skip=105 | xxd | awk '{print $2$3}' )
63if [ "${stage0type}" == "0b807c" ]; then
64#echo "DEBUG: Target has existing Chameleon stage 0 loader - Boot0hfs"
65"$scriptDir"InstallLog.sh "${targetVolume}" "Target has existing Chameleon stage 0 loader - boot0hfs"
66
67# Script CheckDiskSignature.sh returned 0 if a Windows installation was NOT found
68if [ "$diskSigCheck" == "0" ]; then
69#echo "DEBUG: Found no existing Windows installation so will replace stage 0 loader with Boot0"
70"$scriptDir"InstallLog.sh "${targetVolume}" "Will replace boot0hfs with boot0 as Windows is not on target disk."
71exit 0
72fi
73exit 1
74fi
75
76if [ "${stage0type}" == "0a803c" ]; then
77#echo "DEBUG: Found existing Chameleon stage 0 loader - Boot0"
78"$scriptDir"InstallLog.sh "${targetVolume}" "Target has existing Chameleon stage 0 loader - boot0"
79
80# Script CheckDiskSignature.sh returned 1 if a Windows installation was found
81if [ "$diskSigCheck" = "1" ]; then
82#echo "DEBUG: Found existing Windows installation so will replace stage 0 loader with boot0md"
83"$scriptDir"InstallLog.sh "${targetVolume}" "Will replace boot0 with boot0md as Windows is on target disk."
84exit 0
85fi
86exit 1
87fi
88
89if [ "${stage0type}" == "ee7505" ]; then
90#echo "DEBUG: Found existing Chameleon stage 0 loader - Boot0md"
91#echo "DEBUG: And will leave boot0md installed."
92"$scriptDir"InstallLog.sh "${targetVolume}" "Target has existing Chameleon stage 0 loader - boot0md. Leaving as is."
93exit 1
94fi
95
96if [ "${stage0type}" != "0b807c" ] && [ "${stage0type}" != "0a803c" ] && [ "${stage0type}" != "ee7505" ] && [ "${windowsloader}" != "33c08ed0" ] ; then
97#echo "DEBUG: Something other than Chameleon or a Windows bootloader was found"
98test=$(echo "${mbr437}" | awk -F0 '{print NF-1}' )
99#echo "DEBUG: Disk microcode found: ${test} - Preserving."
100#echo "DEBUG: diskupdate is set to false"
101#echo "DEBUG: -----------------------------------------------"
102"$scriptDir"InstallLog.sh "${targetVolume}" "NOTE: Target has existing unrecognised bootcode in the MBR. Leaving as is."
103exit 1
104fi
105fi
106
107echo "diskupdate is now set to true."
108echo "-----------------------------------------------"
109echo ""
110
111exit 0
112

Archive Download this file

Revision: 1615