Skip to content

Instantly share code, notes, and snippets.

@frafra
Created January 9, 2015 15:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frafra/adee26ec0e3ecb911af7 to your computer and use it in GitHub Desktop.
Save frafra/adee26ec0e3ecb911af7 to your computer and use it in GitHub Desktop.
ext4 with checksums
#!/bin/bash
#
# By Frafra (http://frafra.eu)
#(shopt -s globstar;
# for f in **
# do
# if [ -f "$f" ]
# then
# echo -ne "$f\0"
# fi
# done) |
# Genera i checksum
find . -type f -print0 |
xargs --max-args=1 --max-procs=$(getconf _NPROCESSORS_ONLN) -0 -I '{}' \
sh -c 'setfattr -n user.sha1sum -v $(sha1sum "{}" | cut -f1 -d" ") "{}"'
# Controlla i checksum
getfattr -Rd . | xargs -L2 | xargs --max-args=1 --max-procs=$(getconf _NPROCESSORS_ONLN) -I '{}' \
sh -c '
path=$(echo "{}" | cut -f3 -d" ")
sha1sum=$(echo "{}" | grep -Po "user.sha1sum=\K([0-9a-f]+)")
sha1sum_current=$(sha1sum "$path" | cut -f1 -d" ")
if [ "$sha1sum" != "$sha1sum_current" ]
then
echo "Wrong checksum for $path: $sha1sum (expected) $sha1sum_current (current)"
fi'
# Rimuove i checksum
find . -type f -print0 |
xargs --max-args=1 --max-procs=$(getconf _NPROCESSORS_ONLN) -0 -I '{}' \
sh -c 'setfattr -x user.sha1sum "{}"'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment