#!/bin/bash

# create a 30 M file
echo "Create 30M file and get md5sum"
dd if=/dev/urandom of=somefile.1 bs=1k count=30720

md5sum somefile.1

# create copies of file
for f in 2 3 4 ;
do
   cp somefile.1 somefile.$f
done

echo "Calculate md5sums for copied files"
md5sum somefile.*
echo "execute sync and recalculate md5sums"
sync
md5sum somefile.*

echo "Delete one of the files"
rm somefile.2
md5sum somefile.*
echo "recopy the deleted file"
cp somefile.1 somefile.7
md5sum somefile.*

echo "Creating test folder and some junk files in that folder"
mkdir -p test

cd test

dd if=/dev/urandom of=junk.1 bs=1K count=1

md5sum junk.1

for f in 2 3 4 5 6 7 8 9;
do
   cp junk.1 junk.$f
done

echo "md5sums of all files in test folder"
md5sum junk.*

echo "execute sync and recalculate md5sums"
sync

md5sum junk.*

echo "Remove some files and recreate them"
for f in  3 5 8;
do
   rm junk.$f
done

for f in  8 3 5;
do
   cp junk.1 junk.$f
done

cd ..

echo "Calculate md5sums for 30M files again"
md5sum somefile.*
echo "execute sync and recalculate md5sums"
sync
md5sum somefile.*


