checksum_update : recreate hashes.

This commit is contained in:
Dmitry Voronin 2023-11-22 14:51:46 +03:00
parent f4f1a0664e
commit 85dd586802
2 changed files with 22 additions and 30 deletions

View file

@ -359,8 +359,9 @@ Command|Description
Command|Description
---|---
`checksum new`|Create checksums recursively.
`checksum check`|Check previously created checksums.
`checksum_create`|Create checksums for files in current directory.
`checksum_check`|Check previously created checksums.
`checksum_update`|Check old hashes and create new ones for all the files.
## Chmod.

View file

@ -1,37 +1,28 @@
# create or check checksums for all files in current directory.
# usage: checksum <ACTION>
# actions: "new", "check".
checksum()
checksum_create()
{
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
if [[ -f .checksum ]]; then
echo -e "${color_bred}Checksum already exists.${color_default}"
return 1
fi
if [[ "$action" =~ ^(c|check)$ ]]; then
# check checsums for all files.
sha1sum --quiet -c ./checksum.sha1
sha1sum * > .checksum 2> /dev/null
return 0
sed -i "/\.checksum/d" .checksum
}
checksum_check()
{
sha1sum --quiet -c .checksum
}
checksum_update()
{
if [[ ! -f .checksum ]]; then
echo -e "${color_bred}Checksum doesn't exists.${color_default}"
return 1
fi
# error on wrong action.
echo "supported actions: new (n), check (c)."
return 2
}
sha1sum --quiet -c .checksum && rm .checksum && sha1sum * > .checksum 2> /dev/null
# autocomplete.
_checksum()
{
_autocomplete_first "{new,check}"
true
}
complete -F _checksum checksum