From cb37ba08b35f7236f3387d4a5c6463b24936bf24 Mon Sep 17 00:00:00 2001 From: kaotisk Date: Thu, 4 Jul 2024 08:17:29 +0300 Subject: Refactoring --- bin/ak-config | 47 +---------------------------------------------- lib/_ak_config | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ lib/_ak_gpg | 3 ++- lib/_ak_zblock | 2 +- lib/_ak_zchain | 5 +++-- 5 files changed, 56 insertions(+), 50 deletions(-) create mode 100755 lib/_ak_config diff --git a/bin/ak-config b/bin/ak-config index 6be3f8c..4ef851d 100755 --- a/bin/ak-config +++ b/bin/ak-config @@ -17,52 +17,7 @@ PROGRAM="$(basename $0)" descriptionString="Arching Kaos Configuration Tool" source $AK_LIBDIR/_ak_script -source $AK_LIBDIR/_ak_gpg -source $AK_LIBDIR/_ak_ipfs -source $AK_LIBDIR/_ak_node - -_ak_config_get_ipns_key(){ - _ak_ipfs_key_list_full | grep 'ak-config' | cut -d ' ' -f 1 -} - -_ak_config_show(){ - # We will be using our public key also to put it in the block later - KEY="tmp-gpg.pub" - _ak_gpg_key_self_export $KEY - GPG_PUB_KEY=$(_ak_ipfs_add $KEY) - rm $KEY - profile="$(ak-profile -l)" - - echo ' -{ - "profile":'$profile', - "genesis":"'$(cat $AK_WORKDIR/config/zgenesis)'", - "gpg":"'$GPG_PUB_KEY'", - "zchain":"'$(cat $AK_WORKDIR/config/zchain)'", - "zlatest":"'$(ak-get-zlatest)'" -}'| jq; -} - -_ak_config_publish(){ - _ak_config_show | jq -c -M > tmpfile - _ak_ipfs key list | grep ak-config 2> /dev/null 1>&2 - if [ $? -ne 0 ] - then - _ak_ipfs_key_gen ak-config - fi - _ak_ipfs_name_publish --key=ak-config /ipfs/$(_ak_ipfs_add tmpfile) - if [ $? != 0 ] - then - echo -e "\033[0;34mError on publishing\033[0;0m\nYour information:\n" - cat tmpfile - exit 1 - fi - rm tmpfile -} - -_ak_config_published(){ - _ak_ipfs_cat $(_ak_node_info_ipfs_hash) | jq -} +source $AK_LIBDIR/_ak_config if [ ! -z $1 ] && [ -n "$1" ] then diff --git a/lib/_ak_config b/lib/_ak_config new file mode 100755 index 0000000..c362178 --- /dev/null +++ b/lib/_ak_config @@ -0,0 +1,49 @@ +#!/bin/bash + +source $AK_LIBDIR/_ak_gpg +source $AK_LIBDIR/_ak_ipfs +source $AK_LIBDIR/_ak_node + +_ak_config_get_ipns_key(){ + _ak_ipfs_key_list_full | grep 'ak-config' | cut -d ' ' -f 1 +} + +_ak_config_show(){ + # We will be using our public key also to put it in the block later + KEY="tmp-gpg.pub" + _ak_gpg_key_self_export $KEY + GPG_PUB_KEY=$(_ak_ipfs_add $KEY) + rm $KEY + profile="$(ak-profile -l)" + + echo ' +{ + "profile":'$profile', + "genesis":"'$(cat $AK_WORKDIR/config/zgenesis)'", + "gpg":"'$GPG_PUB_KEY'", + "zchain":"'$(cat $AK_WORKDIR/config/zchain)'", + "zlatest":"'$(ak-get-zlatest)'" +}'| jq; +} + +_ak_config_publish(){ + _ak_config_show | jq -c -M > tmpfile + _ak_ipfs key list | grep ak-config 2> /dev/null 1>&2 + if [ $? -ne 0 ] + then + _ak_ipfs_key_gen ak-config + fi + _ak_ipfs_name_publish --key=ak-config /ipfs/$(_ak_ipfs_add tmpfile) + if [ $? != 0 ] + then + echo -e "\033[0;34mError on publishing\033[0;0m\nYour information:\n" + cat tmpfile + exit 1 + fi + rm tmpfile +} + +_ak_config_published(){ + _ak_ipfs_cat $(_ak_node_info_ipfs_hash) | jq +} + diff --git a/lib/_ak_gpg b/lib/_ak_gpg index d220a4b..80e461c 100755 --- a/lib/_ak_gpg +++ b/lib/_ak_gpg @@ -1,6 +1,7 @@ #!/bin/bash source $AK_LIBDIR/_ak_log source $AK_LIBDIR/_ak_ipfs +source $AK_LIBDIR/_ak_config _ak_gpg(){ gpg2 --homedir $AK_GPGHOME $* @@ -26,7 +27,7 @@ _ak_gpg_key_import_from_file(){ } _ak_gpg_key_self_get_fingerprint_from_config(){ - ak-config --show | jq -r '.gpg' + _ak_config_show | jq -r '.gpg' } _ak_gpg_key_self_get_fingerprint(){ diff --git a/lib/_ak_zblock b/lib/_ak_zblock index 278619f..6afacfc 100755 --- a/lib/_ak_zblock +++ b/lib/_ak_zblock @@ -551,7 +551,7 @@ _ak_zblock_pack(){ _ak_log_error "Could not copy $ZBLOCK to /zlatest" exit 1 fi - ak-config --publish + _ak_config_publish if [ $? -ne 0 ] then _ak_log_error "Could not publish new configuration" diff --git a/lib/_ak_zchain b/lib/_ak_zchain index 147f8d5..462a509 100755 --- a/lib/_ak_zchain +++ b/lib/_ak_zchain @@ -1,6 +1,7 @@ #!/bin/bash source $AK_LIBDIR/_ak_ipfs source $AK_LIBDIR/_ak_log +source $AK_LIBDIR/_ak_config _ak_zchain_reset(){ echo "Reseting ZLATEST to ZGENESIS" @@ -28,7 +29,7 @@ _ak_zchain_reset(){ _ak_ipfs_name_publish --key=zchain /ipfs/$(cat $ZLATEST) if [ $? != 0 ]; then exit 1; fi - ak-config --publish + _ak_config_publish if [ $? -ne 0 ] then _ak_log_error "Could not publish new configuration" @@ -67,7 +68,7 @@ _ak_zchain_rebase(){ _ak_ipfs_name_publish --key=zchain /ipfs/$(cat $AK_ZLATEST) if [ $? != 0 ]; then exit 1; fi - ak-config --publish + _ak_config_publish if [ $? -ne 0 ] then _ak_log_error "Could not publish new configuration" -- cgit v1.2.3