dotfiles

regexghost dotfiles and scripts
git clone https://git.regexghost.com/dotfiles.git
Log | Files | Refs | README

hashfolder.sh (613B)


      1 #!/usr/bin/env bash
      2 
      3 # Script to get sha256/sha512 hashes of all files in a directory
      4 
      5 if [[ "$1" == "" ]]; then
      6 	echo "Usage: ./hashfolder.sh [-l] folder"
      7 	echo "  -l for sha512"
      8 	exit
      9 fi
     10 
     11 hash_command="sha256sum"
     12 input_folder="$1"
     13 
     14 if [[ "$1" == "-h" ]]; then
     15 	echo "Usage: hashfolder [-l] folder/ (-l for sha512 instead of sha256)"
     16 elif [[ "$1" == "-l" ]]; then
     17 	hash_command="sha512sum"
     18 	input_folder="$2"
     19 fi
     20 
     21 # There is probably a better way of doing this
     22 oldIFS="$IFS"
     23 IFS=$'\n'
     24 filesA=( $(find "$input_folder" -type f | sort) )
     25 IFS="$oldIFS"
     26 
     27 for fileA in "${filesA[@]}"; do
     28 	"$hash_command" "$fileA"
     29 done