My build of nnn with minor changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

65 line
1.9 KiB

  1. #!/usr/bin/env sh
  2. # Description: Create and verify checksums
  3. #
  4. # If selection is used: it will generate one file containing the checksums with file names
  5. # [and with paths if they are in another directory]
  6. # The filename will be checksum_timestamp.checksum_type
  7. # If file is used: if the file is a checksum, it does the verification
  8. # if the file is not a checksum, it will be created from it
  9. # The filename will be filename.checksum_type
  10. #
  11. # Shell: POSIX compliant
  12. # Author: ath3
  13. selection=${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection
  14. resp=f
  15. chsum=md5
  16. ischksum=0
  17. checksum_type()
  18. {
  19. echo "possible checksums: md5, sha1, sha224, sha256, sha384, sha512"
  20. echo -n "create md5 (m), sha256 (s), sha512 (S) (or type one of the above checksums) [default=m]: "
  21. read chsum_resp
  22. for chks in md5 sha1 sha224 sha256 sha384 sha512
  23. do
  24. if [ "$chsum_resp" = "$chks" ]; then
  25. chsum=$chsum_resp
  26. return
  27. fi
  28. done
  29. if [ "$chsum_resp" = "s" ]; then
  30. chsum=sha256
  31. elif [ "$chsum_resp" = "S" ]; then
  32. chsum=sha512
  33. fi
  34. }
  35. if [ -s "$selection" ]; then
  36. echo -n "work with selection (s) or current file (f) [default=f]: "
  37. read resp
  38. fi
  39. if [ "$resp" = "s" ]; then
  40. checksum_type
  41. sed 's|'"$PWD/"'||g' < "$selection" | xargs -0 -i ${chsum}sum {} > "checksum_$(date '+%Y%m%d%H%M').$chsum"
  42. else
  43. if [ -n "$1" ] && [ -f "$1" ]; then
  44. for chks in md5 sha1 sha224 sha256 sha384 sha512
  45. do
  46. if [ "$(echo "$1" | grep \.${chks}$)" ]; then
  47. ischksum=1
  48. ${chks}sum -c < "$1"
  49. read
  50. exit
  51. fi
  52. done
  53. if [ $ischksum -eq 0 ]; then
  54. checksum_type
  55. file=$(basename "$1").$chsum
  56. ${chsum}sum "$1" > "$file"
  57. fi
  58. fi
  59. fi