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