2019-06-20 01:39:23 +00:00
|
|
|
#!/usr/bin/env sh
|
|
|
|
|
|
|
|
# Description: Create and verify checksums
|
|
|
|
#
|
|
|
|
# If selection is used: it will generate one file containing the checksums with file names
|
|
|
|
# [and with paths if they are in another directory]
|
2019-07-12 03:21:18 +00:00
|
|
|
# The output checksum filename will be checksum_timestamp.checksum_type
|
|
|
|
# If file is used: if the file is a checksum, the plugin does the verification
|
|
|
|
# if the file is not a checksum, checksum will be generated for it
|
|
|
|
# The output checksum filename will be filename.checksum_type
|
2019-06-20 01:39:23 +00:00
|
|
|
#
|
|
|
|
# Shell: POSIX compliant
|
|
|
|
# Author: ath3
|
|
|
|
|
2019-06-20 13:40:47 +00:00
|
|
|
selection=${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection
|
2019-06-20 01:39:23 +00:00
|
|
|
resp=f
|
|
|
|
chsum=md5
|
|
|
|
|
|
|
|
checksum_type()
|
|
|
|
{
|
|
|
|
echo "possible checksums: md5, sha1, sha224, sha256, sha384, sha512"
|
|
|
|
echo -n "create md5 (m), sha256 (s), sha512 (S) (or type one of the above checksums) [default=m]: "
|
|
|
|
read chsum_resp
|
|
|
|
for chks in md5 sha1 sha224 sha256 sha384 sha512
|
|
|
|
do
|
|
|
|
if [ "$chsum_resp" = "$chks" ]; then
|
|
|
|
chsum=$chsum_resp
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
if [ "$chsum_resp" = "s" ]; then
|
|
|
|
chsum=sha256
|
|
|
|
elif [ "$chsum_resp" = "S" ]; then
|
|
|
|
chsum=sha512
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
if [ -s "$selection" ]; then
|
|
|
|
echo -n "work with selection (s) or current file (f) [default=f]: "
|
|
|
|
read resp
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$resp" = "s" ]; then
|
|
|
|
checksum_type
|
2019-08-23 16:13:32 +00:00
|
|
|
sed 's|'"$PWD/"'||g' < "$selection" | xargs -0 -I{} ${chsum}sum {} > "checksum_$(date '+%Y%m%d%H%M').$chsum"
|
2019-06-20 01:39:23 +00:00
|
|
|
else
|
|
|
|
if [ -n "$1" ] && [ -f "$1" ]; then
|
|
|
|
for chks in md5 sha1 sha224 sha256 sha384 sha512
|
|
|
|
do
|
|
|
|
if [ "$(echo "$1" | grep \.${chks}$)" ]; then
|
|
|
|
${chks}sum -c < "$1"
|
2019-08-23 16:13:32 +00:00
|
|
|
read dummy
|
2019-06-20 01:39:23 +00:00
|
|
|
exit
|
|
|
|
fi
|
|
|
|
done
|
2019-06-27 00:42:27 +00:00
|
|
|
checksum_type
|
|
|
|
file=$(basename "$1").$chsum
|
|
|
|
${chsum}sum "$1" > "$file"
|
2019-06-20 01:39:23 +00:00
|
|
|
fi
|
|
|
|
fi
|