This repository has been archived on 2024-03-04. You can view files and clone it, but cannot push or open issues or pull requests.
linux/document/linux/config/bash/module/checksum.sh

36 lines
758 B
Bash
Raw Normal View History

2023-08-08 16:24:15 +03:00
# create or check checksums for all files in current directory.
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
}
2023-10-23 00:36:27 +03:00
# autocomplete.
_checksum()
{
autocomplete "{new,check}"
}
complete -F _checksum checksum