check file for corruption and fallback to golden image if necessary

112 views Asked by At

How can I check in the grub.cfg file the sha1sum of a file and compare it with a stored number?

If it is equal the image can loaded, if not it should switch back to the golden image

I tried following

myLinuxBin='(hd0,msdos2)/bzImage.bin'
myLinuxBinSha1Sum='d15e1a64c0f5dd24052f0cb38b88c9f5d4c30a6c'
if [ "$(sha1sum ${myLinuxBin})" -eq "${myLinuxBinSha1Sum}  ${myLinuxBin}" ]; then
    set default="myRunImage"
else
    set default="myGoldenImage"
fi

But I get the error message

error: syntax error.
error: Incorrect command.
error: syntax error.

Any idea where the error is or how I can handle file check?

1

There are 1 answers

1
ron On

this might be better if it is moved to the linux/unix forum since it's BASH scripting, and GRUB.

your problem seems primarily BASH syntax scripting.

it looks like starting with your "$(sha1sum ${myLinuxBin})" is where you want to execute the program that will return the SHA1 hash of whatever you tell it. I believe your syntax here is wrong.

And it may be easier to dump the resulting hash value into a variable, then do a simple BASH if statement such as if [ $hash_value -e $myLinuxBinSha1Sum ]

You would need the correct BASH syntax for executing the sha1sum executable and dumping the output string into a bash variable named hash_value