On Wed, Nov 22, 2023 at 09:49:53AM +0100, Maja Reberc wrote:
> Would you mind sharing the scripts you mentioned for us newbies?

I don't want to encourage people to just copy and paste some random scripts
that were written to meet our needs but most likely don't exactly meet theirs.

But as a _starting point for writing your own_, the following script will let
you create and verify checksums, as well as identify files which don't yet
have a checksum recorded.

All it does is recurse down the directory structure looking for files called
'checksums' in each directory.  If it finds one then it verifies the checksums
it contains and if there are any files which are not listed then it prints a
message to the console with the filename.

So if you wanted to use it to monitor changes to your home directory, you
would just do 'touch checksums' in $HOME, and any subdirectories that you also
wanted to include.  Then invoke the script the first time with 'a' as an
argument to populate those checksum files.

Then, you can just run it with no arguments in $HOME, and it will tell you if
there are any new files, (which you can add by running the script with any
argument other than 'i'), or any changed files, (they will display a FAILED
message).

If you just want to add new files and skip verifying the existing checksums
for speed, the 'a' option will do that.  Likewise, 'i' will create a new
checksums file in a directory that didn't already have one.

Once again, this is intended as an example to get you started writing your
own better version.  I literally wrote and tested this just now in 15 minutes.
It's not what we actually use here.

Note that if a file has changed and fails the checksum, the script still
prints, 'All files have entries in the checksum file'.  This is intentional,
because the changed file is not _new_, it was already known about.  It's just
changed.

#/bin/sh
if [ "$1" == "i" ] ; then touch checksums ; fi
for i in `find . | grep /checksums$` ;
do (
if [ "$1" == "a" ] ; then echo -n "Not v" ; else echo -n "V" ; fi
echo "erifying checksums in directory ${i%/checksums}";
cd ${i%/checksums};
if [ "$1" != "a" ] ; then sha512 -cq checksums; fi
let flag=0;
for j in !(checksums|checksums.bak) ;
do
if [ ! -d $j ] ; then grep "($j)" checksums > /dev/null || { if [ -z "$1" ] ; 
then echo "$j is not in the checksums file!" ; let flag=1 ; else echo "Adding 
$j to checksums file" ; sha512 $j >> checksums ; fi ; } fi ;
done ;
if [ $flag -eq 1 ] ; then echo "Run $0 with any command line arguments to add 
missing entries to the checksums file."; else echo "All files have entries in 
the checksum file."; fi ;
 );
done

Reply via email to