From a9a3bbaf400e98d6b4e9cdf765728864fe14a7e2 Mon Sep 17 00:00:00 2001 From: kaotisk Date: Fri, 1 Mar 2024 05:36:17 +0200 Subject: Rename ak-pack_z_block to ak-zblock-pack --- bin/ak-articles | 2 +- bin/ak-categories | 2 +- bin/ak-cli | 2 +- bin/ak-comments | 2 +- bin/ak-files | 2 +- bin/ak-folders | 2 +- bin/ak-mixtapes | 4 +- bin/ak-news | 4 +- bin/ak-pack_z_block | 158 ---------------------------------------------------- bin/ak-profile | 2 +- bin/ak-reference | 2 +- bin/ak-repositories | 2 +- bin/ak-sm-files | 2 +- bin/ak-todos | 2 +- bin/ak-transactions | 2 +- bin/ak-zblock-pack | 158 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 16 files changed, 174 insertions(+), 174 deletions(-) delete mode 100755 bin/ak-pack_z_block create mode 100755 bin/ak-zblock-pack (limited to 'bin') diff --git a/bin/ak-articles b/bin/ak-articles index 94e2675..5eaf225 100755 --- a/bin/ak-articles +++ b/bin/ak-articles @@ -97,7 +97,7 @@ EOF echo "File $FILE doesn't exist"; exit 2 fi - ak-pack_z_block "articles/add" $(pwd)/data + ak-zblock-pack "articles/add" $(pwd)/data if [ $? == 0 ] then echo "Articles added successfully" diff --git a/bin/ak-categories b/bin/ak-categories index 47ee69e..dbcf42c 100755 --- a/bin/ak-categories +++ b/bin/ak-categories @@ -87,7 +87,7 @@ EOF echo "File $FILE doesn't exist"; exit 2 fi - ak-pack_z_block "news/add" $(pwd)/data + ak-zblock-pack "news/add" $(pwd)/data if [ $? == 0 ] then echo "News added successfully" diff --git a/bin/ak-cli b/bin/ak-cli index 3fdcf4b..f3de2f4 100755 --- a/bin/ak-cli +++ b/bin/ak-cli @@ -231,7 +231,7 @@ help_modules(){ help_zblock(){ printf ' - ak-pack_z_block + ak-zblock-pack ' printf ' ak-zblock-cache diff --git a/bin/ak-comments b/bin/ak-comments index 34b83c0..e20ab85 100755 --- a/bin/ak-comments +++ b/bin/ak-comments @@ -65,7 +65,7 @@ _ak_modules_comments_add(){ echo "File $FILE doesn't exist"; exit 2 fi - REFERENCE="$(ak-pack_z_block "comments/add" $(pwd)/data)" + REFERENCE="$(ak-zblock-pack "comments/add" $(pwd)/data)" if [ $? == 0 ] then echo "Comment added successfully" diff --git a/bin/ak-files b/bin/ak-files index 2946856..25dc69b 100755 --- a/bin/ak-files +++ b/bin/ak-files @@ -91,7 +91,7 @@ echo "Printing data..." cat $TEMPASSIN/data echo "Publishing..." - ak-pack_z_block files/add $PWD/data + ak-zblock-pack files/add $PWD/data if [ $? == 0 ] then echo "cool" diff --git a/bin/ak-folders b/bin/ak-folders index 1049895..2a28dd9 100755 --- a/bin/ak-folders +++ b/bin/ak-folders @@ -58,7 +58,7 @@ _ak_modules_folders_main(){ cat data echo "Publishing..." - ak-pack_z_block folders/add $(pwd)/data + ak-zblock-pack folders/add $(pwd)/data if [ $? == 0 ] then echo "cool" diff --git a/bin/ak-mixtapes b/bin/ak-mixtapes index 8ccabcf..04b2490 100755 --- a/bin/ak-mixtapes +++ b/bin/ak-mixtapes @@ -1,6 +1,6 @@ #!/bin/bash # The following creates a mixtape data message -# We can extend it by calling the ak-pack_z_block.sh mixtape/add data ## ORIGINAL LINE +# We can extend it by calling the ak-zblock-pack.sh mixtape/add data ## ORIGINAL LINE _ak_modules_mixtapes_usage(){ _ak_modules_mixtapes_title @@ -43,6 +43,6 @@ then MIXTAPE_FILE="$PWD/$3" _ak_modules_mixtapes_main cat $PWD/data | jq -M - ak-pack_z_block mixtape/add $PWD/data + ak-zblock-pack mixtape/add $PWD/data else _ak_modules_mixtapes_usage fi diff --git a/bin/ak-news b/bin/ak-news index 1f265de..220aafa 100755 --- a/bin/ak-news +++ b/bin/ak-news @@ -116,7 +116,7 @@ EOF echo "File $FILE doesn't exist"; exit 2 fi - ak-pack_z_block "news/add" $(pwd)/data + ak-zblock-pack "news/add" $(pwd)/data if [ $? == 0 ] then echo "News added successfully" @@ -151,7 +151,7 @@ EOF echo "File $FILE doesn't exist"; exit 2 fi - ak-pack_z_block "news/add" $(pwd)/data + ak-zblock-pack "news/add" $(pwd)/data if [ $? == 0 ] then echo "News added successfully" diff --git a/bin/ak-pack_z_block b/bin/ak-pack_z_block deleted file mode 100755 index 5105f38..0000000 --- a/bin/ak-pack_z_block +++ /dev/null @@ -1,158 +0,0 @@ -#!/bin/bash -# This file describe the structure of the ArchingKaos messages in their basis. -# -# As previously thought, we exchange one IPFS hash through whatever means we can. -# -# GPG is mentioned as a signing algorithm for encryption, decryption and signing. -# Let's say we have a file named as `example` -# -# We can extend this with calling the encoder and further send the transaction -# - -#AK_FINGERPRINT="CHANGE THIS TO YOUR DEFAULT AK_FINGERPRINT" -# We acquire the GPG fingerprint by email address -# The following example finds kaos@kaos.kaos' GPG fingerprint like this -# AK_FINGERPRINT="$(gpg2 --homedir $AK_GPGHOME --list-keys | grep kaos@kaos.kaos -1 | head -n1 | awk '{print $1}')" - -PROGRAM="$(basename $0)" -set -xe - -# Logging patch -logit(){ - ak-logthis "<$PROGRAM>" "$1" "$2" -} - -# Below, the usage information -usage(){ - echo "" - echo "Usage:" - echo "$PROGRAM " - echo "" - echo " Creates and publishes a ZBLOCK based on ACTION and DATA file." - echo "" - echo " action An action for the render to grasp" - echo " data_file A data file that according to the action is valid" - echo "" - echo "#TODO:" - echo "implement flags to change the inputs so we can manufacture" - 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')" - ak-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 - MESSAGE_HASH=$(ak-ipfs-add $MESSAGE) - - # We create a detached and armor signature of it - MESSAGE_SIGN_FILE=$MESSAGE".asc" - gpg2 --homedir $AK_GPGHOME --detach-sign --sign-with $AK_FINGERPRINT --armor --output $MESSAGE_SIGN_FILE $MESSAGE - - # We add the signature to IPFS - MESSAGE_SIGNATURE=$(ak-ipfs-add $MESSAGE_SIGN_FILE) - - # We will be using our public key also to put it in the block later - KEY="gpg.pub" - gpg2 --homedir $AK_GPGHOME --armour --output $KEY --export $AK_FINGERPRINT - GPG_PUB_KEY=$(ak-ipfs-add $KEY) - - # Acquire last block of information, to chain this one with previous posted - PREVIOUS=$(ak-ipfs-files-stat /zlatest | head -n 1) - - # We create a block of json like this: - printf '{"timestamp":"%s","action":"%s","data":"%s","detach":"%s","gpg":"%s","previous":"%s"}' $(date -u +%s) $ACTION $MESSAGE_HASH $MESSAGE_SIGNATURE $GPG_PUB_KEY $PREVIOUS > block - BLOCK="block" - BLOCK_SIG=$BLOCK".asc" - # We have a block now, so we sign it - gpg2 --homedir $AK_GPGHOME --detach-sign --sign-with $AK_FINGERPRINT --armor --output $BLOCK_SIG $BLOCK - - # We now add the signature to IPFS - BLOCK_SIGNATURE=$(ak-ipfs-add $BLOCK_SIG) - - # We also add the block! - BLOCK=$(ak-ipfs-add $BLOCK) - - # So we now do the think almost again - printf '{"block":"%s","block_signature":"%s"}' $BLOCK $BLOCK_SIGNATURE > zblock - ZBL="zblock" - # and we add it on IPFS - ZBLOCK=$(ak-ipfs-add $ZBL) - echo $ZBLOCK -} - -if [ ! -z $2 ]; -then - MESSAGE="$2" - ACTION="$1" - if [ -f "$MESSAGE" ]; then - main - else - logit "[ERROR]" "File does not exist. Aborting..." - exit 1 - fi - - # cat $PWD/zblock | jq -M - # Optional or extending with - # python send_as_ak_tx $ZBLOCK - # or for "offline" use - echo $ZBLOCK > $AK_ZLATEST - ak-ipfs-name-publish --key=zchain $ZBLOCK > /dev/null 2>&1 - if [ "$?" -ne 0 ] - then - logit "[ERROR]" "Failed publishing ZBLOCK: $ZBLOCK" - exit 1 - fi - ak-ipfs-files-ls /zarchive > /dev/null 2>&1 - if [ "$?" -ne 0 ] - then - logit "[WARNING]" "/zarchive does not exist" - ak-ipfs-files-mkdir /zarchive > /dev/null 2>&1 - if [ "$?" -ne 0 ] - then - logit "[ERROR]" "Could not create /zarchive directory. Aborting." - exit 1 - fi - fi - ak-ipfs-files-cp /zlatest /zarchive/$(date -u +%s)-$(ak-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 - ak-ipfs-files-rm /zlatest > /dev/null 2>&1 - if [ "$?" -ne 0 ] - then - logit "[ERROR]" "Could not remove previous /zlatest" - exit 1 - fi - ak-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 - ak-config publish - if [ "$?" -ne 0 ] - then - logit "[ERROR]" "Could not publish new configuration" - exit 1 - fi -else - usage - exit 0 -fi - diff --git a/bin/ak-profile b/bin/ak-profile index a70ffe4..3f72263 100755 --- a/bin/ak-profile +++ b/bin/ak-profile @@ -169,7 +169,7 @@ EOF exit 2 fi - ak-pack_z_block "profile/add" $(pwd)/data + ak-zblock-pack "profile/add" $(pwd)/data if [ "$?" -ne 0 ] then echo "error??" diff --git a/bin/ak-reference b/bin/ak-reference index 6f24e87..231af00 100755 --- a/bin/ak-reference +++ b/bin/ak-reference @@ -99,7 +99,7 @@ EOF cat data | jq -M -c > tmp cat tmp > data rm tmp - ak-pack_z_block "references/add" $(pwd)/data + ak-zblock-pack "references/add" $(pwd)/data if [ $? != 0 ] then echo "error??" diff --git a/bin/ak-repositories b/bin/ak-repositories index 132d758..0344467 100755 --- a/bin/ak-repositories +++ b/bin/ak-repositories @@ -107,7 +107,7 @@ add(){ then ak-ipfs-name-publish --key="$PROJECT.git" /ipfs/$IPFS printf '{"project":"%s.git","ipns":"%s"}' $PROJECT $try > data - ak-pack_z_block "repos/add" $PWD/data + ak-zblock-pack "repos/add" $PWD/data echo "Done" fi fi diff --git a/bin/ak-sm-files b/bin/ak-sm-files index 5d278de..7ee3d42 100755 --- a/bin/ak-sm-files +++ b/bin/ak-sm-files @@ -115,7 +115,7 @@ EOF cat data echo "Publishing..." - ak-pack_z_block sha-files/announce $(pwd)/data + ak-zblock-pack sha-files/announce $(pwd)/data if [ $? == 0 ] then echo "cool" diff --git a/bin/ak-todos b/bin/ak-todos index 2df403d..3b5813f 100755 --- a/bin/ak-todos +++ b/bin/ak-todos @@ -95,7 +95,7 @@ EOF echo "File $FILE doesn't exist"; exit 2 fi - ak-pack_z_block "todos/add" $(pwd)/data + ak-zblock-pack "todos/add" $(pwd)/data if [ $? == 0 ] then ak-logthis "Todos added successfully" diff --git a/bin/ak-transactions b/bin/ak-transactions index 221b4fd..9573147 100755 --- a/bin/ak-transactions +++ b/bin/ak-transactions @@ -45,6 +45,6 @@ then AMOUNT="$3" _ak_modules_transactions_main cat $PWD/data | jq -M - ak-pack_z_block transaction/add $PWD/data + ak-zblock-pack transaction/add $PWD/data else _ak_modules_transactions_usage fi diff --git a/bin/ak-zblock-pack b/bin/ak-zblock-pack new file mode 100755 index 0000000..5105f38 --- /dev/null +++ b/bin/ak-zblock-pack @@ -0,0 +1,158 @@ +#!/bin/bash +# This file describe the structure of the ArchingKaos messages in their basis. +# +# As previously thought, we exchange one IPFS hash through whatever means we can. +# +# GPG is mentioned as a signing algorithm for encryption, decryption and signing. +# Let's say we have a file named as `example` +# +# We can extend this with calling the encoder and further send the transaction +# + +#AK_FINGERPRINT="CHANGE THIS TO YOUR DEFAULT AK_FINGERPRINT" +# We acquire the GPG fingerprint by email address +# The following example finds kaos@kaos.kaos' GPG fingerprint like this +# AK_FINGERPRINT="$(gpg2 --homedir $AK_GPGHOME --list-keys | grep kaos@kaos.kaos -1 | head -n1 | awk '{print $1}')" + +PROGRAM="$(basename $0)" +set -xe + +# Logging patch +logit(){ + ak-logthis "<$PROGRAM>" "$1" "$2" +} + +# Below, the usage information +usage(){ + echo "" + echo "Usage:" + echo "$PROGRAM " + echo "" + echo " Creates and publishes a ZBLOCK based on ACTION and DATA file." + echo "" + echo " action An action for the render to grasp" + echo " data_file A data file that according to the action is valid" + echo "" + echo "#TODO:" + echo "implement flags to change the inputs so we can manufacture" + 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')" + ak-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 + MESSAGE_HASH=$(ak-ipfs-add $MESSAGE) + + # We create a detached and armor signature of it + MESSAGE_SIGN_FILE=$MESSAGE".asc" + gpg2 --homedir $AK_GPGHOME --detach-sign --sign-with $AK_FINGERPRINT --armor --output $MESSAGE_SIGN_FILE $MESSAGE + + # We add the signature to IPFS + MESSAGE_SIGNATURE=$(ak-ipfs-add $MESSAGE_SIGN_FILE) + + # We will be using our public key also to put it in the block later + KEY="gpg.pub" + gpg2 --homedir $AK_GPGHOME --armour --output $KEY --export $AK_FINGERPRINT + GPG_PUB_KEY=$(ak-ipfs-add $KEY) + + # Acquire last block of information, to chain this one with previous posted + PREVIOUS=$(ak-ipfs-files-stat /zlatest | head -n 1) + + # We create a block of json like this: + printf '{"timestamp":"%s","action":"%s","data":"%s","detach":"%s","gpg":"%s","previous":"%s"}' $(date -u +%s) $ACTION $MESSAGE_HASH $MESSAGE_SIGNATURE $GPG_PUB_KEY $PREVIOUS > block + BLOCK="block" + BLOCK_SIG=$BLOCK".asc" + # We have a block now, so we sign it + gpg2 --homedir $AK_GPGHOME --detach-sign --sign-with $AK_FINGERPRINT --armor --output $BLOCK_SIG $BLOCK + + # We now add the signature to IPFS + BLOCK_SIGNATURE=$(ak-ipfs-add $BLOCK_SIG) + + # We also add the block! + BLOCK=$(ak-ipfs-add $BLOCK) + + # So we now do the think almost again + printf '{"block":"%s","block_signature":"%s"}' $BLOCK $BLOCK_SIGNATURE > zblock + ZBL="zblock" + # and we add it on IPFS + ZBLOCK=$(ak-ipfs-add $ZBL) + echo $ZBLOCK +} + +if [ ! -z $2 ]; +then + MESSAGE="$2" + ACTION="$1" + if [ -f "$MESSAGE" ]; then + main + else + logit "[ERROR]" "File does not exist. Aborting..." + exit 1 + fi + + # cat $PWD/zblock | jq -M + # Optional or extending with + # python send_as_ak_tx $ZBLOCK + # or for "offline" use + echo $ZBLOCK > $AK_ZLATEST + ak-ipfs-name-publish --key=zchain $ZBLOCK > /dev/null 2>&1 + if [ "$?" -ne 0 ] + then + logit "[ERROR]" "Failed publishing ZBLOCK: $ZBLOCK" + exit 1 + fi + ak-ipfs-files-ls /zarchive > /dev/null 2>&1 + if [ "$?" -ne 0 ] + then + logit "[WARNING]" "/zarchive does not exist" + ak-ipfs-files-mkdir /zarchive > /dev/null 2>&1 + if [ "$?" -ne 0 ] + then + logit "[ERROR]" "Could not create /zarchive directory. Aborting." + exit 1 + fi + fi + ak-ipfs-files-cp /zlatest /zarchive/$(date -u +%s)-$(ak-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 + ak-ipfs-files-rm /zlatest > /dev/null 2>&1 + if [ "$?" -ne 0 ] + then + logit "[ERROR]" "Could not remove previous /zlatest" + exit 1 + fi + ak-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 + ak-config publish + if [ "$?" -ne 0 ] + then + logit "[ERROR]" "Could not publish new configuration" + exit 1 + fi +else + usage + exit 0 +fi + -- cgit v1.2.3