30 lines
604 B
Bash
Executable File
30 lines
604 B
Bash
Executable File
#!/bin/bash
|
|
|
|
# This script calculates a sha256sum over all files in a dirextory including its subdirectories
|
|
|
|
if [[ -z $1 ]]; then
|
|
echo "Usage: $0 <path to folder>"
|
|
exit -1
|
|
fi
|
|
|
|
if [[ ! -d "$1" ]]; then
|
|
echo "Specified path: $1 is not a directory"
|
|
exit -2
|
|
fi
|
|
|
|
search_dir="$1"
|
|
|
|
filelist=()
|
|
while IFS= read -d $'\0' -r file ; do
|
|
filelist=("${filelist[@]}" "$file")
|
|
done < <(find "$search_dir" -type f -print0 | sort -z)
|
|
|
|
echo "Found ${#filelist[@]} files"
|
|
|
|
# Calculate shasums over all files
|
|
shasum=`for file in "${filelist[@]}"; do
|
|
sha256sum "$file"
|
|
done | sha256sum | sed 's/\s-//'`
|
|
|
|
echo "$shasum"
|