From e4f18be94261b39544ef3bc50321f6aedeb45bd6 Mon Sep 17 00:00:00 2001 From: kaotisk Date: Sun, 31 Mar 2024 12:00:59 +0300 Subject: huge refactor, might breaking things --- bin/ak | 30 +++-- bin/ak-articles | 33 +++--- bin/ak-categories | 38 +++---- bin/ak-comments | 38 +++---- bin/ak-config | 37 +++---- bin/ak-data-expand | 2 +- bin/ak-enter | 60 ++++------ bin/ak-files | 26 +++-- bin/ak-find-latest-mined-sblock | 45 +++++--- bin/ak-folders | 29 +++-- bin/ak-follow | 2 +- bin/ak-following | 2 +- bin/ak-fs-add | 3 +- bin/ak-get-chain-minified | 1 - bin/ak-ipfs-daemon | 2 - bin/ak-ipfs-starter | 4 +- bin/ak-log-follow | 13 +++ bin/ak-log-grep | 21 ++++ bin/ak-log-message | 47 ++++++++ bin/ak-log-rotate | 7 ++ bin/ak-logfollow | 13 --- bin/ak-logrotate | 7 -- bin/ak-logthis | 47 -------- bin/ak-mempool | 2 +- bin/ak-mixtapes | 70 +++++++----- bin/ak-news | 78 ++++++++----- bin/ak-node-info | 31 ++++-- bin/ak-profile | 59 +++++----- bin/ak-reference | 52 ++++----- bin/ak-repositories | 3 +- bin/ak-schain-latest-cached | 2 +- bin/ak-sm-files | 5 +- bin/ak-sm-filesplitter | 2 +- bin/ak-startup | 2 +- bin/ak-stellar-get-participants | 2 +- bin/ak-tempassin | 2 +- bin/ak-todos | 63 +++++------ bin/ak-transactions | 18 +-- bin/ak-unfollow | 2 + bin/ak-zblock-announce | 14 --- bin/ak-zblock-cache | 44 -------- bin/ak-zblock-gen-html | 239 ---------------------------------------- bin/ak-zblock-manipulator | 143 ------------------------ bin/ak-zblock-pack | 156 -------------------------- bin/ak-zblock-show | 36 ------ bin/ak-zchain-chk | 5 +- bin/ak-zchain-extract-cids | 11 +- 47 files changed, 512 insertions(+), 1036 deletions(-) delete mode 100755 bin/ak-get-chain-minified create mode 100755 bin/ak-log-follow create mode 100755 bin/ak-log-grep create mode 100755 bin/ak-log-message create mode 100755 bin/ak-log-rotate delete mode 100755 bin/ak-logfollow delete mode 100755 bin/ak-logrotate delete mode 100755 bin/ak-logthis delete mode 100755 bin/ak-zblock-announce delete mode 100755 bin/ak-zblock-cache delete mode 100755 bin/ak-zblock-gen-html delete mode 100755 bin/ak-zblock-manipulator delete mode 100755 bin/ak-zblock-pack delete mode 100755 bin/ak-zblock-show (limited to 'bin') diff --git a/bin/ak b/bin/ak index d18012a..add2373 100755 --- a/bin/ak +++ b/bin/ak @@ -1,8 +1,14 @@ #!/bin/bash - -PROGRAM=$(basename $0) -source $AK_LIBDIR/_ak_logit -source $AK_LIBDIR/_ak_script_exit +## +## -h, --help Prints this help message +## +## Run with no arguments to see available commands +## +fullprogrampath="$(realpath $0)" +PROGRAM="$(basename $0)" +descriptionString="Arching Kaos CLI" +source $AK_LIBDIR/_ak_log +source $AK_LIBDIR/_ak_script if [ $# -eq 0 ] then @@ -16,18 +22,28 @@ then if [ -n "$subcmd" ] then echo $subcmd | cut -d '-' -f 2 | sort | uniq | sed -e 's/^/ak /g' - # $(echo $subcmd) $args + #$(echo $subcmd) $args fi done ) | sort | uniq exit 1 fi +if [ $# -eq 1 ] +then + case "$1" in + -h|--help) + _ak_title_description + _ak_help + exit 1 + esac +fi + subcmd="$(echo $* | sed -e 's/ /-/g')" if [ -f "$AK_BINDIR/ak-$subcmd" ] then $(echo ak-$subcmd) - exit_program $? "ak-$subcmd command finished"; + _ak_exit_program $? "ak-$subcmd command finished"; else argc=$# argv="$*" @@ -40,7 +56,7 @@ else then logit "INFO" "Running: ak-$subcmd with args: $args" $(echo ak-$subcmd) $args - exit_program $? "ak-$subcmd command finished"; + _ak_exit_program $? "ak-$subcmd command finished"; fi counter=$(($counter + 1)) done diff --git a/bin/ak-articles b/bin/ak-articles index ba45309..97a8e8d 100755 --- a/bin/ak-articles +++ b/bin/ak-articles @@ -1,12 +1,21 @@ #!/bin/bash - +## +## -h, --help Prints this help message +## index Prints an indexed table of your articles files +## import TODO +## add Creates a data file from the articles file you point to +## create Vim is going to pop up, you will write and save your +## articlesletter and it's going to be saved +## +fullprogrampath="$(realpath $0)" PROGRAM=$(basename $0) descriptionString="Articles module for Arching Kaos" -source $AK_LIBDIR/_ak_logit -source $AK_LIBDIR/_ak_script_description +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 ZARTICLESDIR="$AK_WORKDIR/articles" TEMP="/tmp/aktmp" @@ -108,7 +117,7 @@ EOF echo "File $FILE doesn't exist"; exit 2 fi - ak-zblock-pack "articles/add" $(pwd)/data + _ak_zblock_pack "articles/add" $(pwd)/data if [ $? == 0 ] then echo "Articles added successfully" @@ -117,24 +126,14 @@ EOF exit 1 fi } -_ak_modules_articles_usage(){ - echo " -h, --help Prints this help message" - echo " index Prints an indexed table of your articles files" - echo " import #TODO" - echo " add Creates a data file from the articles file you point to" - echo " create Vim is going to pop up, you will write and save your" - echo " articlesletter and it's going to be saved" - exit 0 -} -_ak_modules_articles_title if [ ! -z $1 ]; then case $1 in - -h | --help) _ak_modules_articles_usage; exit;; + -h | --help) _ak_usage; exit;; index) _ak_modules_articles_index; exit;; import) _ak_modules_articles_import $2; exit;; add) _ak_modules_articles_add $2; exit;; create) _ak_modules_articles_create; exit;; - * ) _ak_modules_articles_usage;; + * ) _ak_usage;; esac -else _ak_modules_articles_usage +else _ak_usage fi diff --git a/bin/ak-categories b/bin/ak-categories index 6f2da6c..c0e1e77 100755 --- a/bin/ak-categories +++ b/bin/ak-categories @@ -1,12 +1,25 @@ #!/bin/bash +## +## -h, --help Prints this help message" +## +## index Prints an indexed table of your news files" +## +## import #TODO" +## +## add Creates a data file from the news file you point to" +## +## create Vim is going to pop up, you will write and save your" +## newsletter and it's going to be saved" +## AK_CATEGORIES="$AK_WORKDIR/categories" PROGRAM="$(basename $0)" descriptionString="A module for adding and refering zblocks to categories" -source $AK_LIBDIR/_ak_logit -source $AK_LIBDIR/_ak_script_description +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 if [ ! -d $AK_CATEGORIES ]; then mkdir $AK_CATEGORIES @@ -41,9 +54,6 @@ _ak_modules_categories_index(){ let i+=1 done } -_ak_modules_categories_title(){ - description -} _ak_modules_categories_import(){ echo "#TODO" @@ -92,7 +102,7 @@ EOF logit "ERROR" "File $FILE doesn't exist"; exit 2 fi - ak-zblock-pack "news/add" $(pwd)/data + _ak_zblock_pack "news/add" $(pwd)/data if [ $? == 0 ] then logit "INFO" "News added successfully" @@ -102,25 +112,15 @@ EOF fi } -_ak_modules_categories_usage(){ - _ak_modules_categories_title - echo " -h, --help Prints this help message" - echo " index Prints an indexed table of your news files" - echo " import #TODO" - echo " add Creates a data file from the news file you point to" - echo " create Vim is going to pop up, you will write and save your" - echo " newsletter and it's going to be saved" - exit 0 -} if [ ! -z $1 ]; then case $1 in - -h | --help) _ak_modules_categories_usage; exit;; + -h | --help) _ak_usage; exit;; index) _ak_modules_categories_index; exit;; import) _ak_modules_categories_import $2; exit;; add) _ak_modules_categories_add $2; exit;; create) _ak_modules_categories_create; exit;; - * ) _ak_modules_categories_usage;; + * ) _ak_usage;; esac -else _ak_modules_categories_usage +else _ak_usage fi diff --git a/bin/ak-comments b/bin/ak-comments index 220b1a7..6193e2f 100755 --- a/bin/ak-comments +++ b/bin/ak-comments @@ -1,11 +1,23 @@ #!/bin/bash +## +## -h, --help Prints this help message" +## +## index Prints an indexed table of your comments files" +## +## add Creates a data file from the comments file you point to" +## +## create Vim is going to pop up, you will write and save your" +## commentsletter and it's going to be saved" +## +fullprogrampath="$(realpath $0)" PROGRAM="$(basename $0)" descriptionString="Comments module for Arching Kaos" -source $AK_LIBDIR/_ak_logit -source $AK_LIBDIR/_ak_script_description +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 ZCOMMENTSDIR="$AK_WORKDIR/comments" TEMP="/tmp/aktmp" @@ -54,9 +66,7 @@ _ak_modules_comments_index(){ let i+=1 done } -_ak_modules_comments_title(){ - echo comments -} + _ak_modules_comments_add(){ TEMP="$(ak-tempassin)" cd $TEMP @@ -73,7 +83,7 @@ _ak_modules_comments_add(){ echo "File $FILE doesn't exist"; exit 2 fi - REFERENCE="$(ak-zblock-pack "comments/add" $(pwd)/data)" + REFERENCE="$(_ak_zblock_pack "comments/add" $(pwd)/data)" if [ $? == 0 ] then echo "Comment added successfully" @@ -82,24 +92,14 @@ _ak_modules_comments_add(){ exit 1 fi } -_ak_modules_comments_usage(){ - _ak_modules_comments_title - echo "" - echo "-h, --help Prints this help message" - echo "index Prints an indexed table of your comments files" - echo "add Creates a data file from the comments file you point to" - echo "create Vim is going to pop up, you will write and save your" - echo " commentsletter and it's going to be saved" - exit 0 -} if [ ! -z $1 ]; then case $1 in - -h | --help) _ak_modules_comments_usage; exit;; + -h | --help) _ak_usage; exit;; index) _ak_modules_comments_index; exit;; add) _ak_modules_comments_add $2 $3; exit;; create) _ak_modules_comments_create $2; exit;; - * ) _ak_modules_comments_usage;; + * ) _ak_usage;; esac -else _ak_modules_comments_usage +else _ak_usage fi diff --git a/bin/ak-config b/bin/ak-config index 1fe4d8d..cc2c8c5 100755 --- a/bin/ak-config +++ b/bin/ak-config @@ -1,27 +1,22 @@ #!/bin/bash +## +## Usage: ak-config [ -h | --help | show | publish | get-published ] +## +## -h, --help Show this help screen +## +## show Show current configuration (from FileSystem) +## +## publish Publish current configuration +## +## get-published Get published ak-config (from IPFS) +## +fullprogrampath="$(realpath $0)" PROGRAM="$(basename $0)" descriptionString="Arching Kaos Configuration Tool" -source $AK_LIBDIR/_ak_script_description +source $AK_LIBDIR/_ak_script source $AK_LIBDIR/_ak_ipfs -_ak_config_title(){ - description -} - -_ak_config_usage(){ - _ak_config_title - echo "" - echo "Usage: $PROGRAM [ -h | --help | show | publish | get-published ]" - echo "" - echo " -h, --help Show this help screen" - echo " show Show current configuration (from FileSystem)" - echo " publish Publish current configuration" - echo " get-published Get published ak-config (from IPFS)" - echo "" - exit 0 -} - _ak_config_show(){ # We will be using our public key also to put it in the block later KEY="tmp-gpg.pub" @@ -62,12 +57,12 @@ _ak_config_published(){ if [ ! -z $1 ]; then case $1 in - --help| -h) _ak_config_usage;exit;; + --help| -h) _ak_usage;exit;; show) _ak_config_show;exit;; publish) _ak_config_publish;exit;; get-published) _ak_config_published;exit;; - *) _ak_config_usage;exit;; + *) _ak_usage;exit;; esac else - _ak_config_usage + _ak_usage fi diff --git a/bin/ak-data-expand b/bin/ak-data-expand index e5e699f..a19ca65 100755 --- a/bin/ak-data-expand +++ b/bin/ak-data-expand @@ -1,6 +1,6 @@ #!/bin/bash PROGRAM="$(basename $0)" -source $AK_LIBDIR/_ak_logit +source $AK_LIBDIR/_ak_log source $AK_LIBDIR/_ak_ipfs source $AK_LIBDIR/_ak_gpg diff --git a/bin/ak-enter b/bin/ak-enter index 3828e04..7dd7ad7 100755 --- a/bin/ak-enter +++ b/bin/ak-enter @@ -13,49 +13,29 @@ # ak-enter -N # ak-enter -h # ak-enter +## ak-enter [-N | --no-verify] [-l | --limit ] [zblock] +## ak-enter [-N | --no-verify] [-l | --limit ] -n +## Usage: +## --help, -h Print this help and exit +## --chain , -n Crawl specified chain +## --no-verify, -N Don't verify signatures +## Specify IPFS CID for entrance +## +## Note that combined flags don't work for now +## Running with no flags crawls your chain based on AK_ZLATEST environment +## variable # # Returns a JSON array representing the chain retrieved. # Logs messages to $LOGSFILE. +fullprogrampath="$(realpath $0)" PROGRAM="$(basename $0)" descriptionString="Crawl an arching kaos chain" -source $AK_LIBDIR/_ak_logit -source $AK_LIBDIR/_ak_script_description +source $AK_LIBDIR/_ak_log +source $AK_LIBDIR/_ak_script source $AK_LIBDIR/_ak_ipfs source $AK_LIBDIR/_ak_gpg -_ak_enter_title(){ - description -} - -_ak_enter_usage(){ - _ak_enter_title - echo "$PROGRAM [-N | --no-verify] [-l | --limit ] [zblock]" - echo "$PROGRAM [-N | --no-verify] [-l | --limit ] -n " - echo "Usage:" - echo " --help, -h Print this help and exit" - echo " --chain , -n Crawl specified chain" - echo " --no-verify, -N Don't verify signatures" - echo " Specify IPFS CID for entrance" - echo "" - echo "Note that combined flags don't work for now" - echo "Running with no flags crawls your chain based on AK_ZLATEST environment variable" - exit 2 -} - -isIPFSv0 () { - if [ -z $1 ] || [ "$1" != "" ] - then - echo $1 | grep -e 'Qm.\{44\}' > /dev/null - if [ "$?" -ne 0 ] - then - logit "ERROR" "Argument provided was not an IPFS CIDv0 string" - exit 1 - fi - else - exit 1 - fi -} # Start of tests #entrance="QmW5WVXCJfhb4peHG6cbEdamC24vZzMX2Vz386vpENh38U" #entrance="QmNjQq7GkuXGF8kFT1z2Mv3i4JhY7sBXVUmHDiR1zkQjoE" @@ -70,7 +50,7 @@ fromIpns=0 while [ "$#" ]; do case "$1" in -h | --help) - _ak_enter_usage + _ak_usage ;; -l | --limit) limit=$2 @@ -97,7 +77,7 @@ while [ "$#" ]; do test="$1" if [ ! -z "$test" ] && [ "$fromIpns" == "0" ] then - isIPFSv0 "$test" + _ak_ipfs_cid_v0_check "$test" entrance="$test" elif [ -z "$entrance" ] && [ "$fromIpns" == "1" ] then @@ -141,7 +121,7 @@ do # Announce to logs which ZBLOCK is being read at the moment logit "INFO" "Examining $zblock" - isIPFSv0 "$zblock" + _ak_ipfs_cid_v0_check "$zblock" # We check if any $zblock at all _ak_ipfs_cat $zblock | jq -c -M > $AK_ZBLOCKDIR/$zblock @@ -174,7 +154,7 @@ do logit "ERROR" "ZBLOCK $zblock has no block" exit 1 fi - isIPFSv0 "$block" + _ak_ipfs_cid_v0_check "$block" logit "INFO" "ZBLOCK $zblock has block" block_signature="$(cat $AK_ZBLOCKDIR/$zblock | jq -M -r .block_signature)" @@ -183,7 +163,7 @@ do logit "ERROR" "ZBLOCK $zblock doesn't contain a block_signature" exit 1 fi - isIPFSv0 "$block_signature" + _ak_ipfs_cid_v0_check "$block_signature" logit "INFO" "ZBLOCK $zblock contains a block_signature" # Same as above applies to BLOCK and DATA subparts of each ZBLOCK @@ -271,7 +251,7 @@ do fi data="$(cat $AK_BLOCKDIR/$block | jq -M -r .data)" - isIPFSv0 "$data" + _ak_ipfs_cid_v0_check "$data" ak-data-expand $data $gpg if [ "$?" -ne 0 ] then diff --git a/bin/ak-files b/bin/ak-files index 7cdedcd..73c8219 100755 --- a/bin/ak-files +++ b/bin/ak-files @@ -1,11 +1,19 @@ #!/bin/bash -# The following creates a mixtape data message +## +## The following creates a files data message +## +## -h, --help Prints this help message +## +fullprogrampath="$(realpath $0)" +PROGRAM=$(basename $0) +descriptionString="Module for adding files" ZFILESDIR="$AK_WORKDIR/files" TEMP="/tmp/aktmp" -PROGRAM="$(basename $0)" -source $AK_LIBDIR/_ak_logit +source $AK_LIBDIR/_ak_script +source $AK_LIBDIR/_ak_log source $AK_LIBDIR/_ak_ipfs source $AK_LIBDIR/_ak_gpg +source $AK_LIBDIR/_ak_zblock if [ ! -d $ZFILESDIR ]; then mkdir $ZFILESDIR @@ -22,10 +30,6 @@ else logit "INFO" "$ZFILESDIR found!" fi -_ak_modules_files_usage(){ - echo "$PROGRAM - file" -} - _ak_modules_files_add(){ CRP="$(pwd)" FILENAME="$1" @@ -92,7 +96,7 @@ echo "Printing data..." cat $TEMPASSIN/data echo "Publishing..." - ak-zblock-pack files/add $PWD/data + _ak_zblock_pack files/add $PWD/data if [ $? == 0 ] then echo "cool" @@ -104,9 +108,9 @@ echo "Publishing..." if [ ! -z $1 ]; then case $1 in - -h | --help) _ak_modules_files_usage; exit;; + -h | --help) _ak_usage; exit;; add) _ak_modules_files_add $2; exit;; - *) _ak_modules_files_usage; exit;; + *) _ak_usage; exit;; esac -else _ak_modules_files_usage +else _ak_usage fi diff --git a/bin/ak-find-latest-mined-sblock b/bin/ak-find-latest-mined-sblock index ce147d4..8ef104c 100755 --- a/bin/ak-find-latest-mined-sblock +++ b/bin/ak-find-latest-mined-sblock @@ -1,9 +1,18 @@ #!/bin/bash -MINED_BLOCKS_DIR="/home/$USER/.arching-kaos/mined_blocks" -cd $MINED_BLOCKS_DIR +cd $AK_MINEDBLOCKSDIR PROGRAM="$(basename $0)" declare -A counters -source $AK_LIBDIR/_ak_logit +source $AK_LIBDIR/_ak_log +source $AK_LIBDIR/_ak_ipfs + +if [ ! -z $1 ] && [ -n "$1" ] +then + if [ "$1" == "-h" ] || [ "$1" == "--help" ] + then + echo "$PROGRAM - Finds longest schain from the $AK_MINEDBLOCKSDIR dir">&2 + exit 2 + fi +fi further(){ # logit "INFO" "Diving into $1" @@ -41,31 +50,33 @@ lookfor(){ fi } -ls -1 > tmplistblock +templistblock="$(mktemp)" +find . -type f | sed 's/^\.\/000/000/g' | grep '^000' | sort > $templistblock while IFS="" read -r p || [ -n "$p" ] do # if [ ! "$p" = "" ] && [ ! "$p" = "tmplistblock" ] if [ "$(echo $p | tr -d '\n' | wc -c)" = 128 ] then - logit "INFO" "Investigating $p..." - export CHAIN_PARENT="$p" + filename="$(basename $p)" + logit "INFO" "Investigating $filename..." + export CHAIN_PARENT="$filename" counters[$CHAIN_PARENT]=1 - lookfor "$p" + lookfor "$filename" else - logit "WARNING" "Nothing to do with $p" + logit "WARNING" "Nothing to do with $filename" fi -done < tmplistblock -rm tmplistblock +done < $templistblock +rm $templistblock max=0 max_holder=0 for value in "${!counters[@]}" do -# echo "${value} : ${counters[${value}]}" - if [ ${counters[${value}]} -gt $max ] - then - max="${counters[${value}]}" - max_holder="${value}" - logit "INFO" "New MAX $max on $max_holder" - fi + # echo "${value} : ${counters[${value}]}" + if [ ${counters[${value}]} -gt $max ] + then + max="${counters[${value}]}" + max_holder="${value}" + logit "INFO" "New MAX $max on $max_holder" + fi done echo '{"latest_block":"'$max_holder'"}' diff --git a/bin/ak-folders b/bin/ak-folders index 2651571..5aa82c7 100755 --- a/bin/ak-folders +++ b/bin/ak-folders @@ -1,11 +1,22 @@ #!/bin/bash -# The following creates a mixtape data message +## The following creates a folder data message +## +## +## -h, --help Prints this help message +## +## +## add Try ak-folders add +## +fullprogrampath="$(realpath $0)" PROGRAM="$(basename $0)" +descriptionString="Module for adding folders" ZFOLDERSDIR="$AK_WORKDIR/folders" TEMP="/tmp/aktmp" -source $AK_LIBDIR/_ak_logit +source $AK_LIBDIR/_ak_log +source $AK_LIBDIR/_ak_script source $AK_LIBDIR/_ak_ipfs +source $AK_LIBDIR/_ak_zblock if [ ! -d $ZFOLDERSDIR ]; then mkdir $ZFOLDERSDIR @@ -17,12 +28,6 @@ fi TEMPASSIN="$(ak-tempassin)" cd $TEMPASSIN -_ak_modules_folders_usage(){ - _ak_modules_folders_title - echo "" - echo " -h, --help Show this message" - echo " add Try ak-folders add " -} _ak_modules_folders_add(){ CRP="$(pwd)" @@ -60,7 +65,7 @@ _ak_modules_folders_main(){ cat data echo "Publishing..." - ak-zblock-pack folders/add $(pwd)/data + _ak_zblock_pack folders/add $(pwd)/data if [ $? == 0 ] then echo "cool" @@ -76,9 +81,9 @@ _ak_modules_folders_title(){ if [ ! -z $1 ]; then case $1 in - -h | --help) _ak_modules_folders_usage; exit;; + -h | --help) _ak_usage; exit;; add) _ak_modules_folders_add $2; exit;; - *) _ak_modules_folders_usage; exit;; + *) _ak_usage; exit;; esac -else _ak_modules_folders_usage +else _ak_usage fi diff --git a/bin/ak-follow b/bin/ak-follow index dea706f..fd32d3a 100755 --- a/bin/ak-follow +++ b/bin/ak-follow @@ -1,7 +1,7 @@ #!/bin/bash FOLLOWING="$HOME/.arching-kaos/following" PROGRAM="$(basename $0)" -source $AK_LIBDIR/_ak_logit +source $AK_LIBDIR/_ak_log source $AK_LIBDIR/_ak_ipfs if [ ! -z $1 ] diff --git a/bin/ak-following b/bin/ak-following index 440a2c0..0446ed8 100755 --- a/bin/ak-following +++ b/bin/ak-following @@ -1,6 +1,6 @@ #!/bin/bash PROGRAM="$(basename $0)" -source $AK_LIBDIR/_ak_logit +source $AK_LIBDIR/_ak_log FOLLOWING="$HOME/.arching-kaos/following" if [ -f $FOLLOWING ] diff --git a/bin/ak-fs-add b/bin/ak-fs-add index b422d25..d00367d 100755 --- a/bin/ak-fs-add +++ b/bin/ak-fs-add @@ -1,4 +1,5 @@ #!/bin/bash +#set -x # # The concept is bit more complicated now # @@ -47,7 +48,7 @@ TECHDIR="$TEMPORARYDIR/chks" CURRENTDIR="$(pwd)" # Our snippet for logging debug info -source $AK_LIBDIR/_ak_logit +source $AK_LIBDIR/_ak_log # Checking directories and create them if necessary rm -rf $TEMPORARYDIR diff --git a/bin/ak-get-chain-minified b/bin/ak-get-chain-minified deleted file mode 100755 index d8c3fff..0000000 --- a/bin/ak-get-chain-minified +++ /dev/null @@ -1 +0,0 @@ -ak-enter | jq --compact-output diff --git a/bin/ak-ipfs-daemon b/bin/ak-ipfs-daemon index ad0565d..b152df8 100755 --- a/bin/ak-ipfs-daemon +++ b/bin/ak-ipfs-daemon @@ -1,7 +1,5 @@ #!/bin/bash - PROGRAM="$(basename $0)" - source $AK_LIBDIR/_ak_ipfs _ak_ipfs daemon diff --git a/bin/ak-ipfs-starter b/bin/ak-ipfs-starter index 3685736..ae483f8 100755 --- a/bin/ak-ipfs-starter +++ b/bin/ak-ipfs-starter @@ -1,10 +1,10 @@ #!/bin/bash PROGRAM="$(basename $0)" -source $AK_LIBDIR/_ak_logit +source $AK_LIBDIR/_ak_log screen -dmS akipfsd ak-ipfs-daemon -if [ "$?" != "0" ] +if [ $? -ne 0 ] then logit "ERROR" "Failed to start IPFS daemon" exit 1 diff --git a/bin/ak-log-follow b/bin/ak-log-follow new file mode 100755 index 0000000..33e5587 --- /dev/null +++ b/bin/ak-log-follow @@ -0,0 +1,13 @@ +#!/bin/bash +tail -f $AK_LOGSFILE | while read -r p || [ -n "$p" ] +do + timestamp="$(echo "$p" | awk '{print $1}')" + program="$(echo "$p" | awk '{print $2}')" + messagetype="$(echo "$p" | awk '{print $3}')" + message="$(echo "$p" | cut -d ' ' -f4-)" + printf '%s \033[1;32m%s\033[0;00m \033[1;31m%s\033[0;00m %s\n' \ + "$(date --date=@$timestamp +%Y%m%d_%H%M%S)" \ + "$program" \ + "$messagetype" \ + "$message" +done diff --git a/bin/ak-log-grep b/bin/ak-log-grep new file mode 100755 index 0000000..685cd0e --- /dev/null +++ b/bin/ak-log-grep @@ -0,0 +1,21 @@ +#!/bin/bash +PROGRAM="$(basename $0)" +descriptionString="Shows a menu to grep logfile for selected script" +source $AK_LIBDIR/_ak_script_description +if [ ! -z $1 ] && [ -n "$1" ] +then + if [ "$1" == "-h" ] || [ "$1" == "--help" ] + then + description + echo "Launch with no arguments and select from the menu that will appear" + exit 1 + fi +fi + +echo "The following scripts have entries in the log file." +echo "Select one of those by entering the number of it below and hit enter:" +select x in $(cat $AK_LOGSFILE | cut -d ' ' -f 2 | sort | uniq) +do + grep $x $AK_LOGSFILE + break +done diff --git a/bin/ak-log-message b/bin/ak-log-message new file mode 100755 index 0000000..b225313 --- /dev/null +++ b/bin/ak-log-message @@ -0,0 +1,47 @@ +#!/bin/bash +PROGRAM="$(basename $0)" +TS="$(date -u +%s)" +if [ ! -z $1 ] && [ -n "$1" ] +then + if [ "$1" == "-h" ] || [ "$1" == "--help" ] + then + echo "$PROGRAM - Log events" + echo "-h, --help Prints this message" + echo " Logs this message" + exit 0 + fi + if [ ! -z "$2" ] && [ -n "$2" ] + then + if [ ! -z "$3" ] && [ -n "$3" ] + then + echo "$TS" "<$1>" "[$2]" "$3" >> $AK_LOGSFILE + if [ "$AK_DEBUG" == "yes" ] + then + echo "$TS" "<$1>" "[$2]" "$3" >&2 + fi + exit 0 + else + echo "$TS" "<$1>" "[ERROR]" "No message" >> $AK_LOGSFILE + if [ "$AK_DEBUG" == "yes" ] + then + echo "$TS" "<$1>" "[ERROR]" "No message" >&2 + fi + exit 1 + fi + else + echo "$TS" "<$1>" "[ERROR]" "No type and message" >> $AK_LOGSFILE + if [ "$AK_DEBUG" == "yes" ] + then + echo "$TS" "<$1>" "[ERROR]" "No type and message" >&2 + fi + exit 1 + fi +else + echo "$TS" "<$(basename $0)>" "[ERROR]" "No arguments given" >> $AK_LOGSFILE + if [ "$AK_DEBUG" == "yes" ] + then + echo "$TS" "<$(basename $0)>" "[ERROR]" "No arguments given" >&2 + fi + exit 1 +fi + diff --git a/bin/ak-log-rotate b/bin/ak-log-rotate new file mode 100755 index 0000000..7bfee72 --- /dev/null +++ b/bin/ak-log-rotate @@ -0,0 +1,7 @@ +#!/bin/bash + +tar cvfz $AK_ARCHIVESDIR/logs_$(date -u +%s).tar.gz $AK_WORKDIR/akd.log $AK_WORKDIR/akd.err $AK_WORKDIR/logs + +cat /dev/null > $AK_WORKDIR/akd.log +cat /dev/null > $AK_WORKDIR/akd.err +cat /dev/null > $AK_WORKDIR/logs diff --git a/bin/ak-logfollow b/bin/ak-logfollow deleted file mode 100755 index 33e5587..0000000 --- a/bin/ak-logfollow +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash -tail -f $AK_LOGSFILE | while read -r p || [ -n "$p" ] -do - timestamp="$(echo "$p" | awk '{print $1}')" - program="$(echo "$p" | awk '{print $2}')" - messagetype="$(echo "$p" | awk '{print $3}')" - message="$(echo "$p" | cut -d ' ' -f4-)" - printf '%s \033[1;32m%s\033[0;00m \033[1;31m%s\033[0;00m %s\n' \ - "$(date --date=@$timestamp +%Y%m%d_%H%M%S)" \ - "$program" \ - "$messagetype" \ - "$message" -done diff --git a/bin/ak-logrotate b/bin/ak-logrotate deleted file mode 100755 index 7bfee72..0000000 --- a/bin/ak-logrotate +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash - -tar cvfz $AK_ARCHIVESDIR/logs_$(date -u +%s).tar.gz $AK_WORKDIR/akd.log $AK_WORKDIR/akd.err $AK_WORKDIR/logs - -cat /dev/null > $AK_WORKDIR/akd.log -cat /dev/null > $AK_WORKDIR/akd.err -cat /dev/null > $AK_WORKDIR/logs diff --git a/bin/ak-logthis b/bin/ak-logthis deleted file mode 100755 index b225313..0000000 --- a/bin/ak-logthis +++ /dev/null @@ -1,47 +0,0 @@ -#!/bin/bash -PROGRAM="$(basename $0)" -TS="$(date -u +%s)" -if [ ! -z $1 ] && [ -n "$1" ] -then - if [ "$1" == "-h" ] || [ "$1" == "--help" ] - then - echo "$PROGRAM - Log events" - echo "-h, --help Prints this message" - echo " Logs this message" - exit 0 - fi - if [ ! -z "$2" ] && [ -n "$2" ] - then - if [ ! -z "$3" ] && [ -n "$3" ] - then - echo "$TS" "<$1>" "[$2]" "$3" >> $AK_LOGSFILE - if [ "$AK_DEBUG" == "yes" ] - then - echo "$TS" "<$1>" "[$2]" "$3" >&2 - fi - exit 0 - else - echo "$TS" "<$1>" "[ERROR]" "No message" >> $AK_LOGSFILE - if [ "$AK_DEBUG" == "yes" ] - then - echo "$TS" "<$1>" "[ERROR]" "No message" >&2 - fi - exit 1 - fi - else - echo "$TS" "<$1>" "[ERROR]" "No type and message" >> $AK_LOGSFILE - if [ "$AK_DEBUG" == "yes" ] - then - echo "$TS" "<$1>" "[ERROR]" "No type and message" >&2 - fi - exit 1 - fi -else - echo "$TS" "<$(basename $0)>" "[ERROR]" "No arguments given" >> $AK_LOGSFILE - if [ "$AK_DEBUG" == "yes" ] - then - echo "$TS" "<$(basename $0)>" "[ERROR]" "No arguments given" >&2 - fi - exit 1 -fi - diff --git a/bin/ak-mempool b/bin/ak-mempool index 51f59a7..a4e11c9 100755 --- a/bin/ak-mempool +++ b/bin/ak-mempool @@ -5,7 +5,7 @@ # They also are a part of our swarm. # So should we ask for our peers? -source $AK_LIBDIR/_ak_logit +source $AK_LIBDIR/_ak_log source $AK_LIBDIR/_ak_ipfs _ak_ipfs_swarm_peers > tmp_peers diff --git a/bin/ak-mixtapes b/bin/ak-mixtapes index 6b70bf5..712bb54 100755 --- a/bin/ak-mixtapes +++ b/bin/ak-mixtapes @@ -1,21 +1,24 @@ #!/bin/bash -# The following creates a mixtape data message -# We can extend it by calling the ak-zblock-pack.sh mixtape/add data ## ORIGINAL LINE +## +## The following creates a mixtape data message +## +## Usage: +## +## -a <file> Adds a file with tags artist and title +## +## -h , --help +## +## -s , --specs +## +# We can extend it by calling the _ak_zblock_pack.sh mixtape/add data ## ORIGINAL LINE +fullprogrampath="$(realpath $0)" PROGRAM="$(basename $0)" descriptionString="AK mixtape block creator" -source $AK_LIBDIR/_ak_logit -source $AK_LIBDIR/_ak_script_description +source $AK_LIBDIR/_ak_log +source $AK_LIBDIR/_ak_script source $AK_LIBDIR/_ak_ipfs source $AK_LIBDIR/_ak_gpg - -_ak_modules_mixtapes_usage(){ - _ak_modules_mixtapes_title - echo "Usage: $0 - artist title file" -} - -_ak_modules_mixtapes_title(){ - description -} +source $AK_LIBDIR/_ak_zblock _ak_modules_mixtapes_specs(){ datetime_mask=$(printf '^[0-9]\{8\}_[0-9]\{6\}$' | xxd -p) @@ -31,6 +34,20 @@ _ak_modules_mixtapes_specs(){ }' | jq } +_ak_modules_mixtapes_add(){ + if [ ! -z $3 ]; + then + echo $1 + PWD="$(pwd)" + MIXTAPE_ARTIST="$1" + MIXTAPE_TITLE="$2" + MIXTAPE_FILE="$PWD/$3" + _ak_modules_mixtapes_main $1 + cat $PWD/data | jq -M + _ak_zblock_pack mixtape/add $PWD/data + fi +} + _ak_modules_mixtapes_main(){ echo $MIXTAPE_FILE "by" $MIXTAPE_ARTIST "named as" $MIXTAPE_TITLE @@ -53,18 +70,17 @@ EOF } -if [ ! -z $3 ]; -then - PWD="$(pwd)" - MIXTAPE_ARTIST="$1" - MIXTAPE_TITLE="$2" - MIXTAPE_FILE="$PWD/$3" - _ak_modules_mixtapes_main - cat $PWD/data | jq -M - ak-zblock-pack mixtape/add $PWD/data -elif [ "$1" == "specs" ] -then - _ak_modules_mixtapes_specs - exit 0 -else _ak_modules_mixtapes_usage +if [ ! -z $1 ]; then + case $1 in + -h | --help) _ak_usage; exit;; + -l | --local-index) _ak_modules_mixtapes_index; exit;; + -i | --import) _ak_modules_mixtapes_import $2; exit;; + -a | --add) _ak_modules_mixtapes_add_from_file $2 $3 $4; exit;; + -c | --create) _ak_modules_mixtapes_create; exit;; + -r | --read) _ak_modules_mixtapes_read $2; exit;; + -s | --specs) _ak_modules_mixtapes_specs $2; exit;; + -x | --html) _ak_modules_mixtapes_html $2; exit;; + * ) _ak_usage;; + esac +else _ak_usage fi diff --git a/bin/ak-news b/bin/ak-news index 3f8b94a..875b888 100755 --- a/bin/ak-news +++ b/bin/ak-news @@ -1,14 +1,37 @@ #!/bin/bash +## +## -h, --help Prints this help message +## +## -l, --local-index Prints an indexed table of your news files +## +## -i, --import <file> TODO +## +## -a, --add <file> Creates a data file from the news file you +## point to +## +## -r, --read <zblock> Reads a zblock as a news data +## +## -c, --create Vim is going to pop up, you will write and +## save your newsletter and it's going to bei +## saved +## +## -s, --specs Print specs of data block +## +## -x, --html <zblock> Returns an appropriate html element from a +## NEWS zblock +## +fullprogrampath="$(realpath $0)" PROGRAM=$(basename $0) descriptionString="Module to read, create and add zblocks" ZNEWSDIR="$AK_WORKDIR/news" TEMP="/tmp/aktmp" -source $AK_LIBDIR/_ak_logit -source $AK_LIBDIR/_ak_script_description +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 if [ ! -d $ZNEWSDIR ]; then mkdir $ZNEWSDIR @@ -63,10 +86,6 @@ _ak_modules_news_index(){ rm temp } -_ak_modules_news_title(){ - description -} - _ak_modules_news_import(){ echo "#TODO" if [ ! -z $1 ] @@ -120,7 +139,7 @@ EOF logit "ERROR" "File $FILE doesn't exist"; exit 2 fi - ak-zblock-pack "news/add" $(pwd)/data + _ak_zblock_pack "news/add" $(pwd)/data if [ $? == 0 ] then logit "INFO" "News added successfully" @@ -156,7 +175,7 @@ EOF logit "ERROR" "File $1 doesn't exist"; exit 2 fi - ak-zblock-pack "news/add" $(pwd)/data + _ak_zblock_pack "news/add" $(pwd)/data if [ $? == 0 ] then logit "INFO" "News added successfully" @@ -166,20 +185,6 @@ EOF fi } -_ak_modules_news_usage(){ - _ak_modules_news_title - echo " -h, --help Prints this help message" - echo " -l, --local-index Prints an indexed table of your news files" - echo " -i, --import <file> #TODO" - echo " -a, --add <file> Creates a data file from the news file you point to" - echo " -r, --read <zblock> Reads a zblock as a news data" - echo " -c, --create Vim is going to pop up, you will write and save your" - echo " newsletter and it's going to be saved" - echo " -s, --specs Print specs of data block" - echo " -x, --html <zblock> Returns an appropriate html element from a NEWS zblock" - exit 0 -} - _ak_modules_news_read(){ ak-enter -l 1 $1 > temp if [ $? -ne 0 ] @@ -232,7 +237,7 @@ _ak_modules_news_html(){ echo " </tr>" echo " <tr>" echo " <td>" - echo " <pre> ✍ī¸ Title</pre>" + echo " <pre>✍ī¸ Title</pre>" echo " </td>" echo " <td>" echo " <pre>$ztitle</pre>" @@ -251,7 +256,26 @@ _ak_modules_news_html(){ echo " <pre>📄 Content</pre>" echo " </td>" echo " <td>" - echo " <pre>$(_ak_ipfs_cat $linkToText)</pre>" + echo " <style>" + echo " .body * {" + echo " border: 0;" + echo " margin: 0;" + echo " padding: 0;" + echo " }" + echo " .body a {" + echo " color: #042746;" + echo " background-color: lightyellow;" + echo " border: 0;" + echo " margin: 0;" + echo " padding: 0;" + echo " }" + echo " .body p {" + echo " border: 0;" + echo " margin: 0;" + echo " padding: 1vh 1vw;" + echo " }" + echo " </style>" + _ak_ipfs_cat $linkToText | txt2tags -t html -H --infile=- --outfile=- echo " </td>" echo " </tr>" echo '</table>' @@ -278,7 +302,7 @@ _ak_modules_news_specs(){ if [ ! -z $1 ]; then case $1 in - -h | --help) _ak_modules_news_usage; exit;; + -h | --help) _ak_usage; exit;; -l | --local-index) _ak_modules_news_index; exit;; -i | --import) _ak_modules_news_import $2; exit;; -a | --add) _ak_modules_news_add_from_file $2; exit;; @@ -286,7 +310,7 @@ if [ ! -z $1 ]; then -r | --read) _ak_modules_news_read $2; exit;; -s | --specs) _ak_modules_news_specs $2; exit;; -x | --html) _ak_modules_news_html $2; exit;; - * ) _ak_modules_news_usage;; + * ) _ak_usage;; esac -else _ak_modules_news_usage +else _ak_usage fi diff --git a/bin/ak-node-info b/bin/ak-node-info index 1b12798..b667fd3 100755 --- a/bin/ak-node-info +++ b/bin/ak-node-info @@ -1,5 +1,20 @@ #!/bin/bash -PROGRAM="$(basename $0)" +## +## Brief description +## +## Usage: +## +## -h, --help Prints this help message +## +## --ipfs +## +## --ipns +## +fullprogrampath="$(realpath $0)" +PROGRAM=$(basename $0) +descriptionString="Quick description" +source $AK_LIBDIR/_ak_log +source $AK_LIBDIR/_ak_script source $AK_LIBDIR/_ak_ipfs # Resolves the IPNS key "ak-config" to its current IPFS value # Return IPFS CIDv0 without /ipfs/ prefix @@ -13,23 +28,23 @@ _ak_node_info_ipns_key(){ _ak_ipfs_key_list_full | grep ak-config | awk '{print $1}' } -_ak_node_info_usage(){ - echo "$PROGRAM ipfs | ipns" -} if [ ! -z "$1" ] then case "$1" in - ipfs) + -h|--help) + _ak_usage + ;; + --ipfs) _ak_node_info_ipfs_hash ;; - ipns) + --ipns) _ak_node_info_ipns_key ;; *) - _ak_node_info_usage + _ak_usage ;; esac else - _ak_node_info_usage + _ak_usage fi diff --git a/bin/ak-profile b/bin/ak-profile index 02a9fe4..74491ef 100755 --- a/bin/ak-profile +++ b/bin/ak-profile @@ -1,12 +1,39 @@ #!/bin/bash -PROGRAM="$(basename $0)" +## +## Indexes, shows, imports, adds, sets and gets values from and to the +## zchain and files. +## +## Usage: +## +## -h, --help Prints this help message +## +## index Show current status +## +## show <data> Show profile entry from specified DATA IPFS CIDv0 +## +## set <property> <value> Sets a profile value +## +## get <property> Gets a profile value from the on-disk file. +## +## Advanced (use with caution may produce duplicate entries): +## +## add <file> Creates a data file from the profile file you point +## to (file should already be in ZPROFILEDIR. +## +## import <folder> Import a folder to zchain #TODO +## +fullprogrampath="$(realpath $0)" +PROGRAM=$(basename $0) +descriptionString="Profile module" ZPROFILEDIR="$AK_WORKDIR/profile" TEMP="/tmp/aktmp" # Outputs to log file in the classic format :) -source $AK_LIBDIR/_ak_logit +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 # Whatever the command is, we check if $ZPROFILEDIR is there. # If NOT we create it and we change dir there. @@ -169,7 +196,7 @@ EOF exit 2 fi - ak-zblock-pack "profile/add" $(pwd)/data + _ak_zblock_pack "profile/add" $(pwd)/data if [ "$?" -ne 0 ] then echo "error??" @@ -180,37 +207,17 @@ EOF rm -rf "$TEMPASSIN" } -_ak_modules_profile_usage(){ - echo "Usage:" - echo " $PROGRAM command [options]" - echo "" - echo "Indexes, shows, imports, adds, sets and gets values from and to the" - echo "zchain and files." - echo "" - echo " -h, --help Prints this help message" - echo " index Show current status" - echo " show <data> Show profile entry from specified DATA IPFS CIDv0" - echo " set <property> <value> Sets a profile value" - echo " get <property> Gets a profile value from the on-disk file." - echo "" - echo "Advanced (use with caution may produce duplicate entries):" - echo " add <file> Creates a data file from the profile file you point" - echo " to (file should already be in ZPROFILEDIR." - echo " import <folder> Import a folder to zchain #TODO" - echo "" - exit 0 -} if [ ! -z $1 ]; then case $1 in - -h | --help) _ak_modules_profile_usage; exit;; + -h | --help) _ak_usage; exit;; index) _ak_modules_profile_index; exit;; show) _ak_modules_profile_show $2; exit;; import) _ak_modules_profile_import $2; exit;; add) _ak_modules_profile_add $2; exit;; set) _ak_modules_profile_propset $2 "$3"; exit;; get) _ak_modules_profile_propget $2; exit;; - * ) _ak_modules_profile_usage;; + * ) _ak_usage;; esac -else _ak_modules_profile_usage +else _ak_usage fi diff --git a/bin/ak-reference b/bin/ak-reference index ee30ae3..157b797 100755 --- a/bin/ak-reference +++ b/bin/ak-reference @@ -1,16 +1,32 @@ #!/bin/bash +## #TODO +## All you need to know is that there are two options available: +## -h, --help Prints this help message +## index Prints an indexed table of your references files +## import <file> #TODO +## add <file> Creates a data file from the references file you point to +## create [ref] [to] Vim is going to pop up, you will write and save your +## referencesletter and it's going to be saved +fullprogrampath="$(realpath $0)" +PROGRAM=$(basename $0) +descriptionString="Quick description" + + ZREFERENCESDIR="$AK_WORKDIR/references" TEMP="/tmp/aktmp" -source $AK_LIBDIR/_ak_logit + +source $AK_LIBDIR/_ak_log +source $AK_LIBDIR/_ak_script source $AK_LIBDIR/_ak_ipfs source $AK_LIBDIR/_ak_gpg -echo $ZREFERENCESDIR +source $AK_LIBDIR/_ak_zblock + if [ ! -d $ZREFERENCESDIR ]; then mkdir $ZREFERENCESDIR cd $ZREFERENCESDIR - echo "zreferencesdir created" + logit "INFO" "zreferencesdir created" else - logthis "zreferencesdir found" + logit "INFO" "zreferencesdir found" fi _ak_modules_reference_create(){ @@ -38,6 +54,7 @@ EOF _ak_modules_reference_add $ZREFERENCESDIR/$TO_FILE cd $ZREFERENCESDIR } + _ak_modules_reference_index(){ FILES="$(ls -1 $ZREFERENCESDIR)" i=0 @@ -50,10 +67,7 @@ _ak_modules_reference_index(){ let i+=1 done } -_ak_modules_reference_title(){ - echo ak-references-cli - echo "--------------" -} + _ak_modules_reference_import(){ echo "#TODO" if [ ! -z $1 ] @@ -76,6 +90,7 @@ _ak_modules_reference_import(){ fi exit 224 } + _ak_modules_reference_add(){ TEMP="$(ak-tempassin)" cd $TEMP @@ -102,7 +117,7 @@ EOF cat data | jq -M -c > tmp cat tmp > data rm tmp - ak-zblock-pack "references/add" $(pwd)/data + _ak_zblock_pack "references/add" $(pwd)/data if [ $? != 0 ] then echo "error??" @@ -111,27 +126,14 @@ EOF echo "References added successfully" } -_ak_modules_reference_usage(){ - _ak_modules_reference_title - echo "#TODO" - echo "All you need to know is that there are two options available:" - echo "-h, --help Prints this help message" - echo "index Prints an indexed table of your references files" - echo "import <file> #TODO" - echo "add <file> Creates a data file from the references file you point to" - echo "create [ref] [to] Vim is going to pop up, you will write and save your" - echo " referencesletter and it's going to be saved" - exit 0 -} - if [ ! -z $1 ]; then case $1 in - -h | --help) _ak_modules_reference_usage; exit;; + -h | --help) _ak_usage; exit;; index) _ak_modules_reference_index; exit;; import) _ak_modules_reference_import $2; exit;; add) _ak_modules_reference_add $2; exit;; create) _ak_modules_reference_create $2 $3; exit;; - * ) _ak_modules_reference_usage;; + * ) _ak_usage;; esac -else _ak_modules_reference_usage +else _ak_usage fi diff --git a/bin/ak-repositories b/bin/ak-repositories index 8dc2652..5086eb2 100755 --- a/bin/ak-repositories +++ b/bin/ak-repositories @@ -1,4 +1,5 @@ #!/bin/bash +source $AK_LIBDIR/_ak_zblock REPODIR="$HOME/projects" BAREDIR="$HOME/bare" REPOSTORE="$HOME/.arching-kaos/repostore" @@ -106,7 +107,7 @@ add(){ then _ak_ipfs_name_publish --key="$PROJECT.git" /ipfs/$IPFS printf '{"project":"%s.git","ipns":"%s"}' $PROJECT $try > data - ak-zblock-pack "repos/add" $PWD/data + _ak_zblock_pack "repos/add" $PWD/data echo "Done" fi fi diff --git a/bin/ak-schain-latest-cached b/bin/ak-schain-latest-cached index 031e997..18ac1df 100755 --- a/bin/ak-schain-latest-cached +++ b/bin/ak-schain-latest-cached @@ -1,7 +1,7 @@ #!/bin/bash PROGRAM="$(basename $0)" -source $AK_LIBDIR/_ak_logit +source $AK_LIBDIR/_ak_log if [ ! -f $AK_WORKDIR/schain.latest ] then ak-find-latest-mined-sblock > $AK_WORKDIR/schain.latest diff --git a/bin/ak-sm-files b/bin/ak-sm-files index 56e80d1..ba4d851 100755 --- a/bin/ak-sm-files +++ b/bin/ak-sm-files @@ -5,9 +5,10 @@ CRD=$(cat .pwd) PROGRAM="$(basename $0)" #set -xe -source $AK_LIBDIR/_ak_logit +source $AK_LIBDIR/_ak_log source $AK_LIBDIR/_ak_ipfs source $AK_LIBDIR/_ak_gpg +source $AK_LIBDIR/_ak_zblock if [ ! -d $ZFILESDIR ]; then mkdir $ZFILESDIR @@ -117,7 +118,7 @@ EOF cat data echo "Publishing..." - ak-zblock-pack sha-files/announce $(pwd)/data + _ak_zblock_pack sha-files/announce $(pwd)/data if [ $? == 0 ] then echo "cool" diff --git a/bin/ak-sm-filesplitter b/bin/ak-sm-filesplitter index b29ac59..d607c15 100755 --- a/bin/ak-sm-filesplitter +++ b/bin/ak-sm-filesplitter @@ -41,7 +41,7 @@ TECHDIR="/tmp/tltmp/chks/" CURRENTDIR="$(pwd)/" # Our snippet for logging debug info -source $AK_LIBDIR/_ak_logit +source $AK_LIBDIR/_ak_log # Checking directories and create them if necessary diff --git a/bin/ak-startup b/bin/ak-startup index 07c7935..9d972d3 100755 --- a/bin/ak-startup +++ b/bin/ak-startup @@ -2,6 +2,6 @@ PATH=$PATH:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:$HOME/bin:$HOME/.arching-kaos/bin screen -dmS ipfs-daemon ipfs daemon source $HOME/.arching-kaos/rc -ak-logrotate +ak-log-rotate screen -dmS akdaemon ak-daemon > $AK_WORKDIR/akd.log 2> $AK_WORKDIR/akd.err & printf '%s' "$!" > $AK_WORKDIR/akd.pid # ak-logfollow diff --git a/bin/ak-stellar-get-participants b/bin/ak-stellar-get-participants index 2a0aad7..932393a 100755 --- a/bin/ak-stellar-get-participants +++ b/bin/ak-stellar-get-participants @@ -3,7 +3,7 @@ PROGRAM="$(basename $0)" tempdir=`mktemp -d` tempfile="$tempdir/tmp" tempaddr="$tempdir/tmpaddr" -source $AK_LIBDIR/_ak_logit +source $AK_LIBDIR/_ak_log stellarParticipants="$AK_WORKDIR/stellar-network-participants" stellarParticipantsOnline="$AK_WORKDIR/stellar-network-participants-online" diff --git a/bin/ak-tempassin b/bin/ak-tempassin index 11e534f..20d1810 100755 --- a/bin/ak-tempassin +++ b/bin/ak-tempassin @@ -1,7 +1,7 @@ #!/bin/bash AK_TEMP="$(mktemp -d /tmp/aktmp-XXXXXXX)" PROGRAM="$(basename $0)" -source $AK_LIBDIR/_ak_logit +source $AK_LIBDIR/_ak_log if [ ! -d "$AK_TEMP" ] then diff --git a/bin/ak-todos b/bin/ak-todos index aa3b95f..afe56f8 100755 --- a/bin/ak-todos +++ b/bin/ak-todos @@ -1,19 +1,35 @@ #!/bin/bash +## +## Brief description +## +## Usage: +## +## -h, --help Prints this help message +## +## index Prints an indexed table of your todos files +## +## import <file> #TODO +## +## add <file> Creates a data file from the todos file you point to +## +## create Vim is going to pop up, you will write and save your +## todosletter and it's going to be saved +## +fullprogrampath="$(realpath $0)" +PROGRAM=$(basename $0) +descriptionString="Quick description" PROGRAM="$(basename $0)" -source $AK_LIBDIR/_ak_logit +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 ZTODOSDIR="$AK_WORKDIR/todos" TEMP="/tmp/aktmp" if [ ! -d $ZTODOSDIR ]; then mkdir $ZTODOSDIR cd $ZTODOSDIR - git init - echo "Todos repository" > README - echo "Qmetc" >> README - git add README - git commit -m "Initiated todos repository" logit "INFO" "ztodosdir created along with git repo" else logit "INFO" "ztodosdir found" @@ -29,15 +45,12 @@ _ak_modules_todos_create(){ TO_FILE=$TODOS_FILE-$(echo $TITLE | tr '[:upper:]' '[:lower:]' | sed -e 's/ /\_/g' ) IPFS_FILE=$(_ak_ipfs_add $TODOS_FILE) mv $TODOS_FILE $ZTODOSDIR/$TO_FILE - sed -e 's,Qm.*,'"$IPFS_FILE"',g' $ZTODOSDIR/README _ak_modules_todos_add $ZTODOSDIR/$TO_FILE logit "INFO" "Adding to git repo..." cd $ZTODOSDIR - git add $TO_FILE README - git commit -m "Added $TO_FILE with $(head -n 1 $ZTODOSDIR/$TO_FILE)" - git clean --force # rm -rf $TEMP } + _ak_modules_todos_index(){ FILES="$(ls -1 $ZTODOSDIR)" i=0 @@ -49,10 +62,7 @@ _ak_modules_todos_index(){ let i+=1 done } -_ak_modules_todos_title(){ - echo ak-todos-cli - echo "--------------" -} + _ak_modules_todos_import(){ echo "#TODO" if [ ! -z $1 ] @@ -75,6 +85,7 @@ _ak_modules_todos_import(){ fi exit 224 } + _ak_modules_todos_add(){ TEMP="$(ak-tempassin)" cd $TEMP @@ -97,37 +108,27 @@ _ak_modules_todos_add(){ } EOF else - echo "File $FILE doesn't exist"; + logit "ERROR" "File $FILE doesn't exist"; exit 2 fi - ak-zblock-pack "todos/add" $(pwd)/data + _ak_zblock_pack "todos/add" $(pwd)/data if [ $? == 0 ] then logit "INFO" "Todos added successfully" else - echo "error??" + logit "ERROR" "error?? _ak_zblock_pack failed" exit 1 fi } -_ak_modules_todos_usage(){ - _ak_modules_todos_title - echo "" - echo "-h, --help Prints this help message" - echo "index Prints an indexed table of your todos files" - echo "import <file> #TODO" - echo "add <file> Creates a data file from the todos file you point to" - echo "create Vim is going to pop up, you will write and save your" - echo " todosletter and it's going to be saved" - exit 0 -} + if [ ! -z $1 ]; then case $1 in - -h | --help) _ak_modules_todos_usage; exit;; + -h | --help) _ak_usage; exit;; index) _ak_modules_todos_index; exit;; import) _ak_modules_todos_import $2; exit;; add) _ak_modules_todos_add $2; exit;; create) _ak_modules_todos_create; exit;; - * ) _ak_modules_todos_usage;; + * ) _ak_usage;; esac -else _ak_modules_todos_usage +else _ak_usage fi diff --git a/bin/ak-transactions b/bin/ak-transactions index 6f33e54..f3bbf79 100755 --- a/bin/ak-transactions +++ b/bin/ak-transactions @@ -1,12 +1,16 @@ #!/bin/bash -PROGRAM="$(basename $0)" -_ak_modules_transactions_usage(){ - echo "$PROGRAM from to amount" -} +## +## ak-transactions <from> <to> <amount> +## +fullprogrampath="$(realpath $0)" +PROGRAM=$(basename $0) +descriptionString="Transactions module" -source $AK_LIBDIR/_ak_logit +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 _ak_modules_transactions_main(){ logit "INFO" "$FROM_ADDRESS to $TO_ADDRESS value sent: $AMOUNT" @@ -45,6 +49,6 @@ then AMOUNT="$3" _ak_modules_transactions_main cat $PWD/data | jq -M - ak-zblock-pack transaction/add $PWD/data -else _ak_modules_transactions_usage + _ak_zblock_pack transaction/add $PWD/data +else _ak_usage fi diff --git a/bin/ak-unfollow b/bin/ak-unfollow index 2b39c94..da22809 100755 --- a/bin/ak-unfollow +++ b/bin/ak-unfollow @@ -1,5 +1,7 @@ #!/bin/bash PROGRAM="$(basename $0)" +source $AK_LIBDIR/_ak_config +source $AK_LIBDIR/_ak_ipfs FOLLOWING="$HOME/.arching-kaos/following" fentries="$(cat $FOLLOWING)" if [ ! -z $1 ] diff --git a/bin/ak-zblock-announce b/bin/ak-zblock-announce deleted file mode 100755 index 74bcdfc..0000000 --- a/bin/ak-zblock-announce +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash -PROGRAM="$(basename $0)" -descriptionString="Announce zblock to local API for schain processing" -source $AK_LIBDIR/_ak_logit -source $AK_LIBDIR/_ak_script_description - -curl http://127.0.0.1:8610/v0/announce/zblock --header 'Content-Type: application/json' --data-raw '{"zblock":"'$(ak-get-zlatest)'"}' 2>/dev/null | jq -M -c > /dev/null -if [ "$?" == "0" ] -then - logit "INFO" "zblock $zblock announced" -else - logit "ERROR" "zblock $zblock announcement failed" -fi - diff --git a/bin/ak-zblock-cache b/bin/ak-zblock-cache deleted file mode 100755 index c314d56..0000000 --- a/bin/ak-zblock-cache +++ /dev/null @@ -1,44 +0,0 @@ -#!/bin/bash -PROGRAM="$(basename $0)" -source $AK_LIBDIR/_ak_logit - -if [ ! -d "$AK_CACHEDIR/fzblocks" ] -then - mkdir $AK_CACHEDIR/fzblocks -fi - -if [ ! -z "$1" ] -then - if [ -f "$AK_ZBLOCKDIR/$1" ] && [ "$(du -b $AK_ZBLOCKDIR | awk '{ print $1 }')" != "0" ] - then - if [ "$(sha512sum $AK_ZBLOCKDIR/$1 | awk '{ print $1 }')" == "$(ak-zblock-show $1 | sha512sum | awk '{ print $1 }')" ] - then - logit "INFO" "Cache already there and updated" - else - logit "INFO" "Updating cache" - ak-zblock-show "$1" > $AK_CACHEDIR/fzblocks/$1 - fi - logit "INFO" "No cache found. Caching..." - ak-zblock-show "$1" - if [ "$?" -ne "0" ] - then - logit "ERROR" "ak-zblock-show failed..." - exit 2 - fi - ak-zblock-show "$1" > $AK_CACHEDIR/fzblocks/$1 - else - ak-zblock-show "$1" > $AK_CACHEDIR/fzblocks/$1 - if [ "$?" -ne "0" ] - then - logit "ERROR" "ak-zblock-show failed..." - exit 2 - fi - logit "ERROR" "Could not find zblock $1..." - exit 1 - fi - exit 0 -else - printf "Usage:\n\t%s <zblock-ipfs-hash>\n" "$PROGRAM" 1>&2 - exit 1 -fi - diff --git a/bin/ak-zblock-gen-html b/bin/ak-zblock-gen-html deleted file mode 100755 index d125d82..0000000 --- a/bin/ak-zblock-gen-html +++ /dev/null @@ -1,239 +0,0 @@ -#!/bin/bash -PROGRAM="$(basename $0)" -source $AK_LIBDIR/_ak_ipfs - -time_started=$(date -u +%s.%N) -ss=$(echo $time_started | cut -d '.' -f 1) -nss=$(echo $time_started | cut -d '.' -f 2) -# Check if there are enough arguments -if [ $# -lt 1 ] -then - echo "Error: Not enough arguments provided" - echo "Give a zblock's IPFS CID v0 as an argument" - exit 1 -fi - -if [ -n "$1" ] -then - TEST="$(echo -n "$1" | grep -v '^Qm[A-Za-z0-9]\{44\}$')" - if [ -n "$TEST" ] - then - echo not ok - exit 1 - fi -fi - -arg="$(mktemp)" -ak-enter -l 1 "$1" | jq '.[]' > $arg - -( \ -# Create HTML document -echo "<!DOCTYPE html>" -echo "<html>" -echo "<head>" -echo " <title>Arching Kaos Chain Data" -echo ' ' -echo ' ' -echo ' ' -echo "" -echo "" - -# Iterate through each argument and parse data -if [ -f "$arg" ] -then - # Extract data from argument - zblock=$(cat $arg | jq -r '.zblock') - block=$(cat $arg | jq -r '.block') - timestamp=$(cat $arg | jq -r '.timestamp') - block_signature=$(cat $arg | jq -r '.block_signature') - detach=$(cat $arg | jq -r '.detach') - data=$(cat $arg | jq -r '.data') - module=$(cat $arg | jq -r '.module') - action=$(cat $arg | jq -r '.action') - gpg=$(cat $arg | jq -r '.gpg') - previous=$(cat $arg | jq -r '.previous') - datablock=$(cat $arg | jq -r ".$data") - - # Output data in HTML format - echo "

