aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorkaotisk <kaotisk@arching-kaos.org>2024-07-04 18:36:54 +0300
committerkaotisk <kaotisk@arching-kaos.org>2024-07-04 18:36:54 +0300
commitc0dbfc8dc7cf7af278de1d233d87ffbe481ba704 (patch)
tree9037aef8094102626f387cec6d026793478fd53a /bin
parent2d04f1e16cd234b6ad82eff3c4cd6b09149ef4ec (diff)
downloadarching-kaos-tools-c0dbfc8dc7cf7af278de1d233d87ffbe481ba704.tar.gz
arching-kaos-tools-c0dbfc8dc7cf7af278de1d233d87ffbe481ba704.tar.bz2
arching-kaos-tools-c0dbfc8dc7cf7af278de1d233d87ffbe481ba704.zip
Refactoring + bug fixes
- Recursive sourcing was introduced and fixed - Almost finished removing old style commands 'ak-zchain-chk' in favor of the new design (eg 'ak zchain --check') - A couple of changes on how we really do concatenation of an IPFS link - Interface function for publishing to 'ak-config' key - Interface function for publishing to IPNS keys
Diffstat (limited to 'bin')
-rwxr-xr-xbin/ak-config3
-rwxr-xr-xbin/ak-zblock5
-rwxr-xr-xbin/ak-zchain3
-rwxr-xr-xbin/ak-zchain-chk149
4 files changed, 2 insertions, 158 deletions
diff --git a/bin/ak-config b/bin/ak-config
index 4ef851d..2a1f063 100755
--- a/bin/ak-config
+++ b/bin/ak-config
@@ -18,6 +18,7 @@ descriptionString="Arching Kaos Configuration Tool"
source $AK_LIBDIR/_ak_script
source $AK_LIBDIR/_ak_config
+source $AK_LIBDIR/_ak_ipfs
if [ ! -z $1 ] && [ -n "$1" ]
then
@@ -26,7 +27,7 @@ then
--show) _ak_config_show;exit;;
--publish) _ak_config_publish;exit;;
--get-published) _ak_config_published;exit;;
- --get-ipns-key) _ak_config_get_ipns_key;exit;;
+ --get-ipns-key) _ak_ipfs_get_config_ipns_key;exit;;
*) _ak_usage;exit;;
esac
else
diff --git a/bin/ak-zblock b/bin/ak-zblock
index 2b8ae42..d3d24ae 100755
--- a/bin/ak-zblock
+++ b/bin/ak-zblock
@@ -26,11 +26,6 @@ source $AK_LIBDIR/_ak_log
source $AK_LIBDIR/_ak_script
source $AK_LIBDIR/_ak_zblock
-# Your stuff here...
-example(){
- echo "Example"
-}
-
# Flags to run
if [ ! -z $1 ]; then
case $1 in
diff --git a/bin/ak-zchain b/bin/ak-zchain
index df73e7c..06a1341 100755
--- a/bin/ak-zchain
+++ b/bin/ak-zchain
@@ -49,9 +49,6 @@ descriptionString="Zchain tools"
source $AK_LIBDIR/_ak_log
source $AK_LIBDIR/_ak_script
-source $AK_LIBDIR/_ak_ipfs
-source $AK_LIBDIR/_ak_gpg
-source $AK_LIBDIR/_ak_zblock
source $AK_LIBDIR/_ak_zchain
# Flags to run
diff --git a/bin/ak-zchain-chk b/bin/ak-zchain-chk
deleted file mode 100755
index 1d9a2f7..0000000
--- a/bin/ak-zchain-chk
+++ /dev/null
@@ -1,149 +0,0 @@
-#!/bin/bash
-##
-## -h, --help Prints this help message
-##
-PROGRAM="$(basename $0)"
-source $AK_LIBDIR/_ak_log
-source $AK_LIBDIR/_ak_ipfs
-
-fix="0"
-usage(){
- echo "zchain-chk - Check and fix zchain"
- echo "---------------------------------"
- echo "Usage:"
- echo " --help, -h Print this help and exit"
- echo " --chain <ipns-link>, -n <ipns-link> Crawl specified chain"
- echo " --fix #TODO Fix your chain"
- echo ""
- echo "Note that combined flags don't work for now"
- echo "Running with no flags crawls your chain"
-}
-
-if [ ! -z "$1" ] && [ "$1" == "-h" ] || [ "$1" == "--help" ]
-then
- usage
- exit
-elif [ ! -z "$1" ] && [ "$1" == "-f" ] || [ "$1" == "--fix" ]
-then
- fix="1"
- entrance="$(cat $AK_ZLATEST)"
-elif [ ! -z "$1" ] && [ "$1" == "-n" ] || [ "$1" == "--chain" ]
-then
- entrance="$(_ak_ipns_resolve $2)"
-elif [ ! -z "$1" ]
-then
- entrance="$1"
-else
- # By default we ak-enter from the latest block
- # We can alter this by changing this value
- entrance="$(cat $AK_ZLATEST)"
-fi
-
-# We assign the IPFS CIDv0 of an empty file as this is used
-# as our GENESIS block, hence the "seed" that the tree grows
-# from.
-seed="$(cat $AK_ZGENESIS)"
-
-# We assume that we found the entrance inside a block, hence
-# ZBLOCK is labeled as previous
-zblock="$entrance"
-declare -A blocks_found
-
-# Enter temp folder
-TEMPASSIN="$(_ak_make_temp_directory)"
-cd $TEMPASSIN
-counter=0
-
-# The loop
-# We break the loop from inside the loop
-while true
-do
- if [ $counter == 0 ]
- then
- echo 'Start checking'
- fi
- counter=$(expr $counter + 1)
-
- # Check if $zblock exists as variable
- if [ ! -v $zblock ]
- then
- # Check if it is not our seed cause if it is we skip this part
- if [ "$zblock" != "$seed" ]
- then
- # Reset timestamp since it's introduced later
- timestamp=''
- # Announce to stdout which ZBLOCK is being read at the moment
- _ak_log_info "Examining $zblock"
-
- # We create files named after each ZBLOCK IPFS CID for later
- # reference. Files are empty.
- touch $AK_ZBLOCKDIR/$zblock
- _ak_log_info "Created reference"
-
- # We concatenate the zblock's contents, pipe them through filter
- # ak-json2bash and output them to tmp-file
- _ak_ipfs_cat $zblock | ak-json2bash > tmp-zblock
- _ak_log_info "ZBLOCK $zblock READ"
-
- # Supposingly you are on a safe environment and you only have
- # access to your chain, I would consider mild secure to source
- # the files into your bash.
- # File an issue/pull request if you think it can be done better!!
- source tmp-zblock
- _ak_log_info "ZBLOCK SOURCED"
-
- # Same as above applies to BLOCK and DATA subparts of each ZBLOCK
- # BLOCKS
- _ak_ipfs_cat $block | ak-json2bash > tmp-block
- source tmp-block
- _ak_log_info "BLOCK $block SOURCED"
- touch $AK_BLOCKDIR/$block
- _ak_log_info "BLOCK REFERENCED"
- module="$(echo $action | sed -e 's/\// /g' | awk '{ print $1 }')"
- _ak_log_info "DATA is $module module."
- command="$(echo $action | sed -e 's/\// /g' | awk '{ print $2 }')"
- _ak_log_info "COMMAND is $command"
- if [ ! -v $timestamp ]
- then
- echo "$timestamp : $zblock -> $block -> $previous"
- blocks_found[$counter]="$block"
- fi
- touch $AK_DATADIR/$data
-
- # Now, since we sourced the BLOCK to our terminal, we can search
- # for $previous variable. In case we don't find one, we exit with
- # code 0
- if [ -v $previous ]
- then
- _ak_log_error "Block $block has no previous zblock"
- echo "Chain with no genesis"
- if [ "$fix" == "1" ]
- then
- echo "LOL"
- else
- echo "Blocks found and need repacking..."
- for value in ${blocks_found[@]}
- do
- echo $value
- _ak_ipfs_cat $value | jq -M
- done
- fi
- exit 0
- # Otherwise, we inform of the sequence
- else
- zblock=$previous
- fi
- # Now check if it is equal to the seed
- # which apparently means we reached the seed.
- elif [ "$zblock" == "$seed" ]
- then
- echo "Chain is OK with GENESIS block = $seed"
- _ak_log_info "Counter $counter"
- exit 0
- fi
- # And finally, if nothing is there exit with error
- else
- _ak_log_error "Check not passed... No previous IPFS CID"
- exit 1
- fi
-done