Is there a tool that automatically downloads and compares md5sums? [closed]
What I want but can't find:
$ download -url http://download.com/me.zip -md5 http://download.com/me.md5
[================================================================>] 100%
md5check .... OK
$
But what I have to do with my current knowledge is this:
$ wget http://download.com/me.zip
$ md5sum me.zip
12345....6789 me.zip
#use eyes for comparison
Is there any tool, that can do that for me? Or do I need to write a shell script for that?
Solution 1:
This should work just fine.
wget ftp://yourfile.zip && wget ftp://yourfile.zip.md5 && md5sum -c *.md5
this is less to type;
wget ftp://yourfile{.zip,.zip.md5} && md5sum -c *.md5
Wildcards are a bit much in a crowded download folder, so adjust to your needs.
Solution 2:
Updated some stuff, now it's working.
First download the file:
wget http://source.tar.gz
Then download the md5sum of file.
wget http://source.md5 -o source.tar.gz.md5
So it looks like this:
$ ls
source.tar.gz
source.tar.gz.md5
Then: vi /bin/md5check.sh
#!/bin/bash
key=$1
[ ! -f "$key" ] && echo "sth done: There is no md5 file to check: $key" && exit
[ ! -f "${key%.*}" ] && echo "sth done: There is no source file to check: ${key%.*}" && exit
[ ! "${key##*.}" == "md5" ] && echo "usage:$0 file.tar.gz.md5" && exit
mdsum=(`md5sum -- "${key%.*}"`);
mdsum_md5=(`head -n1 "$key"`);
[ "${mdsum}" == "" ] || [ "${mdsum_md5}" == "" ] && echo "Propably program error, check spaces or special characters in filenames. md5sum:"${mdsum}" file:"${mdsum_md5} && return;
if [ "${mdsum}" == "$mdsum_md5" ];
then echo " done: CHECKED all ok"
else echo -e " done: WARRNING MD5 sums are not equal!\t(${key})" && echo $mdsum && head -n1 "$key"
fi
and
chmod 700 md5check.sh
So I can
./md5check.sh source.tar.gz.md5
done: CHECKED all ok
./md5check.sh source.tar.gz.md5
done: WARRNING MD5 sums are not equal! (source.tar.gz.md5)
db41373e270b06c00dd3d2c89b95899a
db21373e270b06c00dd3d2c89b95899a source.tar.gz
And where is the download part mentioned earlier?
wget http://source.tar.gz && wget http://source.md5 -o source.tar.gz.md5 && /bin/md5check.sh source.tar.gz.md5
Now you can alias it:
this is wrong: alias md5dl="wget $1 && wget $2 -o $(basename $1).md5 && /bin/md5check.sh $(basename $1).md5"
Still don't know, why aliases don't want to function like above, so if using bash vi .bash_profile
and add:
function md5dl() {
wget $1 && wget $2 -o $(basename $1).md5 && /bin/md5check.sh $(basename $1).md5
}
Reload profile source .bash_profile
And final move would be:
md5dl http://download.com/me.zip http://download.com/me.md5
But in my opinion: better way is to (1st) download all the required files and (2nd) then compare, all types 'md5,asc,sign,sha1' at once in download directory. Even better would be monitor and auto check download folder for 'md5,asc,sign,sha1'.
Solution 3:
Unless my bash-fu failed me, this should work. You only have to have wget
and curl
. Save this as download-compare.sh
or similar, then run chmod +x
on the file.
Now, run as:
./download-compare http://example.com/file.tar.gz http://example.com/sum.md5
This only works with the BSD md5
that comes with OS X:
#!/bin/bash
wget "$1"
checksum=$(curl "$2")
if [ "$checksum" == $(md5 -q $(basename "$1")) ]
then
echo "Checksum correct."
else
echo "Checksum false."
fi
Exchanging the if
line should work for Linux – but I can't test it:
if [ "$checksum" == $(md5sum $(basename "$1") | cut -d ' ' -f 1) ]