From 465d5db06e56dc21072a8ff01258f6815d340b00 Mon Sep 17 00:00:00 2001
From: kaotisk <kaotisk@arching-kaos.org>
Date: Wed, 27 Mar 2024 09:34:01 +0200
Subject: new lib _ak_ipfs

---
 bin/ak-articles              |   7 +-
 bin/ak-categories            |   7 +-
 bin/ak-comments              |   7 +-
 bin/ak-config                |   7 +-
 bin/ak-data-expand           |  21 ++--
 bin/ak-enter                 |  13 +-
 bin/ak-files                 |   5 +-
 bin/ak-folders               |   3 +-
 bin/ak-follow                |   3 +-
 bin/ak-get-zlatest           |   3 +-
 bin/ak-ipfs-daemon           |   7 ++
 bin/ak-ipfs-starter          |   7 +-
 bin/ak-mempool               |   9 +-
 bin/ak-mixtapes              |   5 +-
 bin/ak-news                  |  29 ++---
 bin/ak-node-info             |   5 +-
 bin/ak-profile               |   9 +-
 bin/ak-reference             |   7 +-
 bin/ak-repositories          |  24 ++--
 bin/ak-sm-files              |   5 +-
 bin/ak-todos                 |   7 +-
 bin/ak-transactions          |   5 +-
 bin/ak-unfollow              |   6 +-
 bin/ak-zblock-announce       |  14 +++
 bin/ak-zblock-gen-html       |  13 +-
 bin/ak-zblock-manipulator    |  29 ++---
 bin/ak-zblock-pack           |  26 ++--
 bin/ak-zchain-calculate-size |   3 +-
 bin/ak-zchain-chk            |   7 +-
 bin/ak-zchain-rebase         |  11 +-
 bin/ak-zchain-reset          |  12 +-
 lib/_ak_ipfs                 | 283 +++++++++++++++++++++++++++++++++++++++++++
 32 files changed, 467 insertions(+), 132 deletions(-)
 create mode 100755 bin/ak-ipfs-daemon
 create mode 100755 bin/ak-zblock-announce
 create mode 100755 lib/_ak_ipfs

diff --git a/bin/ak-articles b/bin/ak-articles
index 9a9f462..ba45309 100755
--- a/bin/ak-articles
+++ b/bin/ak-articles
@@ -5,6 +5,7 @@ descriptionString="Articles module for Arching Kaos"
 
 source $AK_LIBDIR/_ak_logit
 source $AK_LIBDIR/_ak_script_description
+source $AK_LIBDIR/_ak_ipfs
 source $AK_LIBDIR/_ak_gpg
 
 ZARTICLESDIR="$AK_WORKDIR/articles"
