1 | #!/bin/bash␊ |
2 | ␊ |
3 | echo "==============================================="␊ |
4 | echo "CheckGRUBLinuxLoader: Does GRUB or LILO exist?"␊ |
5 | echo "**********************************************"␊ |
6 | ␊ |
7 | # This reads the MBR of the disk in the attempt to find the␊ |
8 | # signature for either the GRUB or Linux bootloaders.␊ |
9 | # The script returns 1 if either is found, or 0 if none found.␊ |
10 | ␊ |
11 | # Receives targetdisk: for example, /dev/disk2.␊ |
12 | # Receives targetVolume: Volume to install to.␊ |
13 | # Receives scriptDir: The location of the main script dir.␊ |
14 | ␊ |
15 | if [ "$#" -eq 3 ]; then␊ |
16 | ␉targetDisk="$1"␊ |
17 | ␉targetVolume="$2"␊ |
18 | ␉scriptDir="$3"␊ |
19 | ␉echo "DEBUG: passed argument for targetDisk = $targetDisk"␊ |
20 | ␉echo "DEBUG: passed argument for targetVolume = $targetVolume"␊ |
21 | ␉echo "DEBUG: passed argument for scriptDir = $scriptDir"␊ |
22 | else␊ |
23 | ␉echo "Error - wrong number of values passed"␊ |
24 | ␉exit 9␊ |
25 | fi␊ |
26 | ␊ |
27 | diskmicrocodetype[1]="GRUB,47525542"␊ |
28 | diskmicrocodetype[2]="LILO,4c494c4f"␊ |
29 | ␊ |
30 | diskmicrocode=$( 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 | #echo "DEBUG: ${diskmicrocode}"␊ |
32 | diskmicrocodetypecounter=0␊ |
33 | ␊ |
34 | while [ ${diskmicrocodetypecounter} -lt ${#diskmicrocodetype[@]} ]; do␊ |
35 | diskmicrocodetypecounter=$(( ${diskmicrocodetypecounter} + 1 ))␊ |
36 | diskmicrocodetypeid=${diskmicrocodetype[${diskmicrocodetypecounter}]#*,}␊ |
37 | if [ ! "${diskmicrocode}" = "${diskmicrocode/${diskmicrocodetypeid}/}" ]; then␊ |
38 | echo "${diskmicrocodetype[${diskmicrocodetypecounter}]%,*} found."␊ |
39 | ␉␉exit 1␊ |
40 | ␉#else␊ |
41 | ␉␉#echo "DEBUG: Didn't find a match for ${diskmicrocodetype[${diskmicrocodetypecounter}]%,*}"␊ |
42 | fi␊ |
43 | done␊ |
44 | ␊ |
45 | exit 0 |