#!/bin/bash # # check-md5s version 1.1 (11/09/1999) # # Simple script to check the validity of the CD. # # Usage: check-md5s /path/to/md5sums.txt # # Returns 0 if no invalid checksums were found, 1 otherwise. # # This script is in the public domain, use as you please (but I do like # getting credit, cash and/or feedback from my work, hint hint). # # - Bjarni R. Einarsson # http://bre.klaki.net/ # ############################################################################# if [ "$1" = "" ]; then SUMS=misc/md5sums.txt if [ -e md5sums.txt ]; then cd .. fi else SUMS=$1 fi if [ ! -e $SUMS ]; then echo "Couldn't find $SUMS!" echo echo "Usage: $0 /path/to/md5sums.txt" exit 1 fi FNUM=$(wc -l $SUMS|awk '{print $1}') COUNT=1 SP=" " BAD=0 echo "Verifying $FNUM MD5 sums, this may take a while..." cat $SUMS \ | while read MD5SUM FILENAME; do if [ ! -e "$FILENAME" ]; then echo "File not found: $FILENAME" else echo -n -e "MD5: $COUNT/$FNUM $FILENAME\r" NEWSUM=$(md5sum "$FILENAME" |awk '{print $1}') if [ $NEWSUM != $MD5SUM ]; then echo "Bad:" BAD=$BAD+1 fi fi let COUNT=$COUNT+1 echo -n -e "$SP\r" done if [ $BAD != 0 ]; then echo echo "$BAD files had invalid MD5 checksums!" exit 1 fi exit 0