@@ -35,7 +36,7 @@ _ak_modules_articles_create(){
     logit "INFO" "Renaming..."
     TITLE="$(head -n 1 $ARTICLES_FILE)"
     TO_FILE=$ARTICLES_FILE-$(echo $TITLE | tr '[:upper:]' '[:lower:]' | sed -e 's/ /\_/g' )
-    IPFS_FILE=$(ak-ipfs-add $ARTICLES_FILE)
+    IPFS_FILE=$(_ak_ipfs_add $ARTICLES_FILE)
     mv $ARTICLES_FILE $ZARTICLESDIR/$TO_FILE
     sed -e 's,Qm.*,'"$IPFS_FILE"',g' $ZARTICLESDIR/README
     _ak_modules_articles_add $ZARTICLESDIR/$TO_FILE
@@ -90,10 +91,10 @@ _ak_modules_articles_add(){
         echo "Adding articles from " $FILE
         DATETIME=$(echo $FILE | cut -d - -f 1 | awk '{print $1}')
         TITLE=$(head -n 1 $FILE)
-        FILE_IPFS_HASH=$(ak-ipfs-add $FILE)
+        FILE_IPFS_HASH=$(_ak_ipfs_add $FILE)
         FILE_SIGN_FILE=$FILE".asc"
         _ak_gpg_sign_detached $FILE_SIGN_FILE $FILE
-        FILE_SIGNATURE=$(ak-ipfs-add $FILE_SIGN_FILE)
+        FILE_SIGNATURE=$(_ak_ipfs_add $FILE_SIGN_FILE)
         cat > data <<EOF
 {
    "datetime":"$DATETIME",
diff --git a/bin/ak-categories b/bin/ak-categories
index 9387651..6f2da6c 100755
--- a/bin/ak-categories
+++ b/bin/ak-categories
@@ -5,6 +5,7 @@ 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_ipfs
 source $AK_LIBDIR/_ak_gpg
 
 if [ ! -d $AK_CATEGORIES ]; then
@@ -23,7 +24,7 @@ _ak_modules_categories_create(){
     logit "INFO" "Renaming..."
     TITLE="$(head -n 1 $NEWS_FILE)"
     TO_FILE=$NEWS_FILE-$(echo $TITLE | tr '[:upper:]' '[:lower:]' | sed -e 's/ /\_/g' )
-    IPFS_FILE=$(ak-ipfs-add $NEWS_FILE)
+    IPFS_FILE=$(_ak_ipfs_add $NEWS_FILE)
     mv $NEWS_FILE $AK_CATEGORIES/$TO_FILE
     sed -e 's,Qm.*,'"$IPFS_FILE"',g' $AK_CATEGORIES/README
     _ak_modules_categories_add $AK_CATEGORIES/$TO_FILE
@@ -74,10 +75,10 @@ _ak_modules_categories_add(){
         logit "INFO" "Adding news from " $FILE
         DATETIME=$(echo $FILE | cut -d - -f 1 | awk '{print $1}')
         TITLE=$(head -n 1 $FILE)
-        FILE_IPFS_HASH=$(ak-ipfs-add $FILE)
+        FILE_IPFS_HASH=$(_ak_ipfs_add $FILE)
         FILE_SIGN_FILE=$FILE".asc"
         _ak_gpg_sign_detached $FILE_SIGN_FILE $FILE
-        FILE_SIGNATURE=$(ak-ipfs-add $FILE_SIGN_FILE)
+        FILE_SIGNATURE=$(_ak_ipfs_add $FILE_SIGN_FILE)
         cat > data <<EOF
 {
    "datetime":"$DATETIME",
diff --git a/bin/ak-comments b/bin/ak-comments
index 6a4bb03..220b1a7 100755
--- a/bin/ak-comments
+++ b/bin/ak-comments
@@ -4,6 +4,7 @@ descriptionString="Comments module for Arching Kaos"
 
 source $AK_LIBDIR/_ak_logit
 source $AK_LIBDIR/_ak_script_description
+source $AK_LIBDIR/_ak_ipfs
 source $AK_LIBDIR/_ak_gpg
 
 ZCOMMENTSDIR="$AK_WORKDIR/comments"
@@ -31,7 +32,7 @@ _ak_modules_comments_create(){
     vi $COMMENTS_FILE
     echo "Renaming..."
     TO_FILE=$COMMENTS_FILE
-    IPFS_FILE=$(ak-ipfs-add $COMMENTS_FILE)
+    IPFS_FILE=$(_ak_ipfs_add $COMMENTS_FILE)
     mv $COMMENTS_FILE $ZCOMMENTSDIR/$TO_FILE
     _ak_modules_comments_add $TO_FILE
     logit "INFO" "Adding to git repo..."
@@ -63,10 +64,10 @@ _ak_modules_comments_add(){
         FILE=$ZCOMMENTSDIR/$1
         echo "Adding comments from " $FILE
         DATETIME="$1"
-        FILE_IPFS_HASH=$(ak-ipfs-add $FILE)
+        FILE_IPFS_HASH=$(_ak_ipfs_add $FILE)
         FILE_SIGN_FILE=$FILE".asc"
         _ak_gpg_sign_detached $FILE_SIGN_FILE $FILE
-        FILE_SIGNATURE=$(ak-ipfs-add $FILE_SIGN_FILE)
+        FILE_SIGNATURE=$(_ak_ipfs_add $FILE_SIGN_FILE)
         printf '{"datetime":"%s","ipfs":"%s","detach":"%s"}' $DATETIME $FILE_IPFS_HASH $FILE_SIGNATURE > data
     else
         echo "File $FILE doesn't exist";
diff --git a/bin/ak-config b/bin/ak-config
index 8e2df7b..1fe4d8d 100755
--- a/bin/ak-config
+++ b/bin/ak-config
@@ -3,6 +3,7 @@ PROGRAM="$(basename $0)"
 descriptionString="Arching Kaos Configuration Tool"
 
 source $AK_LIBDIR/_ak_script_description
+source $AK_LIBDIR/_ak_ipfs
 
 _ak_config_title(){
     description
@@ -25,7 +26,7 @@ _ak_config_show(){
     # We will be using our public key also to put it in the block later
     KEY="tmp-gpg.pub"
     gpg2 --homedir $AK_GPGHOME --armour --output $KEY --export $AK_FINGERPRINT
-    GPG_PUB_KEY=$(ak-ipfs-add $KEY)
+    GPG_PUB_KEY=$(_ak_ipfs_add $KEY)
     rm $KEY
 
     echo '
@@ -45,7 +46,7 @@ _ak_config_publish(){
     then
         ipfs key gen ak-config
     fi
-    ak-ipfs-name-publish --key=ak-config /ipfs/$(ak-ipfs-add tmpfile)
+    _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"
@@ -56,7 +57,7 @@ _ak_config_publish(){
 }
 
 _ak_config_published(){
-    ak-ipfs-cat $(ak-node-info ipfs) | jq -c
+    _ak_ipfs_cat $(ak-node-info ipfs) | jq -c
 }
 
 if [ ! -z $1 ]; then
diff --git a/bin/ak-data-expand b/bin/ak-data-expand
index 0a82e63..e5e699f 100755
--- a/bin/ak-data-expand
+++ b/bin/ak-data-expand
@@ -1,6 +1,7 @@
 #!/bin/bash
 PROGRAM="$(basename $0)"
 source $AK_LIBDIR/_ak_logit
+source $AK_LIBDIR/_ak_ipfs
 source $AK_LIBDIR/_ak_gpg
 
 if [ ! -d $AK_WORKDIR/ipfs ]
@@ -16,37 +17,37 @@ then
 		logit "ERROR" "Invalid hash format for $1"
 		exit 1
 	fi
-	ak-ipfs-cat $1 > /dev/null
+	_ak_ipfs_cat $1 > /dev/null
 	if [ "$?" -ne 0 ]
 	then
 		logit "ERROR" "Error while reading $1"
 		exit 1
 	fi
-	ak-ipfs-cat $1 | jq -M > /dev/null
+	_ak_ipfs_cat $1 | jq -M > /dev/null
 	if [ "$?" -ne 0 ]
 	then
 		logit "ERROR" "Error while parsing JSON for $1"
 		exit 1
 	fi
-	ak-ipfs-cat $1 | jq | grep ipfs > /dev/null
+	_ak_ipfs_cat $1 | jq | grep ipfs > /dev/null
 	if [ "$?" -ne 0 ]
 	then
 		logit "ERROR" "Error while extracting data from JSON for $1"
 		exit 1
 	fi
-	DATA="$(ak-ipfs-cat $1 | jq | grep ipfs | sed -e 's/"ipfs": "//g; s/[",]//g; s/ //g')"
+	DATA="$(_ak_ipfs_cat $1 | jq | grep ipfs | sed -e 's/"ipfs": "//g; s/[",]//g; s/ //g')"
 	if [ "$?" -ne 0 ]
 	then
 		logit "ERROR" "Error while extracting data from JSON for $1"
 		exit 1
 	fi
-	ak-ipfs-cat $1 | jq | grep detach > /dev/null
+	_ak_ipfs_cat $1 | jq | grep detach > /dev/null
 	if [ "$?" -ne 0 ]
 	then
 		logit "ERROR" "Error while extracting data from JSON for $1"
 		exit 1
 	fi
-	DETACH="$(ak-ipfs-cat $1 | jq | grep detach | sed -e 's/"detach": "//g; s/[",]//g; s/ //g')"
+	DETACH="$(_ak_ipfs_cat $1 | jq | grep detach | sed -e 's/"detach": "//g; s/[",]//g; s/ //g')"
 	if [ "$?" -ne 0 ]
 	then
 		logit "ERROR" "Error while extracting data from JSON for $1"
@@ -59,7 +60,7 @@ then
 	    exit 1
 	fi
     gpg="$2"
-    ak-ipfs-get $gpg > /dev/null 2>&1
+    _ak_ipfs_get $gpg > /dev/null 2>&1
     if [ "$?" -ne 0 ]
     then
 	logit "ERROR" "Could not get GPG key: $gpg"
@@ -71,7 +72,7 @@ then
 		logit "ERROR" "Could not import GPG key: $gpg"
 		exit 1
 	fi
-	ak-ipfs-get $DETACH > /dev/null 2>&1
+	_ak_ipfs_get $DETACH > /dev/null 2>&1
 	if [ "$?" -ne 0 ]
 	then
 		logit "ERROR" "Error while getting signature: $DETACH for data: $DATA"
@@ -79,7 +80,7 @@ then
 	fi
 	mv $DETACH $DATA.asc
 	logit "INFO" "Block signature downloaded"
-	ak-ipfs-get $DATA > /dev/null 2>&1
+	_ak_ipfs_get $DATA > /dev/null 2>&1
 	if [ "$?" -ne 0 ]
 	then
 		logit "ERROR" "Error while getting data: $DATA"
@@ -94,7 +95,7 @@ then
 	fi
     mv $DATA $AK_WORKDIR/ipfs
 	logit "INFO" "Block signature verified"
-    echo -n '"data":"'$1'","'$1'":'$(ak-ipfs-cat $1|jq -M -c)','
+    echo -n '"data":"'$1'","'$1'":'$(_ak_ipfs_cat $1|jq -M -c)','
 	exit 0
 else
 	echo "Usage: $PROGRAM HASH GPG"
diff --git a/bin/ak-enter b/bin/ak-enter
index 01a93f9..9d9efc5 100755
--- a/bin/ak-enter
+++ b/bin/ak-enter
@@ -21,6 +21,7 @@ PROGRAM="$(basename $0)"
 descriptionString="Crawl an arching kaos chain"
 source $AK_LIBDIR/_ak_logit
 source $AK_LIBDIR/_ak_script_description
+source $AK_LIBDIR/_ak_ipfs
 source $AK_LIBDIR/_ak_gpg
 
 _ak_enter_title(){
@@ -143,7 +144,7 @@ do
             isIPFSv0 "$zblock"
 
             # We check if any $zblock at all
-            ak-ipfs-cat $zblock | jq -c -M > $AK_ZBLOCKDIR/$zblock
+            _ak_ipfs_cat $zblock | jq -c -M > $AK_ZBLOCKDIR/$zblock
             if [ "$?" -ne 0 ]
             then
                 logit "ERROR" "ZBLOCK $zblock READ failed"
@@ -188,7 +189,7 @@ do
             # Same as above applies to BLOCK and DATA subparts of each ZBLOCK
             # BLOCKS
             echo -n '"block":"'$block'",'
-            ak-ipfs-cat $block | jq -c -M > $AK_BLOCKDIR/$block
+            _ak_ipfs_cat $block | jq -c -M > $AK_BLOCKDIR/$block
             cat $AK_BLOCKDIR/$block | jq -M > /dev/null 2>&1
             if [ "$?" -ne 0 ]
             then
@@ -231,7 +232,7 @@ do
 
             if [ $verify == 1 ]
             then
-                ak-ipfs-get $gpg > /dev/null 2>&1
+                _ak_ipfs_get $gpg > /dev/null 2>&1
                 if [ "$?" -ne 0 ]
                 then
                     logit "ERROR" "Could not get GPG key: $gpg ."
@@ -243,7 +244,7 @@ do
                     logit "ERROR" "Could not import GPG key: $gpg ."
                     exit 1
                 fi
-                ak-ipfs-get $block_signature > /dev/null 2>&1
+                _ak_ipfs_get $block_signature > /dev/null 2>&1
                 if [ "$?" -ne 0 ]
                 then
                     logit "ERROR" "Error while getting $block_signature for $block"
@@ -252,7 +253,7 @@ do
                 mv $block_signature $block.asc
                 logit "INFO" "Block signature downloaded"
 
-                ak-ipfs-get $block > /dev/null 2>&1
+                _ak_ipfs_get $block > /dev/null 2>&1
                 if [ "$?" -ne 0 ]
                 then
                     logit "ERROR" "Could not get $block block"
@@ -280,7 +281,7 @@ do
 
             # DATA
             # Only print to stdout
-            # ak-ipfs-cat $data
+            # _ak_ipfs_cat $data
             touch $AK_DATADIR/$data
 
             # Now, since we sourced the BLOCK to our terminal, we can search
diff --git a/bin/ak-files b/bin/ak-files
index c4d6f2c..7cdedcd 100755
--- a/bin/ak-files
+++ b/bin/ak-files
@@ -4,6 +4,7 @@ ZFILESDIR="$AK_WORKDIR/files"
 TEMP="/tmp/aktmp"
 PROGRAM="$(basename $0)"
 source $AK_LIBDIR/_ak_logit
+source $AK_LIBDIR/_ak_ipfs
 source $AK_LIBDIR/_ak_gpg
 
 if [ ! -d $ZFILESDIR ]; then
@@ -55,7 +56,7 @@ main(){
     FILE="$TEMPASSIN/$1"
 
     logit "INFO" "Adding $FILE to IPFS..."
-    FILE_IPFS_HASH=$(ak-ipfs-add $FILE)
+    FILE_IPFS_HASH=$(_ak_ipfs_add $FILE)
     if [ $? == 0 ]; then
         logit "INFO" "Added $FILE to IPFS"
     else
@@ -71,7 +72,7 @@ main(){
     fi
 
     logit "INFO" "Adding signature to IPFS"
-    SIGNATURE=$(ak-ipfs-add $TEMPASSIN/$SIGN_FILE)
+    SIGNATURE=$(_ak_ipfs_add $TEMPASSIN/$SIGN_FILE)
     if [ $? == 0 ]; then
         logit "INFO" "Added"
     else
diff --git a/bin/ak-folders b/bin/ak-folders
index b5f2601..2651571 100755
--- a/bin/ak-folders
+++ b/bin/ak-folders
@@ -5,6 +5,7 @@ ZFOLDERSDIR="$AK_WORKDIR/folders"
 TEMP="/tmp/aktmp"
 
 source $AK_LIBDIR/_ak_logit
+source $AK_LIBDIR/_ak_ipfs
 
 if [ ! -d $ZFOLDERSDIR ]; then
     mkdir $ZFOLDERSDIR
@@ -45,7 +46,7 @@ _ak_modules_folders_main(){
     FOLDER="$1"
 
     logit "INFO" "Adding $FOLDER to IPFS..."
-    FOLDER_IPFS_HASH=$(ak-ipfs-add $FOLDER)
+    FOLDER_IPFS_HASH=$(_ak_ipfs_add $FOLDER)
     if [ $? == 0 ]; then
         logit "INFO" "done"
     else
diff --git a/bin/ak-follow b/bin/ak-follow
index e0e7336..dea706f 100755
--- a/bin/ak-follow
+++ b/bin/ak-follow
@@ -2,6 +2,7 @@
 FOLLOWING="$HOME/.arching-kaos/following"
 PROGRAM="$(basename $0)"
 source $AK_LIBDIR/_ak_logit
+source $AK_LIBDIR/_ak_ipfs
 
 if [ ! -z $1 ]
 then
@@ -12,7 +13,7 @@ then
         exit 1
     fi
     echo $1 >> $FOLLOWING
-    IPFS=$(ak-ipfs-add $FOLLOWING)
+    IPFS=$(_ak_ipfs_add $FOLLOWING)
     if [ $? != 0 ]
     then
         logit "ERROR" "Addition failed"
diff --git a/bin/ak-get-zlatest b/bin/ak-get-zlatest
index 36de493..64085fd 100755
--- a/bin/ak-get-zlatest
+++ b/bin/ak-get-zlatest
@@ -1,2 +1,3 @@
 #!/bin/bash
-ak-ipfs-files-stat /zlatest | head -n 1| tr -d '\n'
+source $AK_LIBDIR/_ak_ipfs
+_ak_ipfs_files_stat /zlatest | head -n 1| tr -d '\n'
diff --git a/bin/ak-ipfs-daemon b/bin/ak-ipfs-daemon
new file mode 100755
index 0000000..ad0565d
--- /dev/null
+++ b/bin/ak-ipfs-daemon
@@ -0,0 +1,7 @@
+#!/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 b067259..3685736 100755
--- a/bin/ak-ipfs-starter
+++ b/bin/ak-ipfs-starter
@@ -1,8 +1,11 @@
 #!/bin/bash
 PROGRAM="$(basename $0)"
-screen -dmS ipfs-daemon ipfs daemon --routing=dht --migrate
+
+source $AK_LIBDIR/_ak_logit
+
+screen -dmS akipfsd ak-ipfs-daemon
 if [ "$?" != "0" ]
 then
-    ak-logthis "$PROGRAM" "ERROR" "Failed to start IPFS daemon"
+    logit "ERROR" "Failed to start IPFS daemon"
     exit 1
 fi
diff --git a/bin/ak-mempool b/bin/ak-mempool
index 1baf4c8..51f59a7 100755
--- a/bin/ak-mempool
+++ b/bin/ak-mempool
@@ -5,13 +5,16 @@
 # They also are a part of our swarm.
 # So should we ask for our peers?
 
-ak-ipfs-swarm-peers > tmp_peers
+source $AK_LIBDIR/_ak_logit
+source $AK_LIBDIR/_ak_ipfs
+
+_ak_ipfs_swarm_peers > tmp_peers
 
 while IFS="" read -r p || [ -n "$p" ]
 do
 	peer="$(echo "$p" | sed -e 's/^.*\///')"
-	echo "Peer $peer found! Examining..."
-	ak-ipfs-cat /ipns/$peer/zlatest
+	logit "INFO" "Peer $peer found! Examining..."
+	_ak_ipfs_cat /ipns/$peer/zlatest
 done < tmp_peers
 
 rm tmp_peers
diff --git a/bin/ak-mixtapes b/bin/ak-mixtapes
index 242211d..6b70bf5 100755
--- a/bin/ak-mixtapes
+++ b/bin/ak-mixtapes
@@ -5,6 +5,7 @@ PROGRAM="$(basename $0)"
 descriptionString="AK mixtape block creator"
 source $AK_LIBDIR/_ak_logit
 source $AK_LIBDIR/_ak_script_description
+source $AK_LIBDIR/_ak_ipfs
 source $AK_LIBDIR/_ak_gpg
 
 _ak_modules_mixtapes_usage(){
@@ -33,12 +34,12 @@ _ak_modules_mixtapes_specs(){
 _ak_modules_mixtapes_main(){
     echo $MIXTAPE_FILE "by" $MIXTAPE_ARTIST "named as" $MIXTAPE_TITLE
 
-    MIXTAPE_IPFS_HASH=$(ak-ipfs-add $MIXTAPE_FILE)
+    MIXTAPE_IPFS_HASH=$(_ak_ipfs_add $MIXTAPE_FILE)
 
     MIXTAPE_SIGN_FILE=$MIXTAPE_FILE".asc"
     _ak_gpg_sign_detached $MIXTAPE_SIGN_FILE $MIXTAPE_FILE
 
-    MIXTAPE_SIGNATURE=$(ak-ipfs-add $MIXTAPE_SIGN_FILE)
+    MIXTAPE_SIGNATURE=$(_ak_ipfs_add $MIXTAPE_SIGN_FILE)
 
     cat > data <<EOF
 {
diff --git a/bin/ak-news b/bin/ak-news
index 84458c8..4c42a5d 100755
--- a/bin/ak-news
+++ b/bin/ak-news
@@ -7,6 +7,7 @@ TEMP="/tmp/aktmp"
 
 source $AK_LIBDIR/_ak_logit
 source $AK_LIBDIR/_ak_script_description
+source $AK_LIBDIR/_ak_ipfs
 source $AK_LIBDIR/_ak_gpg
 
 if [ ! -d $ZNEWSDIR ]; then
@@ -32,7 +33,7 @@ _ak_modules_news_create(){
     echo "Renaming..."
     TITLE="$(head -n 1 $NEWS_FILE)"
     TO_FILE=$NEWS_FILE-$(echo $TITLE | tr '[:upper:]' '[:lower:]' | sed -e 's/ /\_/g' )
-    IPFS_FILE=$(ak-ipfs-add $NEWS_FILE)
+    IPFS_FILE=$(_ak_ipfs_add $NEWS_FILE)
     mv $NEWS_FILE $ZNEWSDIR/$TO_FILE
     sed -i -e 's,Qm.*,'"$IPFS_FILE"',g' $ZNEWSDIR/README
     _ak_modules_news_add $TO_FILE
@@ -99,13 +100,13 @@ _ak_modules_news_add_from_file(){
         cp $FILE $TEMP
         FILE="$(basename $1)"
         cd $TEMP
-        echo "Adding news from " $FILE
+        logit "INFO" "Adding news from " $FILE
         DATETIME=$(echo $FILE | cut -d - -f 1 | awk '{print $1}')
         TITLE=$(head -n 1 $FILE)
-        FILE_IPFS_HASH=$(ak-ipfs-add $FILE)
+        FILE_IPFS_HASH=$(_ak_ipfs_add $FILE)
         FILE_SIGN_FILE=$FILE".asc"
         _ak_gpg_sign_detached $FILE_SIGN_FILE $FILE
-        FILE_SIGNATURE=$(ak-ipfs-add $FILE_SIGN_FILE)
+        FILE_SIGNATURE=$(_ak_ipfs_add $FILE_SIGN_FILE)
         cat > data <<EOF
 {
    "datetime":"$DATETIME",
@@ -116,15 +117,15 @@ _ak_modules_news_add_from_file(){
 }
 EOF
     else
-        echo "File $FILE doesn't exist";
+        logit "ERROR" "File $FILE doesn't exist";
         exit 2
     fi
     ak-zblock-pack "news/add" $(pwd)/data
     if [ $? == 0 ]
     then
-        echo "News added successfully"
+        logit "INFO" "News added successfully"
     else
-        echo "error??"
+        logit "ERROR" "Failed to pack zblock"
         exit 1
     fi
     rm -rf $TEMP
@@ -135,13 +136,13 @@ _ak_modules_news_add(){
     cd $TEMP
     if [ -f $ZNEWSDIR/$1 ]; then
         FILE="$1"
-        echo "Adding news from " $FILE
+        logit "INFO" "Adding news from " $FILE
         DATETIME=$(echo $FILE | cut -d - -f 1 | awk '{print $1}')
         TITLE=$(head -n 1 $ZNEWSDIR/$FILE)
-        FILE_IPFS_HASH=$(ak-ipfs-add $ZNEWSDIR/$FILE)
+        FILE_IPFS_HASH=$(_ak_ipfs_add $ZNEWSDIR/$FILE)
         FILE_SIGN_FILE=$FILE".asc"
         _ak_gpg_sign_detached $FILE_SIGN_FILE $ZNEWSDIR/$FILE
-        FILE_SIGNATURE=$(ak-ipfs-add $FILE_SIGN_FILE)
+        FILE_SIGNATURE=$(_ak_ipfs_add $FILE_SIGN_FILE)
         cat > data <<EOF
 {
    "datetime":"$DATETIME",
@@ -152,15 +153,15 @@ _ak_modules_news_add(){
 }
 EOF
     else
-        echo "File $FILE doesn't exist";
+        logit "ERROR" "File $1 doesn't exist";
         exit 2
     fi
     ak-zblock-pack "news/add" $(pwd)/data
     if [ $? == 0 ]
     then
-        echo "News added successfully"
+        logit "INFO" "News added successfully"
     else
-        echo "error??"
+        logit "ERROR" "error??"
         exit 1
     fi
 }
@@ -193,7 +194,7 @@ _ak_modules_news_read(){
     if [ "$module" == "news" ] && [ "$action" == "add" ]
     then
 
-        ak-ipfs-cat $linkToText
+        _ak_ipfs_cat $linkToText
     else
         logit "ERROR" "Not a news block."
         echo "ERROR Not a news block."
diff --git a/bin/ak-node-info b/bin/ak-node-info
index 73217a0..1b12798 100755
--- a/bin/ak-node-info
+++ b/bin/ak-node-info
@@ -1,15 +1,16 @@
 #!/bin/bash
 PROGRAM="$(basename $0)"
+source $AK_LIBDIR/_ak_ipfs
 # Resolves the IPNS key "ak-config" to its current IPFS value
 # Return IPFS CIDv0 without /ipfs/ prefix
 _ak_node_info_ipfs_hash(){
-    ak-ipfs-name-resolve /ipns/$(_ak_node_info_ipns_key) | sed -e 's/\/ipfs\///'
+    _ak_ipfs_name_resolve /ipns/$(_ak_node_info_ipns_key) | sed -e 's/\/ipfs\///'
 }
 
 # Finds ak-config ipns key
 # Returns IPNS key
 _ak_node_info_ipns_key(){
-    ak-ipfs-key-list-full | grep ak-config | awk '{print $1}'
+    _ak_ipfs_key_list_full | grep ak-config | awk '{print $1}'
 }
 
 _ak_node_info_usage(){
diff --git a/bin/ak-profile b/bin/ak-profile
index fa07fcb..02a9fe4 100755
--- a/bin/ak-profile
+++ b/bin/ak-profile
@@ -5,6 +5,7 @@ TEMP="/tmp/aktmp"
 
 # Outputs to log file in the classic format :)
 source $AK_LIBDIR/_ak_logit
+source $AK_LIBDIR/_ak_ipfs
 source $AK_LIBDIR/_ak_gpg
 
 # Whatever the command is, we check if $ZPROFILEDIR is there.
@@ -26,7 +27,7 @@ _ak_modules_profile_show(){
     if [ ! -z $1 ]
     then
         logit "INFO" "Working with $1"
-        ak-ipfs-cat $(echo $(ak-ipfs-cat $1) | jq '.ipfs' -r)
+        _ak_ipfs_cat $(echo $(_ak_ipfs_cat $1) | jq '.ipfs' -r)
     else
         echo "No DATA provided"
         exit 1
@@ -59,7 +60,7 @@ EOF
     if [ $? == 0 ]
     then
         echo "Added successfully... proceeding"
-        IPFS_FILE=$(ak-ipfs-add $ZPROPERTY_FILE)
+        IPFS_FILE=$(_ak_ipfs_add $ZPROPERTY_FILE)
         echo "Prop writting,,, $IPFS_FILE"
         _ak_modules_profile_add $ZPROPERTY_KEY
         cd $ZPROFILEDIR
@@ -152,10 +153,10 @@ _ak_modules_profile_add(){
     if [ -f $ZPROFILEDIR/$1 ]; then
         FILE="$ZPROFILEDIR/$1"
         echo "Adding from " $FILE
-        FILE_IPFS_HASH=$(ak-ipfs-add $FILE)
+        FILE_IPFS_HASH=$(_ak_ipfs_add $FILE)
         FILE_SIGN_FILE=$(pwd)/$1".asc"
         _ak_gpg_sign_detached $FILE_SIGN_FILE $FILE
-        FILE_SIGNATURE=$(ak-ipfs-add $FILE_SIGN_FILE)
+        FILE_SIGNATURE=$(_ak_ipfs_add $FILE_SIGN_FILE)
         cat > data <<EOF
 {
    "datetime":"$(date -u +%s)",
diff --git a/bin/ak-reference b/bin/ak-reference
index a1a800f..ee30ae3 100755
--- a/bin/ak-reference
+++ b/bin/ak-reference
@@ -2,6 +2,7 @@
 ZREFERENCESDIR="$AK_WORKDIR/references"
 TEMP="/tmp/aktmp"
 source $AK_LIBDIR/_ak_logit
+source $AK_LIBDIR/_ak_ipfs
 source $AK_LIBDIR/_ak_gpg
 echo $ZREFERENCESDIR
 if [ ! -d $ZREFERENCESDIR ]; then
@@ -32,7 +33,7 @@ EOF
     TO_FILE="$REFERENCEFILE-$REFERENCE-$REFER_TO"
     mv $REFERENCEFILE $ZREFERENCESDIR/$TO_FILE
     echo $TO_FILE
-    IPFS_FILE=$(ak-ipfs-add $ZREFERENCESDIR/$TO_FILE)
+    IPFS_FILE=$(_ak_ipfs_add $ZREFERENCESDIR/$TO_FILE)
     sed -e 's,Qm.*,'"$IPFS_FILE"',g' $ZREFERENCESDIR/README
     _ak_modules_reference_add $ZREFERENCESDIR/$TO_FILE
     cd $ZREFERENCESDIR
@@ -85,10 +86,10 @@ _ak_modules_reference_add(){
     FILE="$1"
     echo "Adding references from " $FILE
     DATETIME=$(echo $FILE | cut -d - -f 1 | awk '{print $1}')
-    FILE_IPFS_HASH=$(ak-ipfs-add $FILE)
+    FILE_IPFS_HASH=$(_ak_ipfs_add $FILE)
     FILE_SIGN_FILE=$FILE".asc"
     _ak_gpg_sign_detached $FILE_SIGN_FILE $FILE
-    FILE_SIGNATURE=$(ak-ipfs-add $FILE_SIGN_FILE)
+    FILE_SIGNATURE=$(_ak_ipfs_add $FILE_SIGN_FILE)
     cat > data <<EOF
 {
    "datetime":"$(date -u +%s)",
diff --git a/bin/ak-repositories b/bin/ak-repositories
index c148a81..8dc2652 100755
--- a/bin/ak-repositories
+++ b/bin/ak-repositories
@@ -18,9 +18,9 @@ import(){
         then
             cd $PROJECT.git
             git repack -a
-            IPFS="$(ak-ipfs-add .)"
-            ak-ipfs-key-gen "$PROJECT.git"
-            ak-ipfs-name-publish --key="$PROJECT.git" /ipfs/$IPFS
+            IPFS="$(_ak_ipfs_add .)"
+            _ak_ipfs_key_gen "$PROJECT.git"
+            _ak_ipfs_name_publish --key="$PROJECT.git" /ipfs/$IPFS
             cd $HOME/bare
         else
             echo "$PROJECT not a git repo"
@@ -40,8 +40,8 @@ update(){
             cd $BARE
             git pull
             git repack -a
-            IPFS="$(ak-ipfs-add .)"
-            ak-ipfs-name-publish --key="$BARENAME" /ipfs/$IPFS
+            IPFS="$(_ak_ipfs_add .)"
+            _ak_ipfs_name_publish --key="$BARENAME" /ipfs/$IPFS
             echo "DONE"
         else
             echo "NO BARE TO UPDATE"
@@ -55,8 +55,8 @@ update(){
             cd "$PROJECT"
             git pull
             git repack -a
-            IPFS="$(ak-ipfs-add .)"
-            ak-ipfs-name-publish --key="$PROJECT" /ipfs/$IPFS
+            IPFS="$(_ak_ipfs_add .)"
+            _ak_ipfs_name_publish --key="$PROJECT" /ipfs/$IPFS
             cd $BAREDIR
         done
     fi
@@ -100,11 +100,11 @@ add(){
         then
             cd $BAREGITDIR
             git repack -a
-            IPFS="$(ak-ipfs-add .)"
-            try=ak-ipfs-key-gen "$PROJECT.git"
+            IPFS="$(_ak_ipfs_add .)"
+            try=_ak_ipfs_key_gen "$PROJECT.git"
             if [ $? == 0 ]
             then
-                ak-ipfs-name-publish --key="$PROJECT.git" /ipfs/$IPFS
+                _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 
                 echo "Done"
@@ -116,11 +116,11 @@ add(){
 }
 
 index(){
-    ak-ipfs-key-list-full | grep -e '\.git'
+    _ak_ipfs_key_list_full | grep -e '\.git'
 }
 
 set-as-profile(){
-    IPFS=$(ak-ipfs-add $REPOSTORE)
+    IPFS=$(_ak_ipfs_add $REPOSTORE)
     if [ $? == 0 ]
     then
         profile set repositories $IPFS
diff --git a/bin/ak-sm-files b/bin/ak-sm-files
index 9548b3b..56e80d1 100755
--- a/bin/ak-sm-files
+++ b/bin/ak-sm-files
@@ -6,6 +6,7 @@ CRD=$(cat .pwd)
 PROGRAM="$(basename $0)"
 #set -xe
 source $AK_LIBDIR/_ak_logit
+source $AK_LIBDIR/_ak_ipfs
 source $AK_LIBDIR/_ak_gpg
 
 if [ ! -d $ZFILESDIR ]; then
@@ -61,7 +62,7 @@ main(){
     fi
 
     logit "INFO" "Adding $FILENAME to IPFS..."
-    FILE_IPFS_HASH=$(ak-ipfs-add $FILENAME)
+    FILE_IPFS_HASH=$(_ak_ipfs_add $FILENAME)
     if [ $? == 0 ]; then
         logit "INFO" "Added $FILENAME to IPFS"
     else
@@ -86,7 +87,7 @@ main(){
     fi
 
     logit "INFO" "Adding signature to IPFS"
-    SIGNATURE=$(ak-ipfs-add $SIGN_FILE)
+    SIGNATURE=$(_ak_ipfs_add $SIGN_FILE)
     if [ $? == 0 ]; then
         logit "INFO" "Added"
     else
diff --git a/bin/ak-todos b/bin/ak-todos
index b5ce838..aa3b95f 100755
--- a/bin/ak-todos
+++ b/bin/ak-todos
@@ -1,6 +1,7 @@
 #!/bin/bash
 PROGRAM="$(basename $0)"
 source $AK_LIBDIR/_ak_logit
+source $AK_LIBDIR/_ak_ipfs
 source $AK_LIBDIR/_ak_gpg
 
 ZTODOSDIR="$AK_WORKDIR/todos"
@@ -26,7 +27,7 @@ _ak_modules_todos_create(){
     logit "INFO" "Renaming..."
     TITLE="$(head -n 1 $TODOS_FILE)"
     TO_FILE=$TODOS_FILE-$(echo $TITLE | tr '[:upper:]' '[:lower:]' | sed -e 's/ /\_/g' )
-    IPFS_FILE=$(ak-ipfs-add $TODOS_FILE)
+    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
@@ -82,10 +83,10 @@ _ak_modules_todos_add(){
         logit "INFO" "Adding todos from $FILE"
         DATETIME=$(echo $FILE | cut -d - -f 1 | awk '{print $1}')
         TITLE=$(head -n 1 $FILE)
-        FILE_IPFS_HASH=$(ak-ipfs-add $FILE)
+        FILE_IPFS_HASH=$(_ak_ipfs_add $FILE)
         FILE_SIGN_FILE=$FILE".asc"
         _ak_gpg_sign_detached $FILE_SIGN_FILE $FILE
-        FILE_SIGNATURE=$(ak-ipfs-add $FILE_SIGN_FILE)
+        FILE_SIGNATURE=$(_ak_ipfs_add $FILE_SIGN_FILE)
         cat > data <<EOF
 {
    "datetime":"$TODOS_FILE",
diff --git a/bin/ak-transactions b/bin/ak-transactions
index 1e374fa..6f33e54 100755
--- a/bin/ak-transactions
+++ b/bin/ak-transactions
@@ -5,6 +5,7 @@ _ak_modules_transactions_usage(){
 }
 
 source $AK_LIBDIR/_ak_logit
+source $AK_LIBDIR/_ak_ipfs
 source $AK_LIBDIR/_ak_gpg
 
 _ak_modules_transactions_main(){
@@ -16,12 +17,12 @@ $AMOUNT
 $FEE
 EOF
     TRANSACTION_FILE="transaction_file"
-    FILE_IPFS_HASH=$(ak-ipfs-add $TRANSACTION_FILE)
+    FILE_IPFS_HASH=$(_ak_ipfs_add $TRANSACTION_FILE)
 
     SIGN_FILE=$TRANSACTION_FILE".asc"
     _ak_gpg_sign_detached $SIGN_FILE $TRANSACTION_FILE
 
-    FILE_SIGNATURE=$(ak-ipfs-add $SIGN_FILE)
+    FILE_SIGNATURE=$(_ak_ipfs_add $SIGN_FILE)
 
     cat > data <<EOF
 {
diff --git a/bin/ak-unfollow b/bin/ak-unfollow
index 07940f9..2b39c94 100755
--- a/bin/ak-unfollow
+++ b/bin/ak-unfollow
@@ -8,13 +8,13 @@ then
     sed -i -e 's,'"$search"',,g' $FOLLOWING
     if [ $? != 0 ]
     then
-        ak-logthis "$PROGRAM" "ERROR" "sed didn't found $search"
+        logit "ERROR" "sed didn't found $search"
         exit 1
     fi
-    IPFS="$(ak-ipfs-add $FOLLOWING)"
+    IPFS="$(_ak_ipfs_add $FOLLOWING)"
     if [ $? != 0 ]
     then
-        ak-logthis "$PROGRAM" "ERROR" "IPFS problem"
+        logit "ERROR" "IPFS problem"
         exit 1
     fi
     ak-profile set repositories "$IPFS"
diff --git a/bin/ak-zblock-announce b/bin/ak-zblock-announce
new file mode 100755
index 0000000..74bcdfc
--- /dev/null
+++ b/bin/ak-zblock-announce
@@ -0,0 +1,14 @@
+#!/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-gen-html b/bin/ak-zblock-gen-html
index 0ad01ad..289823b 100755
--- a/bin/ak-zblock-gen-html
+++ b/bin/ak-zblock-gen-html
@@ -1,5 +1,6 @@
 #!/bin/bash
 PROGRAM="$(basename $0)"
+source $AK_LIBDIR/_ak_ipfs
 
 time_started=$(date -u +%s.%N)
 ss=$(echo $time_started | cut -d '.' -f 1)
@@ -101,7 +102,7 @@ then
     echo "            <td>"
     echo "    <details>"
     echo "        <summary>$zblock</summary>"
-    echo "        <pre>$(ak-ipfs-cat $zblock | jq)</pre>"
+    echo "        <pre>$(_ak_ipfs_cat $zblock | jq)</pre>"
     echo "    </details>"
     echo "            </td>"
     echo "        </tr>"
@@ -112,7 +113,7 @@ then
     echo "            <td>"
     echo "    <details>"
     echo "        <summary>$block</summary>"
-    echo "        <pre>$(ak-ipfs-cat $block | jq)</pre>"
+    echo "        <pre>$(_ak_ipfs_cat $block | jq)</pre>"
     echo "    </details>"
     echo "            </td>"
     echo "        </tr>"
@@ -123,7 +124,7 @@ then
     echo "            <td>"
     echo "    <details>"
     echo "        <summary>$block_signature</summary>"
-    echo "        <pre>$(ak-ipfs-cat $block_signature)</pre>"
+    echo "        <pre>$(_ak_ipfs_cat $block_signature)</pre>"
     echo "    </details>"
     echo "            </td>"
     echo "        </tr>"
@@ -158,7 +159,7 @@ then
     echo "            <td>"
     echo "    <details>"
     echo "        <summary>$gpg</summary>"
-    echo "        <pre>$(ak-ipfs-cat $gpg)</pre>"
+    echo "        <pre>$(_ak_ipfs_cat $gpg)</pre>"
     echo "    </details>"
     echo "            </td>"
     echo "        </tr>"
@@ -188,7 +189,7 @@ then
     echo "            <td>"
     echo "    <details>"
     echo "        <summary>$detach</summary>"
-    echo "        <pre>$(ak-ipfs-cat $detach)</pre>"
+    echo "        <pre>$(_ak_ipfs_cat $detach)</pre>"
     echo "    </details>"
     echo "            </td>"
     echo "        </tr>"
@@ -207,7 +208,7 @@ then
     echo "            <td>"
     echo "    <details>"
     echo "        <summary>$(echo $datablock | jq -r '.detach')</summary>"
-    echo "        <pre>$(ak-ipfs-cat $(echo $datablock | jq -r '.detach'))</pre>"
+    echo "        <pre>$(_ak_ipfs_cat $(echo $datablock | jq -r '.detach'))</pre>"
     echo "    </details>"
     echo "            </td>"
     echo "        </tr>"
diff --git a/bin/ak-zblock-manipulator b/bin/ak-zblock-manipulator
index cf67a6e..427ba09 100755
--- a/bin/ak-zblock-manipulator
+++ b/bin/ak-zblock-manipulator
@@ -17,6 +17,7 @@
 # Below, the usage information
 PROGRAM="$(basename $0)"
 source $AK_LIBDIR/_ak_logit
+source $AK_LIBDIR/_ak_ipfs
 source $AK_LIBDIR/_ak_gpg
 
 usage(){
@@ -47,22 +48,22 @@ main(){
 
 	logit "INFO" "We are doing" $BLOCK_TO_ADD "with content" $PREVIOUS
 	# We add it to IPFS
-	MESSAGE_HASH=$(ak-ipfs-add $MESSAGE)
+	MESSAGE_HASH=$(_ak_ipfs_add $MESSAGE)
 
 	# We create a detached and armor signature of it
 	MESSAGE_SIGN_FILE=$MESSAGE".asc"
 	_ak_gpg_sign_detached $MESSAGE_SIGN_FILE $MESSAGE
 
 	# We add the signature to IPFS
-	MESSAGE_SIGNATURE=$(ak-ipfs-add $MESSAGE_SIGN_FILE)
+	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"
     _ak_gpg_key_self_export $KEY
-	GPG_PUB_KEY=$(ak-ipfs-add $KEY)
+	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)
+	PREVIOUS=$(_ak_ipfs_files_stat /zlatest | head -n 1)
 
 	# We create a block of json like this:
 	cat > block <<EOF
@@ -83,10 +84,10 @@ makeZBlock(){
 	_ak_gpg_sign_detached $BLOCK_SIG $BLOCK
 
 	# We now add the signature to IPFS
-	BLOCK_SIGNATURE=$(ak-ipfs-add $BLOCK_SIG)
+	BLOCK_SIGNATURE=$(_ak_ipfs_add $BLOCK_SIG)
 
 	# We also add the block!
-	BLOCK=$(ak-ipfs-add $BLOCK)
+	BLOCK=$(_ak_ipfs_add $BLOCK)
 
 	# So we now do the think almost again
 	cat > zblock << EOF
@@ -97,7 +98,7 @@ makeZBlock(){
 EOF
 	ZBL="zblock"
 	# and we add it on IPFS
-	ZBLOCK=$(ak-ipfs-add $ZBL)
+	ZBLOCK=$(_ak_ipfs_add $ZBL)
 	echo $ZBLOCK
 }
 
@@ -110,11 +111,11 @@ then
 	# We ask for a ZBLOCK or GENESIS to put in the BLOCK
 	PREVIOUS="$2"
 
-	ak-ipfs-cat "$BLOCK_TO_ADD"
+	_ak_ipfs_cat "$BLOCK_TO_ADD"
 	if [ "$?" == 0 ];
 	then
 		echo "Nice! We found the block"
-		ak-ipfs-get "$BLOCK_TO_ADD"
+		_ak_ipfs_get "$BLOCK_TO_ADD"
 
 		sed -i.bak -e 's/^.*previous.*$/\"previous\":\"'$PREVIOUS'\"/' $BLOCK_TO_ADD
 		cat $BLOCK_TO_ADD | jq -M
@@ -130,11 +131,11 @@ then
 	# python send_as_ak_tx $ZBLOCK
 	# or for "offline" use
 	echo $ZBLOCK > $ZLATEST
-	ak-ipfs-name-publish --key=zchain $ZBLOCK > /dev/null 2>&1
-	ak-ipfs-files-mkdir /zarchive > /dev/null 2>&1
-	ak-ipfs-files-cp /zlatest /zarchive/$(date -u +%s)-$(ak-ipfs-files-stat /zlatest | head -n 1) > /dev/null 2>&1
-	ak-ipfs-files-rm /zlatest > /dev/null 2>&1
-	ak-ipfs-files-cp /ipfs/$ZBLOCK /zlatest > /dev/null 2>&1
+	_ak_ipfs_name_publish --key=zchain $ZBLOCK > /dev/null 2>&1
+	_ak_ipfs_files_mkdir /zarchive > /dev/null 2>&1
+	_ak_ipfs_files_cp /zlatest /zarchive/$(date -u +%s)-$(_ak_ipfs_files_stat /zlatest | head -n 1) > /dev/null 2>&1
+	_ak_ipfs_files_rm /zlatest > /dev/null 2>&1
+	_ak_ipfs_files_cp /ipfs/$ZBLOCK /zlatest > /dev/null 2>&1
 else
 	usage
 	exit 0
diff --git a/bin/ak-zblock-pack b/bin/ak-zblock-pack
index 4f635bf..f5b6505 100755
--- a/bin/ak-zblock-pack
+++ b/bin/ak-zblock-pack
@@ -54,22 +54,22 @@ main(){
 
 	logit "INFO" "We are doing $ACTION with content $MESSAGE"
 	# We add it to IPFS
-	MESSAGE_HASH=$(ak-ipfs-add $MESSAGE)
+	MESSAGE_HASH=$(_ak_ipfs_add $MESSAGE)
 
 	# We create a detached and armor signature of it
 	MESSAGE_SIGN_FILE=$MESSAGE".asc"
 	_ak_gpg_sign_detached $MESSAGE_SIGN_FILE $MESSAGE
 
 	# We add the signature to IPFS
-	MESSAGE_SIGNATURE=$(ak-ipfs-add $MESSAGE_SIGN_FILE)
+	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"
 	_ak_gpg_key_self_export $KEY
-	GPG_PUB_KEY=$(ak-ipfs-add $KEY)
+	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)
+	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
@@ -79,16 +79,16 @@ main(){
 	_ak_gpg_sign_detached $BLOCK_SIG $BLOCK
 
 	# We now add the signature to IPFS
-	BLOCK_SIGNATURE=$(ak-ipfs-add $BLOCK_SIG)
+	BLOCK_SIGNATURE=$(_ak_ipfs_add $BLOCK_SIG)
 
 	# We also add the block!
-	BLOCK=$(ak-ipfs-add $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)
+	ZBLOCK=$(_ak_ipfs_add $ZBL)
 	echo $ZBLOCK
 }
 
@@ -108,36 +108,36 @@ then
 	# 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
+	_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
+	_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
+        _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
+	_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
+	_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
+	_ak_ipfs_files_cp /ipfs/$ZBLOCK /zlatest > /dev/null 2>&1
     if [ "$?" -ne 0 ]
     then
         logit "ERROR" "Could not copy $ZBLOCK to /zlatest"
diff --git a/bin/ak-zchain-calculate-size b/bin/ak-zchain-calculate-size
index fe99187..51c4202 100755
--- a/bin/ak-zchain-calculate-size
+++ b/bin/ak-zchain-calculate-size
@@ -1,5 +1,6 @@
 #!/bin/bash
 PROGRAM="$(basename $0)"
+source $AK_LIBDIR/_ak_ipfs
 
 temp="$(mktemp -d)"
 
@@ -16,7 +17,7 @@ sum=0 ; while IFS="" read -r p || [ -n "$p" ]
 do
     if [ "$p" != "" ]
     then
-        ak-ipfs-get $p
+        _ak_ipfs_get $p
         num="$(du -bs --apparent-size $p | cut -d $'\t' -f 1)"
     else
         num=0
diff --git a/bin/ak-zchain-chk b/bin/ak-zchain-chk
index 02d8252..4e509ac 100755
--- a/bin/ak-zchain-chk
+++ b/bin/ak-zchain-chk
@@ -1,6 +1,7 @@
 #!/bin/bash
 PROGRAM="$(basename $0)"
 source $AK_LIBDIR/_ak_logit
+source $AK_LIBDIR/_ak_ipfs
 
 fix="0"
 usage(){
@@ -78,7 +79,7 @@ do
 
             # 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_ipfs_cat $zblock | ak-json2bash > tmp-zblock
             logit "INFO" "ZBLOCK $zblock READ"
 
             # Supposingly you are on a safe environment and you only have
@@ -90,7 +91,7 @@ do
 
             # Same as above applies to BLOCK and DATA subparts of each ZBLOCK
             # BLOCKS
-            ak-ipfs-cat $block | ak-json2bash > tmp-block
+            _ak_ipfs_cat $block | ak-json2bash > tmp-block
             source tmp-block
             logit "INFO" "BLOCK $block SOURCED"
             touch $AK_BLOCKDIR/$block
@@ -121,7 +122,7 @@ do
                     for value in ${blocks_found[@]}
                     do
                         echo $value
-                        ak-ipfs-cat $value | jq -M
+                        _ak_ipfs_cat $value | jq -M
                     done
                 fi
                 exit 0
diff --git a/bin/ak-zchain-rebase b/bin/ak-zchain-rebase
index a798fbe..f0687eb 100755
--- a/bin/ak-zchain-rebase
+++ b/bin/ak-zchain-rebase
@@ -1,5 +1,6 @@
 #!/bin/bash
 PROGRAM=$(basename $0)
+source $AK_LIBDIR/_ak_ipfs
 usage(){
     echo "$PROGRAM - Zchain rebase"
     echo ""
@@ -21,24 +22,24 @@ rebase (){
     if [ $? != 0 ]; then exit 1; fi
 
     echo "Make sure /zarchive folder exists within IPFS FS"
-    ak-ipfs-files-mkdir /zarchive
+    _ak_ipfs_files_mkdir /zarchive
     if [ $? != 0 ]; then echo "Folder already there"; fi
 
     echo "Archive the previous ZLATEST"
-    ak-ipfs-files-cp /zlatest /zarchive/$(date -u +%s)-$(ak-ipfs-files-stat /zlatest | head -n 1)
+    _ak_ipfs_files_cp /zlatest /zarchive/$(date -u +%s)-$(_ak_ipfs_files_stat /zlatest | head -n 1)
     if [ $? != 0 ]; then exit 1; fi
 
     echo "Removing previous /zlatest entry"
-    ak-ipfs-files-rm /zlatest
+    _ak_ipfs_files_rm /zlatest
     if [ $? != 0 ]; then exit 1; fi
 
     echo "Copying rebased ZLATEST"
     CZLATEST="$(cat $AK_ZLATEST)"
-    ak-ipfs-files-cp /ipfs/$CZLATEST /zlatest
+    _ak_ipfs_files_cp /ipfs/$CZLATEST /zlatest
     if [ $? != 0 ]; then exit 1; fi
 
     echo "Publishing new (rebased) ZLATEST"
-    ak-ipfs-name-publish --key=zchain /ipfs/$(cat $AK_ZLATEST)
+    _ak_ipfs_name_publish --key=zchain /ipfs/$(cat $AK_ZLATEST)
     if [ $? != 0 ]; then exit 1; fi
 
     ak-config publish
diff --git a/bin/ak-zchain-reset b/bin/ak-zchain-reset
index f19e1b0..b415c44 100755
--- a/bin/ak-zchain-reset
+++ b/bin/ak-zchain-reset
@@ -1,5 +1,7 @@
 #!/bin/bash
 PROGRAM=$(basename $0)
+source $AK_LIBDIR/_ak_ipfs
+
 usage(){
 	echo "$PROGRAM - Zchain reset"
 	echo ""
@@ -19,24 +21,24 @@ reset (){
 	if [ $? != 0 ]; then exit 1; fi
 
 	echo "Make sure /zarchive folder exists within IPFS FS"
-	ak-ipfs-files-mkdir /zarchive
+	_ak_ipfs_files_mkdir /zarchive
 	if [ $? != 0 ]; then echo "Folder already there"; fi
 
 	echo "Archive the previous ZLATEST"
-	ak-ipfs-files-cp /zlatest /zarchive/$(date -u +%s)-$(ak-ipfs-files-stat /zlatest | head -n 1)
+	_ak_ipfs_files_cp /zlatest /zarchive/$(date -u +%s)-$(_ak_ipfs_files_stat /zlatest | head -n 1)
 	if [ $? != 0 ]; then exit 1; fi
 
 	echo "Removing previous /zlatest entry"
-	ak-ipfs-files-rm /zlatest
+	_ak_ipfs_files_rm /zlatest
 	if [ $? != 0 ]; then exit 1; fi
 
 	echo "Copying reset ZLATEST"
 	CZLATEST="$(cat $ZLATEST)"
-	ak-ipfs-files-cp /ipfs/$CZLATEST /zlatest
+	_ak_ipfs_files_cp /ipfs/$CZLATEST /zlatest
 	if [ $? != 0 ]; then exit 1; fi
 
 	echo "Publishing new (reset) ZLATEST"
-	ak-ipfs-name-publish --key=zchain /ipfs/$(cat $ZLATEST)
+	_ak_ipfs_name_publish --key=zchain /ipfs/$(cat $ZLATEST)
 	if [ $? != 0 ]; then exit 1; fi
 
     ak-config publish
diff --git a/lib/_ak_ipfs b/lib/_ak_ipfs
new file mode 100755
index 0000000..4e7f846
--- /dev/null
+++ b/lib/_ak_ipfs
@@ -0,0 +1,283 @@
+#!/bin/bash
+source $AK_LIBDIR/_ak_logit
+IPFS_REPO="$AK_WORKDIR/ipfsrepo"
+
+_ak_ipfs(){
+    export IPFS_PATH=$IPFS_REPO; ipfs $*
+}
+
+_ak_ipfs_get_peers(){
+    _ak_ipfs swarm peers 1> /dev/null 2>&1
+    if [ $? == 0 ]
+    then
+        _ak_ipfs swarm peers > $AK_WORKDIR/peers.ipfs
+    fi
+}
+
+_ak_ipfs_scanner(){
+    peersIPFSfile="$AK_WORKDIR/peers.ipfs"
+    ak_peersIPFSfile="$AK_WORKDIR/ipfs.peers.akn"
+    if [ ! -f $peersIPFSfile ]
+    then
+        _ak_ipfs_get_peers
+        if [ $? -ne 0 ]
+        then
+            exit 1
+        fi
+    fi
+    counter=0
+
+    printf '[' > walk.aknet
+    cat $peersIPFSfile \
+        | cut -d '/' -f 2,3,7 \
+        | sort \
+        | uniq \
+        | while read -r line || [ -n "$line" ]
+    do
+        protocol="`printf '%s' "$line" | cut -d '/' -f 1`"
+        ip="`printf '%s' "$line" | cut -d '/' -f 2`"
+        ipfsId="`printf '%s' "$line" | cut -d '/' -f 3`"
+        if [ "$protocol" == "ip6" ]
+        then
+            url="http://[$ip]:8610/v0/node_info"
+        else
+            url="http://$ip:8610/v0/node_info"
+        fi
+        node_info="`curl \
+            -A 'akd/0.1.0; https://github.com/arching-kaos' \
+            --connect-timeout 3 \
+            "$url" 2>/dev/null`"
+        if [ $? -eq 0 ]
+        then
+            if [ "$counter" -ne "0" ]
+            then
+                printf ',' >> walk.aknet
+            fi
+            printf '{"ipfsPublicKey":"%s","ip":"%s","node_info":%s}' \
+                "$ipfsId" "$ip" "$node_info" >> walk.aknet
+            counter="`expr $counter + 1`"
+        fi
+    done
+    printf ']' >> walk.aknet
+
+    mv walk.aknet $ak_peersIPFSfile
+}
+
+_ak_ipfs_add(){
+    # Receives a file
+    # Returns a hash
+    _ak_ipfs add -Qr "$1"
+    if [ $? -ne 0 ]
+    then
+        logit "ERROR" "Failed to add $1"
+        exit 1
+    fi
+}
+
+_ak_ipfs_block_stat(){
+    _ak_ipfs block stat "$1"
+    if [ $? -ne 0 ]
+    then
+        logit "ERROR" "Failed to retrieve stat of block $1"
+        exit 1
+    fi
+}
+
+_ak_ipfs_cat(){
+    _ak_ipfs --timeout=10s cat $1
+    if [ "$?" -ne "0" ]
+    then
+        logit "ERROR" "Failed to cat $1"
+        exit 1
+    fi
+
+}
+
+_ak_ipfs_files_cp(){
+    _ak_ipfs files cp "$1" "$2"
+    if [ $? -ne 0 ]
+    then
+        logit "ERROR" "Failed to copy $1 to $2"
+        exit 1
+    fi
+}
+
+_ak_ipfs_files_ls(){
+    _ak_ipfs files ls "$1"
+    if [ $? -ne 0 ]
+    then
+        logit "ERROR" "Failed to list $1"
+        exit 1
+    fi
+}
+
+_ak_ipfs_files_mkdir(){
+    _ak_ipfs files mkdir "$1"
+    if [ $? -ne 0 ]
+    then
+        logit "ERROR" "Failed to mkdir $1"
+        exit 1
+    fi
+}
+
+_ak_ipfs_files_mv(){
+    _ak_ipfs files mv "$1" "$2"
+    if [ $? -ne 0 ]
+    then
+        logit "ERROR" "Failed to move $1 to $2"
+        exit 1
+    fi
+}
+
+_ak_ipfs_files_rm(){
+    _ak_ipfs files rm "$1"
+    if [ $? -ne 0 ]
+    then
+        logit "ERROR" "Failed to remove $1"
+        exit 1
+    fi
+}
+
+_ak_ipfs_files_stat(){
+    _ak_ipfs files stat "$1"
+    if [ $? -ne 0 ]
+    then
+        logit "ERROR" "Failed to get file's stats $1"
+        exit 1
+    fi
+}
+
+_ak_ipfs_get(){
+    _ak_ipfs --timeout=10s get "$1" > /dev/null 2>&1
+    if [ $? -ne 0 ]
+    then
+        logit "ERROR" "Failed to get $1"
+        exit 1
+    fi
+}
+
+_ak_ipfs_key_gen(){
+    _ak_ipfs key gen "$1"
+    if [ $? -ne 0 ]
+    then
+        logit "ERROR" "Failed to generate key $1"
+        exit 1
+    fi
+}
+
+_ak_ipfs_key_list(){
+    _ak_ipfs key list
+    if [ $? -ne 0 ]
+    then
+        logit "ERROR" "Failed to get key list"
+        exit 1
+    fi
+}
+
+_ak_ipfs_key_list_full(){
+    _ak_ipfs key list -l
+    if [ $? -ne 0 ]
+    then
+        logit "ERROR" "Failed to get key list"
+        exit 1
+    fi
+}
+
+_ak_ipfs_name_publish(){
+    _ak_ipfs name publish "$1" "$2"
+    if [ $? -ne 0 ]
+    then
+        logit "ERROR" "Failed to get $1"
+        exit 1
+    fi
+
+}
+
+_ak_ipfs_name_resolve(){
+    _ak_ipfs name resolve "$1"
+    if [ $? -ne 0 ]
+    then
+        logit "ERROR" "Failed to resolve $1"
+        exit 1
+    fi
+
+}
+
+_ak_ipfs_swarm_peers(){
+    _ak_ipfs swarm peers
+    if [ $? -ne 0 ]
+    then
+        logit "ERROR" "Failed to get list of peers"
+        exit 1
+    fi
+}
+
+_ak_ipfs_starter(){
+    _ak_ipfs daemon --routing=dht --migrate
+    if [ $? -ne 0 ]
+    then
+        logit "ERROR" "Failed to start IPFS daemon"
+        exit 1
+    fi
+}
+
+_ak_ipns_resolve(){
+    if [ ! -z $1 ]
+    then
+        rsld=$(ak-ipfs-name-resolve $1)
+        if [ "$?" != 0 ]
+        then
+            logit "ERROR" "Failed to resolve $1"
+            exit 1
+        fi
+        echo -n $rsld | sed -e 's/\/ipfs\///'
+        logit "INFO" "Resolved $1 to $rsld"
+    else
+        exit 69
+    fi
+}
+
+_ak_ipfs_check(){
+
+    _ak_ipfs_files_ls /zarchive > /dev/null
+    if [ $? != 0 ]
+    then
+        logit "ERROR" "/zarchive is missing"
+    else
+        logit "INFO" "/zarchive OK"
+    fi
+
+    _ak_ipfs_files_ls /zlatest > /dev/null
+    if [ $? != 0 ]
+    then
+        logit "ERROR" "/zlatest is missing"
+    else
+        logit "INFO" "/zlatest is OK"
+    fi
+
+    _ak_ipfs_key_list | grep zchain > /dev/null
+    if [ $? != 0 ]; then
+        logit "WARNING" "zchain key is missing"
+        _ak_ipfs_key_gen zchain > $ZCHAIN
+        if [ $? != 0 ]; then
+            logit "ERROR" "zchain fails to create"
+        else
+            logit "INFO" "zchain created"
+        fi
+    else
+        logit "INFO" "zchain is there"
+    fi
+
+    _ak_ipfs_key_list | grep ak-config > /dev/null
+    if [ $? != 0 ]; then
+        logit "WARNING" "ak-config key is missing"
+        _ak_ipfs_key_gen ak-config
+        if [ $? != 0 ]; then
+            logit "ERROR" "ak-config fails to create"
+        else
+            logit "INFO" "ak-config created"
+        fi
+    else
+        logit "INFO" "ak-config is there"
+    fi
+}
-- 
cgit v1.2.3