diff options
55 files changed, 1198 insertions, 1021 deletions
@@ -300,7 +300,7 @@ lib/_ak_gpg lib/_ak_newline lib/_ak_script_description lib/_ak_script_exit -lib/_ak_logit +lib/_ak_log IPFS Wrappers ------------- diff --git a/api/lib/akLogThis/index.js b/api/lib/akLogMessage/index.js index 8f26c84..da35877 100644 --- a/api/lib/akLogThis/index.js +++ b/api/lib/akLogMessage/index.js @@ -3,7 +3,7 @@ const config = require('../../config') module.exports = (type, message) => { const command = spawn( - "ak-logthis", + "ak-log-message", ["ak-daemon", type, message] ); @@ -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 <file> TODO +## add <file> 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 <file> #TODO" - echo " add <file> 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 <file> #TODO" +## +## add <file> 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 <file> #TODO" - echo " add <file> 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 <file> <refer_to> Creates a data file from the comments file you point to" +## +## create <refer_to> 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 <file> <refer_to> Creates a data file from the comments file you point to" - echo "create <refer_to> 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 <number>] [zblock] +## ak-enter [-N | --no-verify] [-l | --limit <number>] -n <zchain> +## Usage: +## --help, -h Print this help and exit +## --chain <ipns-link>, -n <ipns-link> Crawl specified chain +## --no-verify, -N Don't verify signatures +## <ipfs-link> 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 <number>] [zblock]" - echo "$PROGRAM [-N | --no-verify] [-l | --limit <number>] -n <zchain>" - echo "Usage:" - echo " --help, -h Print this help and exit" - echo " --chain <ipns-link>, -n <ipns-link> Crawl specified chain" - echo " --no-verify, -N Don't verify signatures" - echo " <ipfs-link> 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 C |