aboutsummaryrefslogtreecommitdiff
path: root/bin/ak-zblock-cache
blob: cb0d48fd7f5fcc0cee2577427779cf3df27e0314 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/bin/bash
PROGRAM="$(basename $0)"
logit(){
    ak-logthis "<$PROGRAM>" "$1" "$2"
}

if [ ! -z "$1" ]
then
    if [ -f "$AK_ZBLOCKDIR/$1" ] && [ "$(du -b $AK_ZBLOCKDIR | awk '{ print $1 }')" != "0" ]
    then
        if [ "$(sha512sum $AK_ZBLOCKDIR/$1 | awk '{ print $1 }')" == "$(ak-zblock-show $1 | sha512sum | awk '{ print $1 }')" ]
        then
            logit "[INFO]" "Cache already there and updated"
        else
            logit "[INFO]" "Updating cache"
            ak-zblock-show "$1" > $AK_ZBLOCKDIR/$1
        fi
        logit "[INFO]" "No cache found. Caching..."
        ak-zblock-show "$1" 
        if [ "$?" -ne "0" ]
        then
            logit "[ERROR]" "ak-zblock-show failed..."
            exit 1
        fi
        ak-zblock-show "$1" > $AK_ZBLOCKDIR/$1
    else
        logit "[ERROR]" "Could not find zblock $1..."
        exit 1
    fi
    exit 0
else
    printf "Usage:\n\t%s <zblock-ipfs-hash>\n" "$PROGRAM" 1>&2
    exit 1
fi