$PROGRAM

" - echo "

🔎 $zblock

" - if [ "$module" == "news" ] && [ "$action" == "add" ] - then - ak-news -x $zblock - fi - echo "

ℹī¸ $zblock

" - echo " " - echo " " - echo " " - echo " " - echo " " - echo " " - echo " " - echo " " - echo " " - echo " " - echo " " - echo " " - echo " " - echo " " - echo " " - echo " " - echo " " - echo " " - echo " " - echo " " - echo " " - echo " " - echo " " - echo " " - echo " " - echo " " - echo " " - echo " " - echo " " - echo " " - echo " " - echo " " - echo " " - echo " " - echo " " - echo " " - echo " " - echo " " - echo " " - echo " " - echo " " - echo " " - echo " " - echo " " - echo " " - echo " " - echo " " - echo " " - echo " " - echo "
" - echo "
đŸ“Ļ ZBLOCK
" - echo "
" - echo "
" - echo " $zblock" - echo "
$(_ak_ipfs_cat $zblock | jq)
" - echo "
" - echo "
" - echo "
đŸ“Ļ BLOCK
" - echo "
" - echo "
" - echo " $block" - echo "
$(_ak_ipfs_cat $block | jq)
" - echo "
" - echo "
" - echo "
🔏 BLOCK SIGNATURE
" - echo "
" - echo "
" - echo " $block_signature" - echo "
$(_ak_ipfs_cat $block_signature)
" - echo "
" - echo "
" - echo "
⌚ TIMESTAMP
" - echo "
" - echo "

