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
52echo "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
64echo "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
69echo "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
73fi
74
75if [ "${stage0type}" == "0a803c" ]; then
76echo "Found existing Chameleon stage 0 loader - Boot0"
77"$scriptDir"InstallLog.sh "${targetVolume}" "Target has existing Chameleon stage 0 loader - boot0"
78
79# Script CheckDiskSignature.sh returned 1 if a Windows installation was found
80if [ "$diskSigCheck" = "1" ]; then
81echo "Found existing Windows installation so will replace stage 0 loader with boot0md"
82"$scriptDir"InstallLog.sh "${targetVolume}" "Will replace boot0 with boot0md as Windows is on target disk."
83exit 0
84fi
85fi
86
87if [ "${stage0type}" == "ee7505" ]; then
88echo "Found existing Chameleon stage 0 loader - Boot0md"
89echo "And will leave boot0md installed."
90"$scriptDir"InstallLog.sh "${targetVolume}" "Target has existing Chameleon stage 0 loader - boot0md. Leaving as is."
91exit 1
92fi
93
94if [ "${stage0type}" != "0b807c" ] && [ "${stage0type}" != "0a803c" ] && [ "${stage0type}" != "ee7505" ] && [ "${windowsloader}" != "33c08ed0" ] ; then
95echo "Something other than Chameleon or a Windows bootloader was found"
96test=$(echo "${mbr437}" | awk -F0 '{print NF-1}' )
97echo "Disk microcode found: ${test} - Preserving."
98echo "diskupdate is set to false"
99echo "-----------------------------------------------"
100"$scriptDir"InstallLog.sh "${targetVolume}" "NOTE: Target has existing unrecognised bootcode in the MBR. Leaving as is."
101echo ""
102exit 1
103fi
104fi
105
106echo "diskupdate is now set to true."
107echo "-----------------------------------------------"
108echo ""
109
110exit 0
111

Archive Download this file

Revision: 1579