andreafabrizi / Dropbox-Uploader

Dropbox Uploader is a BASH script which can be used to upload, download, list or delete files from Dropbox, an online file sharing, synchronization and backup service.
https://www.andreafabrizi.it/2016/01/01/Dropbox-Uploader/
GNU General Public License v3.0
6.56k stars 1.08k forks source link

Hashing issue on the raspberry pi #555

Open jugOS-19 opened 2 years ago

jugOS-19 commented 2 years ago

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:

Thanks for this tool! Please continue with the development.

jugOS-19 commented 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.

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}'
}