aboutsummaryrefslogtreecommitdiff
path: root/bin/ak-zblock-cache
blob: c314d56a6970619f3253ec73265a5232df629512 (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
36
37
38
39
40
41
42
43
44
#!/bin/bash
PROGRAM="$(basename $0)"
source $AK_LIBDIR/_ak_logit

if [ ! -d "$AK_CACHEDIR/fzblocks" ]
then
    mkdir $AK_CACHEDIR/fzblocks
fi

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_CACHEDIR/fzblocks/$1
        fi
        logit "INFO" "No cache found. Caching..."
        ak-zblock-show "$1"
        if [ "$?" -ne "0" ]
        then
            logit "ERROR" "ak-zblock-show failed..."
            exit 2
        fi
        ak-zblock-show "$1" > $AK_CACHEDIR/fzblocks/$1
    else
        ak-zblock-show "$1" > $AK_CACHEDIR/fzblocks/$1
        if [ "$?" -ne "0" ]
        then
            logit "ERROR" "ak-zblock-show failed..."
            exit 2
        fi
        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