mirror of
https://github.com/jarun/nnn.git
synced 2024-11-24 11:51:27 +00:00
Extended md5sum script to support multiple checksums and renamed it to checksum
This commit is contained in:
parent
c499f1cb7f
commit
682e810e6e
64
plugins/checksum
Executable file
64
plugins/checksum
Executable file
|
@ -0,0 +1,64 @@
|
|||
#!/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]
|
||||
# The filename will be checksum_timestamp.checksum_type
|
||||
# If file is used: if the file is a checksum, it does the verification
|
||||
# if the file is not a checksum, it will be created from it
|
||||
# The filename will be filename.checksum_type
|
||||
#
|
||||
# Shell: POSIX compliant
|
||||
# Author: ath3
|
||||
|
||||
selection=~/.config/nnn/.selection
|
||||
resp=f
|
||||
chsum=md5
|
||||
ischksum=0
|
||||
|
||||
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
|
||||
sed 's|'"$PWD/"'||g' < "$selection" | xargs -0 -i ${chsum}sum {} > "checksum_$(date '+%Y%m%d%H%M').$chsum"
|
||||
else
|
||||
if [ -n "$1" ] && [ -f "$1" ]; then
|
||||
for chks in md5 sha1 sha224 sha256 sha384 sha512
|
||||
do
|
||||
if [ "$(echo "$1" | grep \.${chks}$)" ]; then
|
||||
ischksum=1
|
||||
${chks}sum -c < "$1"
|
||||
read
|
||||
exit
|
||||
fi
|
||||
done
|
||||
if [ $ischksum -eq 0 ]; then
|
||||
checksum_type
|
||||
file=$(basename "$1").$chsum
|
||||
${chsum}sum "$1" > "$file"
|
||||
fi
|
||||
fi
|
||||
fi
|
|
@ -1,34 +0,0 @@
|
|||
#!/usr/bin/env sh
|
||||
|
||||
# Description: Create and verify md5 checksums
|
||||
#
|
||||
# If selection is used: it will generate one md5 file containing the checksums and file names
|
||||
# [with paths if they are in another directory]
|
||||
# If file is used: if the file is .md5 file, then it does the check
|
||||
# if the file is not .md5 file, it creates the md5 file from it
|
||||
#
|
||||
# Shell: POSIX compliant
|
||||
# Author: ath3
|
||||
|
||||
selection=~/.config/nnn/.selection
|
||||
resp=f
|
||||
|
||||
if [ -s "$selection" ]; then
|
||||
echo -n "work with selection (s) or current file (f) [default=f]: "
|
||||
read resp
|
||||
fi
|
||||
|
||||
if [ "$resp" = "s" ]; then
|
||||
file=$(basename "$(cat $selection | tr '\0' '\n' | head -n 1)").md5
|
||||
cat "$selection" | sed 's|'"$PWD/"'||g' | xargs -0 -i md5sum {} > "$file"
|
||||
else
|
||||
if ! [ -z "$1" ] && [ -f "$1" ]; then
|
||||
if [ $(echo $1 | grep \.md5$) ]; then
|
||||
cat "$1" | md5sum -c
|
||||
read
|
||||
else
|
||||
file=$(basename "$1").md5
|
||||
md5sum "$1" > "$file"
|
||||
fi
|
||||
fi
|
||||
fi
|
Loading…
Reference in a new issue