Skip to content

Instantly share code, notes, and snippets.

@mmmunk

mmmunk/check-checksums.sh

Last active Jan 15, 2021
Embed
What would you like to do?
Usage of HashDeep (apt install hashdeep)
#!/bin/bash
# Files changed or deleted since checksum creation are noted.
# New files are not noted.
if [ -z "$1" ]; then
DIR=`pwd`
else
DIR=`realpath $1`
fi
cd $DIR
FILE=checksums.sha1
if [ -f $FILE ]; then
echo "Checking files in directory" $DIR "against checksums in file" $FILE
sha1sum --check --quiet --strict $FILE
if [ $? -eq 0 ]; then echo "OK"; fi
else
echo "Creating checksums file"
# find . -type f ! -name "*.sha1" -print0|xargs -0 sha1sum >$FILE
find . -type f ! -name "*.sha1" -exec sha1sum "{}" \; >>$FILE
echo $FILE "has been created in" $DIR
fi
#!/bin/bash
# This is a generic script which can be copied into any level of any
# directory tree which should be manually audited for file changes.
DIR=$(dirname `realpath $0`)
FILE=".checksums"
echo Scanning $DIR
cd $DIR
if [ -f $FILE ]; then
hashdeep -l -r -o f -k $FILE -a -vv *
else
hashdeep -l -r -o f * >$FILE
echo $FILE "has been generated in" $DIR
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment