Chameleon

Chameleon Svn Source Tree

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

Archive Download this file

Revision: 1545