aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xbin/ak-articles4
-rwxr-xr-xbin/ak-categories45
-rwxr-xr-xbin/ak-comments18
-rwxr-xr-xbin/ak-enter17
-rwxr-xr-xbin/ak-files3
-rwxr-xr-xbin/ak-folders48
-rwxr-xr-xbin/ak-mixtapes4
-rwxr-xr-xbin/ak-news4
-rwxr-xr-xbin/ak-pack_z_block21
-rwxr-xr-xbin/ak-profile2
-rwxr-xr-xbin/ak-reference2
-rwxr-xr-xbin/ak-repositories9
-rwxr-xr-xbin/ak-sm-files50
-rwxr-xr-xbin/ak-tempassin4
-rwxr-xr-xbin/ak-todos2
-rwxr-xr-xbin/ak-transactions2
-rwxr-xr-xbin/ak-zblock-show256
-rwxr-xr-xbin/ak-zchain-chk11
18 files changed, 354 insertions, 148 deletions
diff --git a/bin/ak-articles b/bin/ak-articles
index e198712..9256d2a 100755
--- a/bin/ak-articles
+++ b/bin/ak-articles
@@ -72,7 +72,7 @@ import(){
fi
exit 224
}
-add()
+add(){
TEMP="$(ak-tempassin)"
cd $TEMP
if [ -f $1 ]; then
@@ -97,7 +97,7 @@ EOF
echo "File $FILE doesn't exist";
exit 2
fi
- ak-pack_z_block "articles/add" data
+ ak-pack_z_block "articles/add" $(pwd)/data
if [ $? == 0 ]
then
echo "Articles added successfully"
diff --git a/bin/ak-categories b/bin/ak-categories
index 45d11ff..d72453f 100755
--- a/bin/ak-categories
+++ b/bin/ak-categories
@@ -1,18 +1,14 @@
#!/bin/bash
-ZNEWSDIR="$AK_WORKDIR/news"
-TEMP="/tmp/aktmp"
-echo $ZNEWSDIR
-if [ ! -d $ZNEWSDIR ]; then
- mkdir $ZNEWSDIR
- cd $ZNEWSDIR
- git init
- echo "News repository" > README
- echo "Qmetc" >> README
- git add README
- git commit -m "Initiated news repository"
- echo "znewsdir created along with git repo"
+AK_CATEGORIES="$AK_WORKDIR/categories"
+PROGRAM="$(basename $0)"
+
+echo $AK_CATEGORIES
+if [ ! -d $AK_CATEGORIES ]; then
+ mkdir $AK_CATEGORIES
+ cd $AK_CATEGORIES
+ echo "AK_CATEGORIES created"
else
- echo "znewsdir found"
+ echo "AK_CATEGORIES found"
fi
create(){
@@ -24,31 +20,26 @@ create(){
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)
- mv $NEWS_FILE $ZNEWSDIR/$TO_FILE
- sed -e 's,Qm.*,'"$IPFS_FILE"',g' $ZNEWSDIR/README
- add $ZNEWSDIR/$TO_FILE
- echo "Adding to git repo..."
- cd $ZNEWSDIR
- git add $TO_FILE README
- git commit -m "Added $TO_FILE with $(head -n 1 $ZNEWSDIR/$TO_FILE)"
- git clean --force
- # rm -rf $TEMP
+ mv $NEWS_FILE $AK_CATEGORIES/$TO_FILE
+ sed -e 's,Qm.*,'"$IPFS_FILE"',g' $AK_CATEGORIES/README
+ add $AK_CATEGORIES/$TO_FILE
+ cd $AK_CATEGORIES
}
index(){
- FILES="$(ls -1 $ZNEWSDIR)"
+ FILES="$(ls -1 $AK_CATEGORIES)"
i=0
for FILE in $FILES
do
DATE=$(echo $FILE | cut -d - -f 1 | awk '{print $1}')
- TITLE=$(head -n 1 $ZNEWSDIR/$FILE)
+ TITLE=$(head -n 1 $AK_CATEGORIES/$FILE)
echo $i \| $DATE \| $TITLE
let i+=1
done
}
title(){
- echo ak-news-cli
- echo "--------------"
+ echo "$PROGRAM"
}
+
import(){
echo "#TODO"
if [ ! -z $1 ]
@@ -96,7 +87,7 @@ EOF
echo "File $FILE doesn't exist";
exit 2
fi
- ak-pack_z_block "news/add" data
+ ak-pack_z_block "news/add" $(pwd)/data
if [ $? == 0 ]
then
echo "News added successfully"
diff --git a/bin/ak-comments b/bin/ak-comments
index 7feb889..cd86a08 100755
--- a/bin/ak-comments
+++ b/bin/ak-comments
@@ -4,8 +4,7 @@ TEMP="/tmp/aktmp"
if [ ! -d $ZCOMMENTSDIR ]; then
mkdir $ZCOMMENTSDIR
cd $ZCOMMENTSDIR
- git init
- ak-logthis "[INFO]" "zcommentsdir created along with git repo"
+ ak-logthis "[INFO]" "zcommentsdir created"
else
ak-logthis "[INFO]" "zcommentsdir found"
fi
@@ -30,15 +29,12 @@ create(){
add $TO_FILE
ak-logthis "[INFO]" "Adding to git repo..."
cd $ZCOMMENTSDIR
- git add $TO_FILE
- git commit -m "Added $TO_FILE with $(head -n 1 $ZCOMMENTSDIR/$TO_FILE)"
- git clean --force
- # rm -rf $TEMP
if [ ! -z $REFER_TO ]
then
reference create $REFERENCE $REFER_TO
fi
}
+
index(){
FILES="$(ls -1 $ZCOMMENTSDIR)"
i=0
@@ -64,18 +60,12 @@ add(){
FILE_SIGN_FILE=$FILE".asc"
gpg --detach-sign --sign-with $FINGERPRINT --armor --output $FILE_SIGN_FILE $FILE
FILE_SIGNATURE=$(ak-ipfs-add $FILE_SIGN_FILE)
- cat > data <<EOF
-{
- "datetime":"$DATETIME",
- "ipfs":"$FILE_IPFS_HASH",
- "detach":"$FILE_SIGNATURE"
-}
-EOF
+ printf '{"datetime":"%s","ipfs":"%s","detach":"%s"}' $DATETIME $FILE_IPFS_HASH $FILE_SIGNATURE > data
else
echo "File $FILE doesn't exist";
exit 2
fi
- REFERENCE="$(ak-pack_z_block "comments/add" data)"
+ REFERENCE="$(ak-pack_z_block "comments/add" $(pwd)/data)"
if [ $? == 0 ]
then
echo "Comment added successfully"
diff --git a/bin/ak-enter b/bin/ak-enter
index dd65dcf..45fcace 100755
--- a/bin/ak-enter
+++ b/bin/ak-enter
@@ -75,8 +75,7 @@ seed="$(cat $AK_ZGENESIS)"
zblock="$entrance"
# Enter temp folder
-TEMPASSIN="/tmp/aktmp_$(date -u +%s)"
-mkdir $TEMPASSIN
+TEMPASSIN="$(ak-tempassin)"
cd $TEMPASSIN
counter=0
# The loop
@@ -123,12 +122,12 @@ do
logit "[INFO]" "ZBLOCK $zblock is JSON"
# Then we pass it through the filter and save it
- ak-ipfs-cat $zblock | ak-json2bash > $TEMPASSIN/tmp-zblock
+ ak-ipfs-cat $zblock | ak-json2bash > tmp-zblock
# Be sure that there are the expected values
# We need 'block' and 'block_signature' inside a 'zblock'
# Exit if any is missing
- grep -e 'block_signature' $TEMPASSIN/tmp-zblock > /dev/null 2>&1
+ grep -e 'block_signature' tmp-zblock > /dev/null 2>&1
if [ "$?" -ne 0 ]
then
logit "[ERROR]" "ZBLOCK $zblock doesn't contain a block_signature"
@@ -136,7 +135,7 @@ do
fi
logit "[INFO]" "ZBLOCK $zblock contains a block_signature"
- grep -e 'block=' $TEMPASSIN/tmp-zblock > /dev/null 2>&1
+ grep -e 'block=' tmp-zblock > /dev/null 2>&1
if [ "$?" -ne 0 ]
then
logit "[ERROR]" "ZBLOCK $zblock has no block"
@@ -153,20 +152,20 @@ do
# access to your chain, I would consider mild secure to source
# the files into your bash.
# File an issue/pull request if you think it can be done better!!
- source $TEMPASSIN/tmp-zblock
+ source tmp-zblock
logit "[INFO]" "ZBLOCK SOURCED"
# Same as above applies to BLOCK and DATA subparts of each ZBLOCK
# BLOCKS
echo -n '"block":"'$block'",'
- ak-ipfs-cat $block | ak-json2bash > $TEMPASSIN/tmp-block
+ ak-ipfs-cat $block | ak-json2bash > tmp-block
if [ "$?" -ne 0 ]
then
logit "[ERROR]" "BLOCK $block READ failed"
exit 1
fi
- grep -e 'timestamp' -e 'gpg' -e 'data' -e 'action' -e 'detach' -e 'previous' $TEMPASSIN/tmp-block > /dev/null 2>&1
+ grep -e 'timestamp' -e 'gpg' -e 'data' -e 'action' -e 'detach' -e 'previous' tmp-block > /dev/null 2>&1
if [ "$?" -ne 0 ]
then
logit "[ERROR]" "BLOCK $block is NOT a valid block"
@@ -174,7 +173,7 @@ do
fi
logit "[INFO]" "BLOCK $block is a block"
- source $TEMPASSIN/tmp-block
+ source tmp-block
logit "[INFO]" "BLOCK $block SOURCED"
touch $BLOCKDIR/$block
logit "[INFO]" "BLOCK REFERENCED"
diff --git a/bin/ak-files b/bin/ak-files
index 92c7e17..fe0d279 100755
--- a/bin/ak-files
+++ b/bin/ak-files
@@ -1,6 +1,5 @@
#!/bin/bash
# The following creates a mixtape data message
-# We can extend it by calling the ak-pack_z_block.sh mixtape/add data
ZFILESDIR="$AK_WORKDIR/files"
TEMP="/tmp/aktmp"
PROGRAM="$(basename $0)"
@@ -92,7 +91,7 @@ echo "Printing data..."
cat $TEMPASSIN/data
echo "Publishing..."
- ak-pack_z_block files/add data
+ ak-pack_z_block files/add $PWD/data
if [ $? == 0 ]
then
echo "cool"
diff --git a/bin/ak-folders b/bin/ak-folders
index b30f401..3654b67 100755
--- a/bin/ak-folders
+++ b/bin/ak-folders
@@ -1,15 +1,15 @@
#!/bin/bash
# The following creates a mixtape data message
-# We can extend it by calling the ak-pack_z_block.sh mixtape/add data
ZFOLDERSDIR="$AK_WORKDIR/folders"
TEMP="/tmp/aktmp"
if [ ! -d $ZFOLDERSDIR ]; then
mkdir $ZFOLDERSDIR
cd $ZFOLDERSDIR
- git init
else
ak-logthis "error $ZFOLDERSDIR not found"
fi
+TEMPASSIN="$(ak-tempassin)"
+cd $TEMPASSIN
usage(){
title
@@ -20,30 +20,22 @@ add(){
CRP="$(pwd)"
FOLDERNAME="$1"
main $FOLDERNAME $CRP
- cat $TEMPASSIN/data | jq -M
+ cat data | jq -M
}
+
main(){
FOLDERNAME="$1"
CRP="$2"
echo "Adding $FOLDERNAME"
- ak-logthis "Switching to tmp folder..."
- TEMPASSIN="$(ak-tempassin)"
- cd $TEMPASSIN
- if [ $? == 0 ]; then
- ak-logthis "Success"
- else
- ak-logthis "Error with tmp folder"
- exit 5
- fi
- ak-logthis "Copying $1 to $TEMPASSIN"
- cp -r $2/$1 $TEMPASSIN/$1
+ ak-logthis "Copying $1 to temporary folder"
+ cp -r $2/$1 $1
if [ $? == 0 ]; then
ak-logthis "Copied successfully"
else
ak-logthis "Error copying..."
fi
- FOLDER="$TEMPASSIN/$1"
+ FOLDER="$1"
ak-logthis "Adding $FOLDER to IPFS..."
FOLDER_IPFS_HASH=$(ak-ipfs-add $FOLDER)
@@ -64,26 +56,27 @@ main(){
# fi
#
# ak-logthis "Adding signature to IPFS"
-# SIGNATURE=$(ak-ipfs-add $TEMPASSIN/$SIGN_FOLDER)
+# SIGNATURE=$(ak-ipfs-add $SIGN_FOLDER)
# if [ $? == 0 ]; then
# ak-logthis "Added"
# else
# ak-logthis "Error while adding"
# fi
- cat > $TEMPASSIN/data <<EOF
-{
- "timestamp":"$(date -u +%s)",
- "foldername":"$FOLDERNAME",
- "ipfs":"$FOLDER_IPFS_HASH"
-}
-EOF
+# cat > data <<EOF
+# {
+# "timestamp":"$(date -u +%s)",
+# "foldername":"$FOLDERNAME",
+# "ipfs":"$FOLDER_IPFS_HASH"
+# }
+# EOF
+ printf '{"timestamp":"%s","foldername":"%s","ipfs":"%s"}' $(date -u +%s) $FOLDERNAME $FOLDER_IPFS_HASH
-echo "Printing data..."
-cat $TEMPASSIN/data
-echo "Publishing..."
+ echo "Printing data..."
+ cat data
+ echo "Publishing..."
- ak-pack_z_block folders/add data
+ ak-pack_z_block folders/add $(pwd)/data
if [ $? == 0 ]
then
echo "cool"
@@ -95,7 +88,6 @@ echo "Publishing..."
title(){
echo "Folder block creator"
- echo "===================="
}
diff --git a/bin/ak-mixtapes b/bin/ak-mixtapes
index c78a709..93ba01b 100755
--- a/bin/ak-mixtapes
+++ b/bin/ak-mixtapes
@@ -1,6 +1,6 @@
#!/bin/bash
# The following creates a mixtape data message
-# We can extend it by calling the ak-pack_z_block.sh mixtape/add data
+# We can extend it by calling the ak-pack_z_block.sh mixtape/add data ## ORIGINAL LINE
usage(){
title
@@ -43,6 +43,6 @@ then
MIXTAPE_FILE="$PWD/$3"
main
cat $PWD/data | jq -M
- # sh ak-pack_z_block.sh mixtape/add $PWD/data
+ ak-pack_z_block mixtape/add $PWD/data
else usage
fi
diff --git a/bin/ak-news b/bin/ak-news
index 812ef34..1c0a440 100755
--- a/bin/ak-news
+++ b/bin/ak-news
@@ -105,7 +105,7 @@ EOF
echo "File $FILE doesn't exist";
exit 2
fi
- ak-pack_z_block "news/add" data
+ ak-pack_z_block "news/add" $(pwd)/data
if [ $? == 0 ]
then
echo "News added successfully"
@@ -139,7 +139,7 @@ EOF
echo "File $FILE doesn't exist";
exit 2
fi
- ak-pack_z_block "news/add" data
+ ak-pack_z_block "news/add" $(pwd)/data
if [ $? == 0 ]
then
echo "News added successfully"
diff --git a/bin/ak-pack_z_block b/bin/ak-pack_z_block
index 76e87df..7465897 100755
--- a/bin/ak-pack_z_block
+++ b/bin/ak-pack_z_block
@@ -74,16 +74,7 @@ main(){
PREVIOUS=$(ak-ipfs-files-stat /zlatest | head -n 1)
# We create a block of json like this:
- cat > block <<EOF
-{
- "timestamp":"$(date -u +%s)",
- "action":"$ACTION",
- "data":"$MESSAGE_HASH",
- "detach":"$MESSAGE_SIGNATURE",
- "gpg":"$GPG_PUB_KEY",
- "previous":"$PREVIOUS"
-}
-EOF
+ 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
BLOCK="block"
BLOCK_SIG=$BLOCK".asc"
# We have a block now, so we sign it
@@ -96,12 +87,7 @@ EOF
BLOCK=$(ak-ipfs-add $BLOCK)
# So we now do the think almost again
- cat > zblock << EOF
-{
- "block":"$BLOCK",
- "block_signature":"$BLOCK_SIGNATURE"
-}
-EOF
+ printf '{"block":"%s","block_signature":"%s"}' $BLOCK $BLOCK_SIGNATURE > zblock
ZBL="zblock"
# and we add it on IPFS
ZBLOCK=$(ak-ipfs-add $ZBL)
@@ -110,8 +96,7 @@ EOF
if [ ! -z $2 ];
then
- PWD="$(pwd)"
- MESSAGE="$PWD/$2"
+ MESSAGE="$2"
ACTION="$1"
if [ -f "$MESSAGE" ]; then
main
diff --git a/bin/ak-profile b/bin/ak-profile
index 0b08fe3..17cf399 100755
--- a/bin/ak-profile
+++ b/bin/ak-profile
@@ -170,7 +170,7 @@ EOF
exit 2
fi
- ak-pack_z_block "profile/add" data
+ ak-pack_z_block "profile/add" $(pwd)/data
if [ "$?" -ne 0 ]
then
echo "error??"
diff --git a/bin/ak-reference b/bin/ak-reference
index 2484ba0..4c41005 100755
--- a/bin/ak-reference
+++ b/bin/ak-reference
@@ -108,7 +108,7 @@ EOF
echo "File $FILE doesn't exist";
exit 2
fi
- ak-pack_z_block "references/add" data
+ ak-pack_z_block "references/add" $(pwd)/data
if [ $? == 0 ]
then
echo "References added successfully"
diff --git a/bin/ak-repositories b/bin/ak-repositories
index 7d3bf5a..132d758 100755
--- a/bin/ak-repositories
+++ b/bin/ak-repositories
@@ -106,13 +106,8 @@ add(){
if [ $? == 0 ]
then
ak-ipfs-name-publish --key="$PROJECT.git" /ipfs/$IPFS
- cat > data <<EOF
-{
- "project":"$PROJECT.git",
- "ipns":"$try"
-}
-EOF
- ak-pack_z_block "repos/add" data
+ printf '{"project":"%s.git","ipns":"%s"}' $PROJECT $try > data
+ ak-pack_z_block "repos/add" $PWD/data
echo "Done"
fi
fi
diff --git a/bin/ak-sm-files b/bin/ak-sm-files
index 6aaea26..d937763 100755
--- a/bin/ak-sm-files
+++ b/bin/ak-sm-files
@@ -1,7 +1,7 @@
#!/bin/bash
-# The following creates a mixtape data message
-# We can extend it by calling the ak-pack_z_block.sh mixtape/add data
ZFILESDIR="$AK_WORKDIR/files"
+pwd > .pwd
+CRD=$(cat .pwd)
PROGRAM="$(basename $0)"
#set -xe
@@ -26,22 +26,24 @@ usage(){
echo "$PROGRAM - file"
echo " add <file>"
echo " index"
+ echo " full-index"
+ echo " ls-map-files"
}
add(){
- CRP="$(pwd)"
FILENAME="$1"
- main $FILENAME $CRP
- cat $TEMPASSIN/data | jq -M
+ main $FILENAME $CRD
+ cat data | jq -M
}
main(){
FILENAME="$1"
CRP="$2"
- echo "Adding $FILENAME"
- logit "[INFO]" "Switching to tmp folder..."
- TEMPASSIN="$(ak-tempassin)"
+ TEMPASSIN="$(ak-tempassin)"
cd $TEMPASSIN
+
+ echo "Adding $FILENAME"
+ logit "[INFO]" "Switching to tmp folder..."
if [ $? == 0 ]; then
logit "[INFO]" "Success"
else
@@ -50,34 +52,32 @@ main(){
fi
logit "[INFO]" "Copying $1 to $TEMPASSIN"
- cp $2/$1 $TEMPASSIN/$1
+ cp $CRP/$FILENAME $FILENAME
if [ $? == 0 ]; then
logit "[INFO]" "Copied successfully"
else
logit "[ERROR]" "Error copying..."
fi
- FILE="$TEMPASSIN/$1"
-
- logit "[INFO]" "Adding $FILE to IPFS..."
- FILE_IPFS_HASH=$(ak-ipfs-add $FILE)
+ logit "[INFO]" "Adding $FILENAME to IPFS..."
+ FILE_IPFS_HASH=$(ak-ipfs-add $FILENAME)
if [ $? == 0 ]; then
- logit "[INFO]" "Added $FILE to IPFS"
+ logit "[INFO]" "Added $FILENAME to IPFS"
else
- logit "[ERROR]" "Error in adding the $FILE to IPFS"
+ logit "[ERROR]" "Error in adding the $FILENAME to IPFS"
fi
logit "[INFO]" "Adding $FILE to SHAMAPSYS..."
- FILEMAP_SHA512_HASH=$(ak-sm-filesplitter $FILE)
+ FILEMAP_SHA512_HASH=$(ak-sm-filesplitter $FILENAME)
if [ $? == 0 ]; then
- logit "[INFO]" "Added $FILE to SHAMAPSYS"
+ logit "[INFO]" "Added $FILENAME to SHAMAPSYS"
else
- logit "[ERROR]" "Error in adding the $FILE to SHAMAPSYS"
+ logit "[ERROR]" "Error in adding the $FILENAME to SHAMAPSYS"
fi
logit "[INFO]" "Signing..."
SIGN_FILE=$FILENAME".asc"
- gpg2 --detach-sign --sign-with $FINGERPRINT --armor --output $SIGN_FILE $FILE
+ gpg2 --detach-sign --sign-with $FINGERPRINT --armor --output $SIGN_FILE $FILENAME
if [ $? == 0 ]; then
logit "[INFO]" "Signed"
else
@@ -85,7 +85,7 @@ main(){
fi
logit "[INFO]" "Adding signature to IPFS"
- SIGNATURE=$(ak-ipfs-add $TEMPASSIN/$SIGN_FILE)
+ SIGNATURE=$(ak-ipfs-add $SIGN_FILE)
if [ $? == 0 ]; then
logit "[INFO]" "Added"
else
@@ -93,29 +93,29 @@ main(){
fi
logit "[INFO]" "Adding signature to SHAMAPSYS"
- SHAMAPSIGMAP=$(ak-sm-filesplitter $TEMPASSIN/$SIGN_FILE)
+ SHAMAPSIGMAP=$(ak-sm-filesplitter $SIGN_FILE)
if [ $? == 0 ]; then
logit "[INFO]" "Added"
else
logit "[ERROR]" "Error while adding"
fi
- cat > $TEMPASSIN/data <<EOF
+ cat > data <<EOF
{
"timestamp":"$(date -u +%s)",
"filename":"$FILENAME",
"shamap":"$FILEMAP_SHA512_HASH",
- "shamapsigmap":"$SHAMAPSIGMAP",
+ "shamapsig":"$SHAMAPSIGMAP",
"ipfs":"$FILE_IPFS_HASH",
"detach":"$SIGNATURE"
}
EOF
echo "Printing data..."
- cat $TEMPASSIN/data
+ cat data
echo "Publishing..."
- ak-pack_z_block sha-files/announce data
+ ak-pack_z_block sha-files/announce $(pwd)/data
if [ $? == 0 ]
then
echo "cool"
diff --git a/bin/ak-tempassin b/bin/ak-tempassin
index bc649c5..acf32dd 100755
--- a/bin/ak-tempassin
+++ b/bin/ak-tempassin
@@ -1,7 +1,7 @@
#!/bin/bash
-AK_TEMP="mktemp -d aktmp-XXXXXXX"
+AK_TEMP="$(mktemp -d aktmp-XXXXXXX)"
logit(){
- ak-logthis <"$PROGRAM"> "$1" "$2"
+ ak-logthis "<$PROGRAM>" "$1" "$2"
}
if [ ! -d "$AK_TEMP" ]
then
diff --git a/bin/ak-todos b/bin/ak-todos
index 46b9021..be2fd86 100755
--- a/bin/ak-todos
+++ b/bin/ak-todos
@@ -95,7 +95,7 @@ EOF
echo "File $FILE doesn't exist";
exit 2
fi
- ak-pack_z_block "todos/add" data
+ ak-pack_z_block "todos/add" $(pwd)/data
if [ $? == 0 ]
then
ak-logthis "Todos added successfully"
diff --git a/bin/ak-transactions b/bin/ak-transactions
index 5c1cf4c..c100774 100755
--- a/bin/ak-transactions
+++ b/bin/ak-transactions
@@ -45,6 +45,6 @@ then
AMOUNT="$3"
main
cat $PWD/data | jq -M
- # sh ak-pack_z_block.sh mixtape/add $PWD/data
+ ak-pack_z_block transaction/add $PWD/data
else usage
fi
diff --git a/bin/ak-zblock-show b/bin/ak-zblock-show
new file mode 100755
index 0000000..886490b
--- /dev/null
+++ b/bin/ak-zblock-show
@@ -0,0 +1,256 @@
+#!/bin/bash
+# ak-enter
+#
+# Using this tool, we can seek a whole zchain, if available from
+# an IPFS CID or an IPNS link.
+#
+# Default (no arguments) will retrieve the local ZCHAIN starting
+# from the IPFS CID stored in the file that is tracked by the
+# $AK_ZLATEST environment variable.
+#
+# ak-enter [-n IPNS_LINK]
+# ak-enter [IPFS CID]
+# ak-enter -nV
+# ak-enter
+#
+# Returns a JSON array representing the chain retrieved.
+# Logs messages to $LOGSFILE.
+
+PROGRAM="$(basename $0)"
+
+logit(){
+ ak-logthis "<$PROGRAM>" "$1" "$2"
+}
+
+usage(){
+ echo "$PROGRAM - Show a zblock"
+ echo "-----------------------------------"
+ echo ""
+ echo "$PROGRAM <zblock_hash>"
+ echo "Usage:"
+ echo " --help, -h Print this help and exit"
+}
+# Start of tests
+#entrance="QmW5WVXCJfhb4peHG6cbEdamC24vZzMX2Vz386vpENh38U"
+#entrance="QmNjQq7GkuXGF8kFT1z2Mv3i4JhY7sBXVUmHDiR1zkQjoE"
+#entrance="QmbFMke1KXqnYyBBWxB74N4c5SBnJMVAiMNRcGu6x1AwQH"
+# End of tests
+verify=1
+if [ ! -z "$1" ] && [ "$1" == "-h" ] || [ "$1" == "--help" ]
+then
+ usage
+ exit
+elif [ ! -z "$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
+ entrance="$1"
+else
+ # By default we ak-enter from the latest block
+ # We can alter this by changing this value
+ entrance="$(cat $AK_ZLATEST)"
+fi
+# We assign the IPFS CIDv0 of an empty file as this is used
+# as our GENESIS block, hence the "seed" that the tree grows
+# from.
+seed="$(cat $AK_ZGENESIS)"
+
+# We assume that we found the entrance inside a block, hence
+# ZBLOCK is labeled as previous
+zblock="$entrance"
+
+# Enter temp folder
+TEMPASSIN="$(ak-tempassin)"
+cd "$TEMPASSIN"
+
+counter=0
+# The loop
+# We break the loop from inside the loop
+#while true
+#do
+# if [ $counter == 0 ]
+# then
+# echo -n '['
+# fi
+ counter=$(expr $counter + 1)
+ # Check if $zblock exists as variable
+ if [ ! -v $zblock ]
+ then
+ # Check if it is not our seed cause if it is we skip this part
+ if [ "$zblock" != "$seed" ]
+ then
+ # Reset timestamp since it's introduced later
+ timestamp=''
+ # Announce to logs which ZBLOCK is being read at the moment
+ logit "[INFO]" "Examining $zblock"
+ echo -n '{"zblock":"'$zblock'",'
+
+ # We concatenate the zblock's contents, pipe
+ # them through filter ak-json2bash and output
+ # them to tmp-file
+ #
+ # We check if any $zblock at all
+ ak-ipfs-cat $zblock > /dev/null 2>&1
+ if [ "$?" -ne 0 ]
+ then
+ logit "[ERROR]" "ZBLOCK $zblock READ failed"
+ exit 1
+ fi
+ logit "[INFO]" "ZBLOCK $zblock READ"
+
+ # If it's JSON formated
+ ak-ipfs-cat $zblock | jq -M > /dev/null 2>&1
+ if [ "$?" -ne 0 ]
+ then
+ logit "[ERROR]" "ZBLOCK $zblock is not JSON"
+ exit 1
+ fi
+ logit "[INFO]" "ZBLOCK $zblock is JSON"
+
+ # Then we pass it through the filter and save it
+ ak-ipfs-cat $zblock | ak-json2bash > tmp-zblock
+
+ # Be sure that there are the expected values
+ # We need 'block' and 'block_signature' inside a 'zblock'
+ # Exit if any is missing
+ grep -e 'block_signature' tmp-zblock > /dev/null 2>&1
+ if [ "$?" -ne 0 ]
+ then
+ logit "[ERROR]" "ZBLOCK $zblock doesn't contain a block_signature"
+ exit 1
+ fi
+ logit "[INFO]" "ZBLOCK $zblock contains a block_signature"
+
+ grep -e 'block=' tmp-zblock > /dev/null 2>&1
+ if [ "$?" -ne 0 ]
+ then
+ logit "[ERROR]" "ZBLOCK $zblock has no block"
+ exit 1
+ fi
+ logit "[INFO]" "ZBLOCK $zblock has block"
+
+ # We create files named after each ZBLOCK IPFS CID for later
+ # reference. Files are empty.
+ touch $ZBLOCKDIR/$zblock
+ logit "[INFO]" "Created reference"
+
+ # Supposingly you are on a safe environment and you only have
+ # access to your chain, I would consider mild secure to source
+ # the files into your bash.
+ # File an issue/pull request if you think it can be done better!!
+ source tmp-zblock
+ logit "[INFO]" "ZBLOCK SOURCED"
+
+ # Same as above applies to BLOCK and DATA subparts of each ZBLOCK
+ # BLOCKS
+ echo -n '"block":"'$block'",'
+ ak-ipfs-cat $block | ak-json2bash > tmp-block
+ if [ "$?" -ne 0 ]
+ then
+ logit "[ERROR]" "BLOCK $block READ failed"
+ exit 1
+ fi
+
+ grep -e 'timestamp' -e 'gpg' -e 'data' -e 'action' -e 'detach' -e 'previous' tmp-block > /dev/null 2>&1
+ if [ "$?" -ne 0 ]
+ then
+ logit "[ERROR]" "BLOCK $block is NOT a valid block"
+ exit 1
+ fi
+ logit "[INFO]" "BLOCK $block is a block"
+
+ source tmp-block
+ logit "[INFO]" "BLOCK $block SOURCED"
+ touch $BLOCKDIR/$block
+ logit "[INFO]" "BLOCK REFERENCED"
+ module="$(echo $action | sed -e 's/\// /g' | awk '{ print $1 }')"
+ logit "[INFO]" "DATA is $module module."
+ command="$(echo $action | sed -e 's/\// /g' | awk '{ print $2 }')"
+ logit "[INFO]" "COMMAND is $command"
+ if [ ! -v $timestamp ]
+ then
+ echo -n '"timestamp":"'$timestamp'",'
+ fi
+ echo -n '"block_signature":"'$block_signature'",'
+ echo -n '"detach":"'$detach'",'
+ echo -n '"module":"'$module'",'
+ echo -n '"action":"'$command'",'
+ echo -n '"gpg":"'$gpg'",'
+ if [ $verify == 1 ]
+ then
+ ak-ipfs-get $gpg > /dev/null 2>&1
+ if [ "$?" -ne 0 ]
+ then
+ logit "[ERROR]" "Could not get GPG key: $gpg ."
+ exit 1
+ fi
+ gpg2 --import $gpg > /dev/null 2>&1
+ if [ "$?" -ne 0 ]
+ then
+ logit "[ERROR]" "Could not import GPG key: $gpg ."
+ exit 1
+ fi
+ ak-ipfs-get $block_signature > /dev/null 2>&1
+ if [ "$?" -ne 0 ]
+ then
+ logit "[ERROR]" "Error while getting $block_signature for $block"
+ exit 1
+ fi
+ mv $block_signature $block.asc
+ logit "[INFO]" "Block signature downloaded"
+ ak-ipfs-get $block > /dev/null 2>&1
+ if [ "$?" -ne 0 ]
+ then
+ logit "[ERROR]" "Could not get $block block"
+ exit 1
+ fi
+ logit "[INFO]" "Downloaded block $block."
+ gpg2 --verify $block.asc > /dev/null 2>&1
+ if [ "$?" -ne 0 ]
+ then
+ logit "[ERROR]" "Could not verify $block with GPG key $gpg."
+ exit 1
+ fi
+ logit "[GPG]" "$gpg signature of $block is verified."
+ fi
+ ak-data-expand $data $gpg
+
+ if [ "$?" -ne 0 ]
+ then
+ logit "[ERROR]" "Failed on data signature verification [data: $data, gpg: $gpg, zblock: $zblock]"
+ exit 1
+ fi
+
+ # DATA (but we don't source it's stuff)
+ # Only print to stdout
+ #ak-ipfs-cat $data
+ touch $DATADIR/$data
+
+ # Now, since we sourced the BLOCK to our terminal, we can search
+ # for $previous variable. In case we don't find one, we append one
+ # and we exit.
+ if [ -v $previous ]
+ then
+ logit "[WARNING]" "Block $block has no previous zblock, appending pseudo genesis to exit gracefully."
+ echo -n '"previous":"genesis"},{"genesis":"genesis"}]'
+ logit "[INFO]" "Reached pseudo-genesis, counted $counter zblocks."
+ exit 0
+
+ # Otherwise, we inform of the sequence
+ else
+ logit "[INFO]" "Found a previous block for $zblock: $previous"
+ echo -n '"previous":"'$previous'"}'
+ fi
+
+ exit 0
+ fi
+ # And finally, if nothing is there exit with error
+ else
+ echo "Check not passed... No previous IPFS CID"
+ exit 1
+ fi
+#done
diff --git a/bin/ak-zchain-chk b/bin/ak-zchain-chk
index 946919a..c5a97cf 100755
--- a/bin/ak-zchain-chk
+++ b/bin/ak-zchain-chk
@@ -43,8 +43,7 @@ zblock="$entrance"
declare -A blocks_found
# Enter temp folder
-TEMPASSIN="/tmp/aktmp_$(date -u +%s)"
-mkdir $TEMPASSIN
+TEMPASSIN="$(ak-tempassin)"
cd $TEMPASSIN
counter=0
@@ -76,20 +75,20 @@ do
# We concatenate the zblock's contents, pipe them through filter
# ak-json2bash and output them to tmp-file
- ak-ipfs-cat $zblo