#!/bin/bash # sitecheck: Creates an md5sum message digest for the files in a # directory and allows for them to be checked later against it # Copyright (C) 2009 David Leutzinger (leutzdave @ charter.net) # /home/david/bin/Website/CHECKSUMS/sitecheck # 2009-07-27 vs 0.1 # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # ---------- FUNTIONS ---------- create_md5 () { mv "$MD5SUM_FILE.1" "$MD5SUM_FILE.2" mv "$MD5SUM_FILE" "$MD5SUM_FILE.1" date=`date` # This adds the header section # Add the Title and Date echo "CHECKSUMS.md5 created on $date" | tee -a $MD5SUM_FILE # Add the header message cat >> $MD5SUM_FILE << EOF These are the MD5 message digests for the files in this directory. If you want to test your files, use 'md5sum' and compare the values to the ones listed here. To test all these files, use this command: md5sum -bc CHECKSUMS.md5 | less 'md5sum' can be found in the GNU coreutils package on ftp.gnu.org in /pub/gnu, or at any GNU mirror site. MD5 message digest Filename EOF # Find all files and checksum them echo "Finding files in $TOP" echo "" for i in `find $TOP -name "*" | sort` do if [ -f "$i" ];then md5sum -b $i | tee -a $MD5SUM_FILE fi done echo "" echo "$MD5SUM_FILE created" cd $EXEDIR } check_md5 () { mv "$CHECK_LOG.1" "$CHECK_LOG.2" mv "$CHECK_LOG" "$CHECK_LOG.1" mv "$CHECK_LOG_FAIL.1" "$CHECK_LOG_FAIL.2" mv "$CHECK_LOG_FAIL" "$CHECK_LOG_FAIL.1" md5sum -c $MD5SUM_FILE | tee -a $CHECK_LOG grep -v "OK" $CHECK_LOG > $CHECK_LOG_FAIL echo "" echo "----------RESULTS----------" if [ ! -s "$CHECK_LOG_FAIL" ];then echo "$MD5SUM_FILE passed checks" else echo "$MD5SUM_FILE failed checks" cat $CHECK_LOG_FAIL fi } # MAIN PROGRAM # Variable Definitions EXEDIR="/home/david/bin/Website/CHECKSUMS" MD5SUM_FILE="$EXEDIR/sitecheck-dev-CHECKSUMS.md5" CHECK_LOG="$EXEDIR/sitecheck-dev-CHECKSUMS.md5.check" CHECK_LOG_FAIL="$EXEDIR/sitecheck-dev-CHECKSUMS.md5.check.FAIL" TOP="/home/david/http" case "$1" in '--create') echo "Creating CHECKSUMS.md5" create_md5 ;; '--check') echo "Checking CHECKSUMS.md5" check_md5 ;; '--help') echo "Useage $0 --create|--check|-h|--help|" echo " --create Create CHECKSUMS.md5" echo " --check Check CHECKSUMS.md5" echo " --help Long help" echo " -h Short help" ;; *) echo "Useage $0 --create|--check|-h|--help|" esac exit 0