-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommonchain.sh
71 lines (65 loc) · 2.17 KB
/
commonchain.sh
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/bash -e
nm="CommonChain"
vs="r1"
commonchainversion="""
\e[1;42m $nm \e[0m\e[100m version $vs \e[0m
\e[100m Created in 10-21-2021 by Daniella Mesquita \e[0m
"""
lastblockpath=$(find -maxdepth 1 -name '*.json' | sort -t_ -nk2,2 | tail -n1)
tmp="${lastblockpath##*/}" # gives 2.json
lastblock="${tmp%.*}" # gives 2
if [ "$lastblock" -ge "2" ]
then
prevblock="$(($lastblock - 1))"
else
prevblock="Can't verify previous block because this commonchain is still at block 1. Wait until it reach block 2 or more."
fi
gitrepo="$(jq -r '.gitrepo' 0.json)"
lastblocktag="$(jq -r '.tag' $lastblock.json)"
releasetag="$(
curl --silent "https://api.github.com/repos/$gitrepo/releases/latest" \
| grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/'
)"
releasetagnov="$(
curl --silent "https://api.github.com/repos/$gitrepo/releases/latest" \
| grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/' \
| cut -c 2-
)"
export nm && export vs && export commonchainversion && export lastblockpath && export lastblock && export prevblock && export gitrepo && export releasetag && export releasetag && export lastblocktag
if [ "$1" = "" ]; then
if [ "$lastblocktag" != "$releasetag" ]; then
./check.sh
./commonchain.sh && exit
fi
if [ -f justupdated.now ]; then
rm justupdated.now
echo "This commonchain has been updated just now; from block $prevblock to $lastblock!"
echo "Its advisable to run 'commonchain validate' in order to verify this update is legit."
echo "--------------------"
fi
echo "$commonchainversion"
echo "Type 'commonchain --help' (without quotes) to see a list of available commands."
echo "--------------------"
echo "gitrepo: $gitrepo" #test
echo "Latest registered release: $lastblocktag"
echo "Latest release: $releasetag"
fi
if [ "$1" = "latest" ]; then
if [ "$2" = "" ]; then
echo "Latest block is: $lastblock"
fi
if [ "$2" = "--plain" ]; then
echo "$lastblock"
fi
fi
if [ "$1" = "previous" ]; then
if [ "$2" = "" ]; then
echo "Previous block is: $prevblock"
fi
if [ "$2" = "--plain" ]; then
echo "$prevblock"
fi
fi
if [ "$1" = "validate" ]; then
./validate.sh
fi