I am currently working on the LFS project along with the book and a video to guide me through some parts of it. However, as I came across checking the MD5 of some packages the verification of this didn’t seem to work.
I initially tried this approach, but for some reason the echo "$MD5SUM $FILENAME"
appended the file name to the begging of MD5SUM
if ! echo "$MD5SUM $FILENAME" | md5sum -c >/dev/null; then
echo "Verification of $FILENAME failed. MD5 mismatch"
fi
Instead, I tried the following, that despite working perfectly when testing it, didn’t work in this particular case
if [[ $(md5sum "$FILENAME" | cut -d ' ' -f1) != "$MD5SUM" ]]; then
echo "Verification of $FILENAME failed. MD5 mismatch"
fi
As per someone’s request the output of md5sum "$FILENAME" | cut -d ' ' -f1
is 590765dee95907dbc3c856f7255bd669
. On the other hand, the output from md5sum "$FILENAME" | cut -d ' ' -f1 | cat -A
is 590765dee95907dbc3c856f7255bd669$
3
Use stdin instead of providing the filename
md5sum < "$filename"
so you don’t need to cut.
Then you can compare directly.
2
Assuming that MD5SUM
contains the MD5 of file FILENAME
,
if ! md5sum -c --quiet <<<"$MD5SUM $FILENAME"
then
echo Verification failed
fi
should do the job.