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 "CheckDiskMicrocode: Any existing bootloaders?"
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 0 to indicate that Chameleon stage0
15# loader can be written, or 1 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"
37else
38# There is already something on the MBR
39
40# See if a Windows bootloader already exists
41# Check bytes 440-443 of the GPTdiskProtectiveMBR for a Windows Disk Signature
42windowsloader=$( dd 2>/dev/null if="$targetDisk" count=4 bs=1 | xxd | awk '{print $2$3}' )
43if [ "${windowsloader}" == "33c08ed0" ] ; then
44echo "Found existing Windows Boot Loader so will replace with Chameleon Boot0hfs"
45fi
46
47# See if a Chameleon stage0 boot file already exists
48
49# Note: The checks for Boot0 and Boot0hfs assume the code stays the same.
50# if the code changes then the hex values 0b807c and 0a803c used for matching
51# need to be checked to see if they are the same or not.
52
53stage0type=$( dd 2>/dev/null if="$targetDisk" count=3 bs=1 skip=105 | xxd | awk '{print $2$3}' )
54echo ${stage0type}
55if [ "${stage0type}" == "0b807c" ]; then
56echo "Found existing Chameleon stage 0 loader - Boot0hfs"
57
58# Script CheckDiskSignature.sh returned 0 if a Windows installation was NOT found
59if [ "$diskSigCheck" == "0" ]; then
60echo "Found no existing Windows installation so will replace stage 0 loader with Boot0"
61fi
62fi
63
64if [ "${stage0type}" == "0a803c" ]; then
65echo "Found existing Chameleon stage 0 loader - Boot0"
66
67# Script CheckDiskSignature.sh returned 1 if a Windows installation was found
68if [ "$diskSigCheck" = "1" ]; then
69echo "Found existing Windows installation so will replace stage 0 loader with Boot0hfs"
70fi
71fi
72
73if [ "${stage0type}" != "0b807c" ] && [ "${stage0type}" != "0a803c" ] && [ "${windowsloader}" != "33c08ed0" ] ; then
74echo "Something other than Chameleon or a Windows bootloader was found"
75test=$(echo "${mbr437}" | awk -F0 '{print NF-1}' )
76echo "Disk microcode found: ${test} - Preserving."
77echo "diskupdate is set to false"
78echo "-----------------------------------------------"
79echo ""
80exit 1
81fi
82fi
83
84echo "diskupdate is now set to true."
85echo "-----------------------------------------------"
86echo ""
87
88exit 0
89

Archive Download this file

Revision: 255