Created
January 9, 2015 15:11
-
-
Save frafra/adee26ec0e3ecb911af7 to your computer and use it in GitHub Desktop.
ext4 with checksums
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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