Open jugOS-19 opened 2 years ago
So, after a lot of resesearching i found a solution. It works for the raspberry pi but not sure for other *nix OSes.
echo
at the end of the db_sha_local
function.sed
bit was perfectly fine)So, this is the function that now works for me
function db_sha_local
{
local FILE=$(normalize_path "$1")
local FILE_SIZE=$(file_size "$FILE")
local OFFSET=0
local SKIP=0
local SHA_CONCAT=""
which shasum > /dev/null
if [[ $? != 0 ]]; then
echo "ERR"
return
fi
while ([[ $OFFSET -lt "$FILE_SIZE" ]]); do
dd if="$FILE" of="$CHUNK_FILE" bs=4194304 skip=$SKIP count=1 2> /dev/null
if [[ "`uname -s`" = "Darwin" ]]
then
local SHA=$(shasum -a 256 "$CHUNK_FILE" | awk '{print $1}' | sed 's/\([0-9A-Fa-f]\{2\}\)/\\x\1/g')
SHA_CONCAT="${SHA_CONCAT}${SHA}"
else
local SHA=$(shasum -a 256 "$CHUNK_FILE" | awk '{print $1}' | sed 's/\([0-9A-F]\{2\}\)/\\x\1/gI')
SHA_CONCAT="${SHA_CONCAT}${SHA}"
fi
let OFFSET=$OFFSET+4194304
let SKIP=$SKIP+1
done
echo -ne "$SHA_CONCAT" | shasum -a 256 | awk '{print $1}'
}
I have been trying to use this great tool on the raspberry pi and although downloading files works fine, the hash comparison does not seem to be working.
As far as I can tell, there are 2 issues:
echo -ne $shaHex | shasum -a 256
sed 's/\([0-9A-F]\{2\}\)/\\x\1/gI'
is not doing what the API means by hex-encode? I really don't undestand what "hex-encode" means :(Thanks for this tool! Please continue with the development.