2020-06-14 08:07:18 +00:00
|
|
|
#!/bin/sh -e
|
|
|
|
|
|
|
|
dst="/$__object_id"
|
|
|
|
|
2020-06-20 22:13:30 +00:00
|
|
|
if [ ! -f "$dst" ]
|
|
|
|
then
|
|
|
|
echo 'absent'
|
|
|
|
exit 0
|
|
|
|
fi
|
2020-06-14 08:07:18 +00:00
|
|
|
|
2020-06-20 22:13:30 +00:00
|
|
|
sum_should="$( cat "$__object/parameter/sum" )"
|
2020-06-14 08:07:18 +00:00
|
|
|
|
2020-06-20 22:13:30 +00:00
|
|
|
if [ -f "$__object/parameter/cmd-sum" ]
|
2020-06-14 08:07:18 +00:00
|
|
|
then
|
2020-06-20 22:13:30 +00:00
|
|
|
# shellcheck disable=SC2059
|
|
|
|
sum_is="$( eval "$( printf \
|
|
|
|
"$( cat "$__object/parameter/cmd-sum" )" \
|
|
|
|
"$dst" )" )"
|
|
|
|
else
|
|
|
|
os="$( "$__explorer/os" )"
|
|
|
|
|
|
|
|
if echo "$sum_should" | grep -Eq '^[0-9]+\s[0-9]+$'
|
|
|
|
then
|
|
|
|
sum_is="$( cksum "$dst" | awk '{print $1" "$2}' )"
|
|
|
|
|
|
|
|
elif echo "$sum_should" | grep -Eiq '^md5:[a-f0-9]{32}$'
|
|
|
|
then
|
|
|
|
case "$os" in
|
|
|
|
freebsd)
|
|
|
|
sum_is="md5:$( md5 -q "$dst" )"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
sum_is="md5:$( md5sum "$dst" | awk '{print $1}' )"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
elif echo "$sum_should" | grep -Eiq '^sha1:[a-f0-9]{40}$'
|
2020-06-14 08:07:18 +00:00
|
|
|
then
|
2020-06-20 22:13:30 +00:00
|
|
|
case "$os" in
|
|
|
|
freebsd)
|
|
|
|
sum_is="sha1:$( sha1 -q "$dst" )"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
sum_is="sha1:$( sha1sum "$dst" | awk '{print $1}' )"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
elif echo "$sum_should" | grep -Eiq '^sha256:[a-f0-9]{64}$'
|
|
|
|
then
|
|
|
|
case "$os" in
|
|
|
|
freebsd)
|
|
|
|
sum_is="sha256:$( sha256 -q "$dst" )"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
sum_is="sha256:$( sha256sum "$dst" | awk '{print $1}' )"
|
|
|
|
;;
|
|
|
|
esac
|
2020-06-14 08:07:18 +00:00
|
|
|
fi
|
2020-06-20 22:13:30 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "$sum_is" ]
|
|
|
|
then
|
|
|
|
echo 'no checksum from target' >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$sum_is" = "$sum_should" ]
|
|
|
|
then
|
|
|
|
echo 'present'
|
2020-06-14 08:07:18 +00:00
|
|
|
else
|
2020-06-20 22:13:30 +00:00
|
|
|
echo 'mismatch'
|
2020-06-14 08:07:18 +00:00
|
|
|
fi
|