diff options
author | kaotisk <kaotisk@arching-kaos.org> | 2023-02-01 03:19:20 +0200 |
---|---|---|
committer | kaotisk <kaotisk@arching-kaos.org> | 2023-02-01 03:19:20 +0200 |
commit | d39b26b36a7079e288dc57611364ef146ce7f0fa (patch) | |
tree | 856bcac41f4f68042a208aaf31a145aec2d1843c /bin | |
parent | 4b5a8f019e6cb58be0d4fb28d02f7ff5ce6e0197 (diff) | |
download | arching-kaos-tools-d39b26b36a7079e288dc57611364ef146ce7f0fa.tar.gz arching-kaos-tools-d39b26b36a7079e288dc57611364ef146ce7f0fa.tar.bz2 arching-kaos-tools-d39b26b36a7079e288dc57611364ef146ce7f0fa.zip |
Exits on failures, added check so we don't produce duplicate references to the same ipfs key
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/pack_z_block | 46 |
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 |