9

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?

3 Answers 3

9

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.

2
  • the really critical part here, I guess would be the md5sum -c part of it?
    – Journeyman Geek
    Nov 3, 2012 at 12:24
  • essentially yes op (and I) wanted an automated solution. This just adds all the cmds together. if you already have the files then just the md5sum -c will work just fine
    – wuxmedia
    Nov 3, 2012 at 12:27
3

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'.

3
  • shell aliases don't accept parameters ($1 etc), that's what functions are for.
    – nohillside
    Aug 4, 2012 at 9:30
  • I always catch myself on this, but i think they don't accept parameters because of security reason.
    – okobaka
    Aug 8, 2012 at 13:23
  • No, but because of how they work. Basically an alias results in a text substitution of the alias with its 'value'. That's why alias ll=ls -l does the "right" thing when ll *.foo is called (which gets expanded to ls -l *.foo and afterwards executed).
    – nohillside
    Aug 8, 2012 at 15:55
2

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) ]

Not the answer you're looking for? Browse other questions tagged .