38 lines
819 B
Bash
38 lines
819 B
Bash
# create or check checksums for all files in current directory.
|
|
# usage: checksum <ACTION>
|
|
# actions: "new", "check".
|
|
checksum()
|
|
{
|
|
local action="$1" # what to do with checksum.
|
|
local file="checksum.sha1" # file name to store checksums.
|
|
|
|
if [[ "$action" =~ ^(n|new)$ ]]; then
|
|
# create checksums for all files.
|
|
find -type f | parallel sha1sum {} > "$file"
|
|
|
|
# remove checksum file from resulting hashes.
|
|
sed -i "/$file/d" "$file"
|
|
|
|
return 0
|
|
fi
|
|
|
|
if [[ "$action" =~ ^(c|check)$ ]]; then
|
|
# check checsums for all files.
|
|
sha1sum --quiet -c ./checksum.sha1
|
|
|
|
return 0
|
|
fi
|
|
|
|
# error on wrong action.
|
|
echo "supported actions: new (n), check (c)."
|
|
return 1
|
|
}
|
|
|
|
# autocomplete.
|
|
_checksum()
|
|
{
|
|
_autocomplete_first "{new,check}"
|
|
}
|
|
|
|
complete -F _checksum checksum
|