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.

45 lines
1.4 KiB

#! /bin/bash
function sha1_dir() {
local target=$1
for file in `ls $1` ;do
local current="${target}/${file}"
if [ -d "${current}" ]; then
sha1_dir "${current}"
else
if [ "${file##*.}" == "sha1sum" ]; then
continue
fi
_total=$(($_total + 1))
if [ -s "${current}.sha1sum" ]; then
echo "[:)] SHA-1 sum for \"${current}\" already exists, skipping..."
else
echo "[:|] Calculating SHA-1 sum for \"$current\"..."
pushd "${target}" >/dev/null 2>&1
local current_sum=$(sha1sum "${file}")
popd >/dev/null 2>&1
if [ $? -eq 0 ]; then
echo "[:)] Checksum calculation completed (${current_sum})"
echo "${current_sum}" > "${current}.sha1sum"
_cal=$(($_cal + 1))
else
echo "[:X] Checksum calculation error for \"${current}=\"!"
_err=$(($_err + 1))
fi
fi
fi
done
}
if [ $# -gt 0 ]; then
_total=0
_cal=0
_err=0
while [ $# -gt 0 ]; do
sha1_dir $1
shift
done
echo "[:O] Found $_total files, calculated $_cal, with $_err error(s) happened."
else
echo "Usage: $0 path/to/dir1 [path/to/dir2 [path/to/dir3 ...]]"
fi