checksum_update : recreate hashes.
This commit is contained in:
parent
f4f1a0664e
commit
85dd586802
|
@ -359,8 +359,9 @@ Command|Description
|
||||||
|
|
||||||
Command|Description
|
Command|Description
|
||||||
---|---
|
---|---
|
||||||
`checksum new`|Create checksums recursively.
|
`checksum_create`|Create checksums for files in current directory.
|
||||||
`checksum check`|Check previously created checksums.
|
`checksum_check`|Check previously created checksums.
|
||||||
|
`checksum_update`|Check old hashes and create new ones for all the files.
|
||||||
|
|
||||||
## Chmod.
|
## Chmod.
|
||||||
|
|
||||||
|
|
|
@ -1,37 +1,28 @@
|
||||||
# create or check checksums for all files in current directory.
|
checksum_create()
|
||||||
# usage: checksum <ACTION>
|
|
||||||
# actions: "new", "check".
|
|
||||||
checksum()
|
|
||||||
{
|
{
|
||||||
local action="$1" # what to do with checksum.
|
if [[ -f .checksum ]]; then
|
||||||
local file="checksum.sha1" # file name to store checksums.
|
echo -e "${color_bred}Checksum already exists.${color_default}"
|
||||||
|
return 1
|
||||||
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
|
fi
|
||||||
|
|
||||||
if [[ "$action" =~ ^(c|check)$ ]]; then
|
sha1sum * > .checksum 2> /dev/null
|
||||||
# check checsums for all files.
|
|
||||||
sha1sum --quiet -c ./checksum.sha1
|
|
||||||
|
|
||||||
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
|
fi
|
||||||
|
|
||||||
# error on wrong action.
|
sha1sum --quiet -c .checksum && rm .checksum && sha1sum * > .checksum 2> /dev/null
|
||||||
echo "supported actions: new (n), check (c)."
|
|
||||||
return 2
|
|
||||||
}
|
|
||||||
|
|
||||||
# autocomplete.
|
true
|
||||||
_checksum()
|
|
||||||
{
|
|
||||||
_autocomplete_first "{new,check}"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
complete -F _checksum checksum
|
|
||||||
|
|
Reference in a new issue