$timestamp

" - echo "
" - echo "
🔌 MODULE
" - echo "
" - echo "

$module

" - echo "
" - echo "
đŸĒ§ ACTION
" - echo "
" - echo "

$action

" - echo "
" - echo "
🔑 GPG
" - echo "
" - echo "
" - echo " $gpg" - echo "
$(_ak_ipfs_cat $gpg)
" - echo "
" - echo "
" - echo "
đŸ“Ļ PREVIOUS
" - echo "
" - echo ' 🔗 '$previous'' - echo "
" - echo "
đŸ“Ļ DATA
" - echo "
" - echo "
" - echo " $data" - echo "
$datablock
" - echo "
" - echo "
" - echo "
🔏 DATA_SIGNATURE
" - echo "
" - echo "
" - echo " $detach" - echo "
$(_ak_ipfs_cat $detach)
" - echo "
" - echo "
" - echo "
📄 ipfs
" - echo "
" - echo ' '🔗 $(echo $datablock | jq -r '.ipfs')'' - echo "
" - echo "
🔏 detach
" - echo "
" - echo "
" - echo " $(echo $datablock | jq -r '.detach')" - echo "
$(_ak_ipfs_cat $(echo $datablock | jq -r '.detach'))
" - echo "
" - echo "
" - echo "
📃 Rendered ZBLOCK
" - echo "
$(cat $arg | jq)
" -fi -time_ended=$(date -u +%s.%N) -se=$(echo $time_ended | cut -d '.' -f 1) -nse=$(echo $time_ended | cut -d '.' -f 2) -echo "
" -echo -n " " -else - echo "$(( $nse - $(echo -n $nss|sed 's/^0*//') )) seconds" -fi - -echo "" -echo "" ) > zblock-$1.html - -rm $arg diff --git a/bin/ak-zblock-manipulator b/bin/ak-zblock-manipulator deleted file mode 100755 index 427ba09..0000000 --- a/bin/ak-zblock-manipulator +++ /dev/null @@ -1,143 +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 -# - -#FINGERPRINT="CHANGE THIS TO YOUR DEFAULT FINGERPRINT" -# We acquire the GPG fingerprint by email address -# The following example finds kaos@kaos.kaos' GPG fingerprint like this -# FINGERPRINT="$(gpg2 --homedir $AK_GPGHOME --list-keys | grep kaos@kaos.kaos -1 | head -n1 | awk '{print $1}')" - -# Below, the usage information -PROGRAM="$(basename $0)" -so