fuel-mirror/util/checksum.sh
Sergey Kulanov f2bccfc0b3 Bump version to 7.0. Update code from upstream repo
1. Bump version to 7.0

2. Use perestroika v5 repo schema

3. Fixing pool permissions after rsync
This change corrects the permissions of the pool folder so that it can
be consumed as a repository mirror via nginx.

4. Add packages (deb, rpm) specs

Related-bug: #1478118
Related-bug: #1476561
Change-Id: Iada03ddab5b7d551f13692cb1c87a634c2f10947
2015-08-11 17:41:01 +03:00

42 lines
1.3 KiB
Bash

check_file()
{
checksum_file=$1
root=$2
file_to_check=$3
debug_job_start "Checking checksum of file '$root/$file_to_check'"
file_records=`grep "$file_to_check" "$checksum_file" | sort -u`
IFS='
'
[[ -z "$file_records" ]] && echo -n "checksums not found..." \
&& debug_job_skip && return 0
for file_record in $file_records; do
expected_checksum_type=`echo $file_record | awk '{print $1}'`
expected_checksum=`echo $file_record | awk '{print $2}'`
shopt -s nocasematch
if [[ $expected_checksum_type == "MD5" ]]; then
echo -n "MD5..."
actual_checksum=`md5sum "$root/$file_to_check" | head -c 32`
elif [[ $expected_checksum_type == "SHA1" ]] || [[ $expected_checksum_type == "SHA" ]]; then
echo -n "SHA1..."
actual_checksum=`sha1sum "$root/$file_to_check" | head -c 40`
elif [[ $expected_checksum_type == "SHA256" ]]; then
echo -n "SHA256..."
actual_checksum=`sha256sum "$root/$file_to_check" | head -c 64`
elif [[ $expected_checksum_type == "NONE" ]]; then
echo -n "NONE..."
actual_checksum=$expected_checksum
fi
shopt -u nocasematch
[[ "$expected_checksum" != "$actual_checksum" ]] && debug_job_err && return 1
done
debug_job_ok
return 0
}