Chameleon Applications

Chameleon Applications Svn Source Tree

Root/branches/blackosx/trunk/PackageBuilder/Main_Package_Elements/Scripts/CheckDiskMicrocode.sh

  • Property svn:executable set to *
1#!/bin/bash
2
3echo "==============================================="
4echo "Entering CheckDiskMicrocode:"
5echo "****************************"
6
7# This script is passed the targetDisk and diskSigCheck.
8#
9# it then reads the GPTdiskProtectiveMBR and searches for an existing
10# Windows bootloader and also for an existing Chameleon stage 0 loader
11# which might be better changed depending on whether or not a Windows
12# signature is found or not.
13#
14# The script then exits with the value 1 to indicate that Chameleon stage0
15# loader can be written, or 0 to indicate not to write the stage0 loader.
16
17if [ "$#" -eq 2 ]; then
18targetDisk="$1"
19diskSigCheck="$2"
20echo "DEBUG: passed argument for targetDisk = $targetDisk"
21echo "DEBUG: passed argument for diskSigCheck = $diskSigCheck"
22else
23echo "Error - wrong number of values passed - Exiting"
24exit 9
25fi
26
27
28# read the first 437 bytes of the MBR
29
30mbr437=$( 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}' )
31#mbr437md5=$( dd 2>/dev/null if="$targetDisk" count=1 | dd 2>/dev/null count=1 bs=437 | md5 )
32
33#echo "DEBUG: ${mbr437}"
34
35if [ $( echo "${mbr437}" | awk -F0 '{print NF-1}' ) = 874 ]; then
36echo "The first 437 bytes of the MBR Disk Sector is blank - Updating"
37echo "diskupdate is now set to true."
38echo "-----------------------------------------------"
39echo ""
40exit 1
41else
42# There is already something on the MBR
43
44# See if a Windows bootloader already exists
45# Check bytes 440-443 of the GPTdiskProtectiveMBR for a Windows Disk Signature
46windowsloader=$( dd 2>/dev/null if="$targetDisk" count=4 bs=1 | xxd | awk '{print $2$3}' )
47if [ "${windowsloader}" == "33c08ed0" ] ; then
48echo "Found existing Windows Boot Loader so will replace with Chameleon Boot0hfs"
49echo "diskupdate is now set to true."
50echo "-----------------------------------------------"
51echo ""
52exit 1
53fi
54
55# See if a Chameleon stage0 boot file already exists
56
57# Note: The checks for Boot0 and Boot0hfs assume the code stays the same.
58# if the code changes then the hex values 0b807c and 0a803c used for matching
59# need to be checked to see if they are the same or not.
60
61stage0type=$( dd 2>/dev/null if="$targetDisk" count=3 bs=1 skip=105 | xxd | awk '{print $2$3}' )
62echo ${stage0type}
63if [ "${stage0type}" == "0b807c" ]; then
64echo "Found existing Chameleon stage 0 loader - Boot0hfs"
65
66# CheckDiskSignature.sh returns 0 if a Windows installation was NOT found
67if [ "$diskSigCheck" == "0" ]; then
68echo "Found no existing Windows installation so will replace stage 0 loader with Boot0"
69echo "diskupdate is now set to true."
70echo "-----------------------------------------------"
71echo ""
72exit 1
73fi
74fi
75
76if [ "${stage0type}" == "0a803c" ]; then
77echo "Found existing Chameleon stage 0 loader - Boot0"
78
79# CheckDiskSignature.sh returns 1 if a Windows installation was found
80if [ "$diskSigCheck" = "1" ]; then
81echo "Found existing Windows installation so will replace stage 0 loader with Boot0hfs"
82echo "diskupdate is now set to true."
83echo "-----------------------------------------------"
84echo ""
85exit 1
86fi
87fi
88
89# If neither Chameleon Boot Loader or Windows loader exists
90if [ "${stage0type}" != "0b807c" ] && [ "${stage0type}" != "0a803c" ] && [ "${windowsloader}" != "33c08ed0" ] ; then
91test=$(echo "${mbr437}" | awk -F0 '{print NF-1}' )
92echo "Disk microcode found: ${test} - Preserving."
93echo "diskupdate is left at false"
94echo "-----------------------------------------------"
95echo ""
96exit 0
97fi
98fi
99
100
101echo "-----------------------------------------------"
102echo ""
103echo ""
104
105exit 0
106

Archive Download this file

Revision: 221