aboutsummaryrefslogtreecommitdiff
path: root/bin/pack_z_block
diff options
context:
space:
mode:
Diffstat (limited to 'bin/pack_z_block')
-rwxr-xr-xbin/pack_z_block46
1 files changed, 45 insertions, 1 deletions
diff --git a/bin/pack_z_block b/bin/pack_z_block
index 158a2cd..71aa4b7 100755
--- a/bin/pack_z_block
+++ b/bin/pack_z_block
@@ -37,7 +37,21 @@ usage(){
echo "zblocks directly from IPFS hashes refering to blocks."
}
+
main(){
+ # We check firstly if the encapsulated value of the "ipfs" key has already
+ # appeared in the zchain.
+ TO_CHECK="$(cat $MESSAGE | jq | grep ipfs | awk '{print $2}' | sed -e 's/"//g;s/,//g')"
+ enter | jq | grep ipfs | awk '{print $2}' | sed -e 's/"//g;s/,//g' | sort | uniq > tempisalreadythere
+ while IFS="" read -r p || [ -n "$p" ]
+ do
+ if [ "$p" == "$TO_CHECK" ]
+ then
+ logit "[ERROR]" "Value $TO_CHECK already mentioned on the zchain"
+ exit 1
+ fi
+ done < tempisalreadythere
+ rm tempisalreadythere
logit "[INFO]" "We are doing" $ACTION "with content" $MESSAGE
# We add it to IPFS
@@ -111,10 +125,40 @@ then
# or for "offline" use
echo $ZBLOCK > $ZLATEST
ipfs name publish --key=zchain $ZBLOCK > /dev/null 2>&1
- ipfs files mkdir /zarchive > /dev/null 2>&1
+ if [ "$?" -ne 0 ]
+ then
+ logit "[ERROR]" "Failed publishing ZBLOCK: $ZBLOCK"
+ exit 1
+ fi
+ ipfs files ls /zarchive > /dev/null 2>&1
+ if [ "$?" -ne 0 ]
+ then
+ logit "[WARNING]" "/zarchive does not exist"
+ ipfs files mkdir /zarchive > /dev/null 2>&1
+ if [ "$?" -ne 0 ]
+ then
+ logit "[ERROR]" "Could not create /zarchive directory. Aborting."
+ exit 1
+ fi
+ fi
ipfs files cp /zlatest /zarchive/$(date -u +%s)-$(ipfs files stat /zlatest | head -n 1) > /dev/null 2>&1
+ if [ "$?" -ne 0 ]
+ then
+ logit "[ERROR]" "Could not back up previous /zlatest"
+ exit 1
+ fi
ipfs files rm /zlatest > /dev/null 2>&1
+ if [ "$?" -ne 0 ]
+ then
+ logit "[ERROR]" "Could not remove previous /zlatest"
+ exit 1
+ fi
ipfs files cp /ipfs/$ZBLOCK /zlatest > /dev/null 2>&1
+ if [ "$?" -ne 0 ]
+ then
+ logit "[ERROR]" "Could not copy $ZBLOCK to /zlatest"
+ exit 1
+ fi
else
usage
exit 0