From 9606644a0beb4f2883e1e0f4c6c81b42ab40b3a1 Mon Sep 17 00:00:00 2001 From: kaotisk Date: Mon, 3 Apr 2023 00:24:49 +0300 Subject: Renaming to prefix convention, introduced ipfs wrappers so it can be easier to maintain, changes in filesplitter and filejoiner as they move sm submodule namespace... like there are namespaces in bash or something --- bin/ak-articles | 8 +- bin/ak-calculate-size | 2 +- bin/ak-categories | 8 +- bin/ak-comments | 8 +- bin/ak-config | 6 +- bin/ak-data-expand | 20 +-- bin/ak-enter | 28 ++-- bin/ak-extract-cids | 6 +- bin/ak-filejoiner | 78 ----------- bin/ak-files | 8 +- bin/ak-filesplitter | 136 ------------------ bin/ak-folders | 8 +- bin/ak-follow | 2 +- bin/ak-get-akid | 2 +- bin/ak-get-chain-minified | 2 +- bin/ak-get-ipfs-hashes-from-my-zchain | 2 +- bin/ak-get-latest | 2 +- ...k-get-only-ipfs-key-values-from-our-or-a-zchain | 4 +- bin/ak-get-only-ipfs-key-values-from-our-zchain | 2 +- bin/ak-ipfs-add | 3 + bin/ak-ipfs-block-stat | 3 + bin/ak-ipfs-cat | 2 + bin/ak-ipfs-check | 12 +- bin/ak-ipfs-files-cp | 3 + bin/ak-ipfs-files-ls | 3 + bin/ak-ipfs-files-mkdir | 3 + bin/ak-ipfs-files-mv | 0 bin/ak-ipfs-files-rm | 3 + bin/ak-ipfs-files-stat | 3 + bin/ak-ipfs-get | 3 + bin/ak-ipfs-key-gen | 2 + bin/ak-ipfs-key-list | 1 + bin/ak-ipfs-key-list-full | 2 + bin/ak-ipfs-name-publish | 3 + bin/ak-ipfs-name-resolve | 3 + bin/ak-ipfs-swarm-peers | 1 + bin/ak-ipns-resolve | 2 +- bin/ak-json2bash | 2 +- bin/ak-mempool | 4 +- bin/ak-miner-script | 2 +- bin/ak-mixtapes | 8 +- bin/ak-news | 54 +++---- bin/ak-pack_z_block | 29 ++-- bin/ak-profile | 10 +- bin/ak-reference | 8 +- bin/ak-repositories | 26 ++-- bin/ak-sm-filejoiner | 90 ++++++++++++ bin/ak-sm-files | 156 +++++++++++++++++++++ bin/ak-sm-filesplitter | 136 ++++++++++++++++++ bin/ak-todos | 8 +- bin/ak-transactions | 6 +- bin/ak-unfollow | 2 +- bin/ak-zblock-manipulator | 28 ++-- bin/ak-zchain-chk | 8 +- bin/ak-zchain-rebase | 10 +- bin/ak-zchain-reset | 10 +- 56 files changed, 597 insertions(+), 384 deletions(-) delete mode 100755 bin/ak-filejoiner delete mode 100755 bin/ak-filesplitter create mode 100755 bin/ak-ipfs-add create mode 100755 bin/ak-ipfs-block-stat create mode 100755 bin/ak-ipfs-cat create mode 100755 bin/ak-ipfs-files-cp create mode 100755 bin/ak-ipfs-files-ls create mode 100755 bin/ak-ipfs-files-mkdir create mode 100755 bin/ak-ipfs-files-mv create mode 100755 bin/ak-ipfs-files-rm create mode 100755 bin/ak-ipfs-files-stat create mode 100755 bin/ak-ipfs-get create mode 100755 bin/ak-ipfs-key-gen create mode 100755 bin/ak-ipfs-key-list create mode 100755 bin/ak-ipfs-key-list-full create mode 100755 bin/ak-ipfs-name-publish create mode 100755 bin/ak-ipfs-name-resolve create mode 100755 bin/ak-ipfs-swarm-peers create mode 100755 bin/ak-sm-filejoiner create mode 100755 bin/ak-sm-files create mode 100755 bin/ak-sm-filesplitter diff --git a/bin/ak-articles b/bin/ak-articles index ce782b8..1eb3056 100755 --- a/bin/ak-articles +++ b/bin/ak-articles @@ -35,7 +35,7 @@ create(){ echo "Renaming..." TITLE="$(head -n 1 $ARTICLES_FILE)" TO_FILE=$ARTICLES_FILE-$(echo $TITLE | tr '[:upper:]' '[:lower:]' | sed -e 's/ /\_/g' ) - IPFS_FILE=$(ipfs add -q $ARTICLES_FILE) + IPFS_FILE=$(ak-ipfs-add $ARTICLES_FILE) mv $ARTICLES_FILE $ZARTICLESDIR/$TO_FILE sed -e 's,Qm.*,'"$IPFS_FILE"',g' $ZARTICLESDIR/README add $ZARTICLESDIR/$TO_FILE @@ -90,10 +90,10 @@ add(){ echo "Adding articles from " $FILE DATETIME=$(echo $FILE | cut -d - -f 1 | awk '{print $1}') TITLE=$(head -n 1 $FILE) - FILE_IPFS_HASH=$(ipfs add -q $FILE) + FILE_IPFS_HASH=$(ak-ipfs-add $FILE) FILE_SIGN_FILE=$FILE".asc" gpg --detach-sign --sign-with $AK_FINGERPRINT --armor --output $FILE_SIGN_FILE $FILE - FILE_SIGNATURE=$(ipfs add -q $FILE_SIGN_FILE) + FILE_SIGNATURE=$(ak-ipfs-add $FILE_SIGN_FILE) cat > data < to_stats sum=0 ; while IFS="" read -r p || [ -n "$p" ] do - num=$(ipfs block stat $p | grep Size | sed -e 's/Size: //g') + num=$(ak-ipfs-block-stat $p | grep Size | sed -e 's/Size: //g') sum=$(expr $sum + $num ) done < to_stats echo "Chain is : $sum bytes" diff --git a/bin/ak-categories b/bin/ak-categories index c9edd3c..5bc67d7 100755 --- a/bin/ak-categories +++ b/bin/ak-categories @@ -35,7 +35,7 @@ create(){ echo "Renaming..." TITLE="$(head -n 1 $NEWS_FILE)" TO_FILE=$NEWS_FILE-$(echo $TITLE | tr '[:upper:]' '[:lower:]' | sed -e 's/ /\_/g' ) - IPFS_FILE=$(ipfs add -q $NEWS_FILE) + 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 @@ -90,10 +90,10 @@ add(){ echo "Adding news from " $FILE DATETIME=$(echo $FILE | cut -d - -f 1 | awk '{print $1}') TITLE=$(head -n 1 $FILE) - FILE_IPFS_HASH=$(ipfs add -q $FILE) + FILE_IPFS_HASH=$(ak-ipfs-add $FILE) FILE_SIGN_FILE=$FILE".asc" gpg --detach-sign --sign-with $FINGERPRINT --armor --output $FILE_SIGN_FILE $FILE - FILE_SIGNATURE=$(ipfs add -q $FILE_SIGN_FILE) + FILE_SIGNATURE=$(ak-ipfs-add $FILE_SIGN_FILE) cat > data < data < tmpfile - ipfs name publish --key=ak-config /ipfs/$(ipfs add -q 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" @@ -39,13 +39,13 @@ publish(){ } published(){ - ipfs cat $(get_akid) + ak-ipfs-cat $(get_akid) } # We will be using our public key also to put it in the block later KEY="tmp-gpg.pub" gpg2 --armour --output $KEY --export $FINGERPRINT -GPG_PUB_KEY=$(ipfs add -q $KEY) +GPG_PUB_KEY=$(ak-ipfs-add $KEY) rm $KEY if [ ! -z $1 ]; then diff --git a/bin/ak-data-expand b/bin/ak-data-expand index 35f7826..08aae20 100755 --- a/bin/ak-data-expand +++ b/bin/ak-data-expand @@ -11,37 +11,37 @@ then logit "[ERROR]" "Invalid hash format for $1" exit 1 fi - ipfs --timeout=10s cat $1 > /dev/null + ak-ipfs-cat $1 > /dev/null if [ "$?" -ne 0 ] then logit "[ERROR]" "Error while reading $1" exit 1 fi - ipfs --timeout=10s 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 - ipfs --timeout=10s 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="$(ipfs --timeout=10s 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 - ipfs --timeout=10s 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="$(ipfs --timeout=10s 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" @@ -54,7 +54,7 @@ then exit 1 fi gpg="$2" - ipfs --timeout=10s 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" @@ -66,7 +66,7 @@ then logit "[ERROR]" "Could not import GPG key: $gpg" exit 1 fi - ipfs --timeout=10s 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" @@ -74,7 +74,7 @@ then fi mv $DETACH $DATA.asc logit "[INFO]" "Block signature downloaded" - ipfs --timeout=10s 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" @@ -88,7 +88,7 @@ then exit 1 fi logit "[INFO]" "Block signature verified" - echo -n '"data":{"'$1'":'$(ipfs --timeout=10s cat $1)'},' + echo -n '"data":{"'$1'":'$(ak-ipfs-cat $1)'},' exit 0 else echo "Usage: $PROGRAM HASH GPG" diff --git a/bin/ak-enter b/bin/ak-enter index 0f3b17c..dd65dcf 100755 --- a/bin/ak-enter +++ b/bin/ak-enter @@ -1,5 +1,5 @@ #!/bin/bash -# enter +# ak-enter # # Using this tool, we can seek a whole zchain, if available from # an IPFS CID or an IPNS link. @@ -8,10 +8,10 @@ # from the IPFS CID stored in the file that is tracked by the # $AK_ZLATEST environment variable. # -# enter [-n IPNS_LINK] -# enter [IPFS CID] -# enter -nV -# enter +# 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. @@ -61,7 +61,7 @@ then fi entrance="$1" else - # By default we enter from the latest block + # By default we ak-enter from the latest block # We can alter this by changing this value entrance="$(cat $AK_ZLATEST)" fi @@ -105,7 +105,7 @@ do # them to tmp-file # # We check if any $zblock at all - ipfs --timeout=10s cat $zblock > /dev/null 2>&1 + ak-ipfs-cat $zblock > /dev/null 2>&1 if [ "$?" -ne 0 ] then logit "[ERROR]" "ZBLOCK $zblock READ failed" @@ -114,7 +114,7 @@ do logit "[INFO]" "ZBLOCK $zblock READ" # If it's JSON formated - ipfs --timeout=10s cat $zblock | jq -M > /dev/null 2>&1 + ak-ipfs-cat $zblock | jq -M > /dev/null 2>&1 if [ "$?" -ne 0 ] then logit "[ERROR]" "ZBLOCK $zblock is not JSON" @@ -123,7 +123,7 @@ do logit "[INFO]" "ZBLOCK $zblock is JSON" # Then we pass it through the filter and save it - ipfs --timeout=10s cat $zblock | ak-json2bash > $TEMPASSIN/tmp-zblock + ak-ipfs-cat $zblock | ak-json2bash > $TEMPASSIN/tmp-zblock # Be sure that there are the expected values # We need 'block' and 'block_signature' inside a 'zblock' @@ -159,7 +159,7 @@ do # Same as above applies to BLOCK and DATA subparts of each ZBLOCK # BLOCKS echo -n '"block":"'$block'",' - ipfs --timeout=10s cat $block | ak-json2bash > $TEMPASSIN/tmp-block + ak-ipfs-cat $block | ak-json2bash > $TEMPASSIN/tmp-block if [ "$?" -ne 0 ] then logit "[ERROR]" "BLOCK $block READ failed" @@ -193,7 +193,7 @@ do echo -n '"gpg":"'$gpg'",' if [ $verify == 1 ] then - 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 ." @@ -205,7 +205,7 @@ do logit "[ERROR]" "Could not import GPG key: $gpg ." exit 1 fi - 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" @@ -213,7 +213,7 @@ do fi mv $block_signature $block.asc logit "[INFO]" "Block signature downloaded" - 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" @@ -238,7 +238,7 @@ do # DATA (but we don't source it's stuff) # Only print to stdout - #ipfs --timeout=10s cat $data + #ak-ipfs-cat $data touch $DATADIR/$data # Now, since we sourced the BLOCK to our terminal, we can search diff --git a/bin/ak-extract-cids b/bin/ak-extract-cids index 06b7ebc..3076ace 100755 --- a/bin/ak-extract-cids +++ b/bin/ak-extract-cids @@ -1,8 +1,8 @@ #!/bin/bash # -# Extracts unique IPFS CIDs from an entered zchain +# Extracts unique IPFS CIDs from an ak-entered zchain # # Previously: -# enter | jq | grep Qm | sed -e 's/^.*Qm/Qm/g' | cut -d '"' -f 1 +# ak-enter | jq | grep Qm | sed -e 's/^.*Qm/Qm/g' | cut -d '"' -f 1 # -enter | jq | grep Qm | sed -e 's/".*"://g; s/ //g; s/[{,"]//g' | sort | uniq +ak-enter | jq | grep Qm | sed -e 's/".*"://g; s/ //g; s/[{,"]//g' | sort | uniq diff --git a/bin/ak-filejoiner b/bin/ak-filejoiner deleted file mode 100755 index 2efd9e4..0000000 --- a/bin/ak-filejoiner +++ /dev/null @@ -1,78 +0,0 @@ -#!/bin/bash -# -set -xe - -PROGRAM="$(basename $0)" - -usage(){ - echo "$PROGRAM " -} - -cdaw(){ - pwd > tmp_holder -} - -cdaw - -CURDIR="$(cat tmp_holder)" - -TMPWD="/tmp/rjs" - -if [ ! -d "$TMPWD" ] -then - mkdir -p "$TMPWD" - if [ "$?" != 0 ] - then - echo "Can't create $TMPWD dir" - exit 1 - fi -fi - -MAPSDIR="$AK_WORKDIR/fmp" - -CHKDIR="$AK_WORKDIR/ftr" - -cd $CHKDIR -if [ "$?" != 0 ] -then - echo "Can't get dir" - exit 1 -fi - - - -if [ ! -z $1 ] -then - MAPSFILE="$1" - - echo '#!/bin/bash' > script - - awk '{print "cp '$CHKDIR'/"$1" '$TMPWD'/"$2" "}' $MAPSDIR/$MAPSFILE| grep chk > script - - sh script - if [ "$?" != 0 ] - then - echo "Error executing copy script" - exit 1 - fi - rm script - - cd $TMPWD - - echo "$PWD" - OUTPUT="$(tail -n1 $MAPSDIR/$MAPSFILE | awk '{print $2}')" - - echo $OUTPUT - - cat $(echo -n $(cat $MAPSDIR/$MAPSFILE|grep chk|awk '{print $2" "}'|tr -d '\n')) > $OUTPUT - - sha512sum -c $MAPSDIR/$MAPSFILE - - mv $OUTPUT $CURDIR - - rm -rf "$TMPWD" - - rm $CURDIR/tmp_holder -else - usage -fi diff --git a/bin/ak-files b/bin/ak-files index 9fddc60..448ae76 100755 --- a/bin/ak-files +++ b/bin/ak-files @@ -1,6 +1,6 @@ #!/bin/bash # The following creates a mixtape data message -# We can extend it by calling the pack_z_block.sh mixtape/add data +# 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)" @@ -71,7 +71,7 @@ main(){ FILE="$TEMPASSIN/$1" logit "[INFO]" "Adding $FILE to IPFS..." - FILE_IPFS_HASH=$(ipfs add -q $FILE) + FILE_IPFS_HASH=$(ak-ipfs-add $FILE) if [ $? == 0 ]; then logit "[INFO]" "Added $FILE to IPFS" else @@ -87,7 +87,7 @@ main(){ fi logit "[INFO]" "Adding signature to IPFS" - SIGNATURE=$(ipfs add -q $TEMPASSIN/$SIGN_FILE) + SIGNATURE=$(ak-ipfs-add $TEMPASSIN/$SIGN_FILE) if [ $? == 0 ]; then logit "[INFO]" "Added" else @@ -107,7 +107,7 @@ echo "Printing data..." cat $TEMPASSIN/data echo "Publishing..." - pack_z_block files/add data + ak-pack_z_block files/add data if [ $? == 0 ] then echo "cool" diff --git a/bin/ak-filesplitter b/bin/ak-filesplitter deleted file mode 100755 index c675870..0000000 --- a/bin/ak-filesplitter +++ /dev/null @@ -1,136 +0,0 @@ -#!/bin/bash -# -# The concept is simple -# -# 1. For a given file we split in 1MB files inside a temporary directory -# -# 2. We then create a map file, containing the resulted files and their sha512sum -# -# 3. We move the files to our $CHKDIR named after their checksums -# -# We ultimately want to be seeding the file so -# -# 4. We append the checksum of the original file with its name into the map file -# -# 5. We rename the map file after its checksum and move it to maps directory -# -# 6. We are done! -# - -# Uncomment next line if you want to debug -# set -xe -PROGRAM="$(basename $0)" - -if [ ! -f "$1" ] -then - echo "[ERROR] File not found" - exit 1 -else - FILE="$1" -fi - -# The directory where the chunked data will be living at -CHKDIR="$AK_WORKDIR/ftr/" -# The directory for the map files so we can reconstruct the file -FILEMAPSDIR="$AK_WORKDIR/fmp/" -# A temporary root dir to work on -TEMPORARYDIR="/tmp/tltmp" -# A subdir to split the files there -TECHDIR="/tmp/tltmp/chks/" -# A pin point to return from where we came from -CURRENTDIR="$(pwd)/" - -# Our snippet for logging debug info -logit(){ - ak-logthis "<$PROGRAM>" "$1" "$2" -} - -# Checking directories and create them if necessary - -# TECHDIR -if [ ! -d "$TECHDIR" ] -then - mkdir -p "$TECHDIR" - if [ "$?" == 0 ] - then - logit "[INFO]" "Folder $TECHDIR created!" - else - logit "[ERROR]" "Problem occured while creating $TECHDIR" - echo "[ERROR] Can't create $TECHDIR" - exit 1 - fi -else - logit "[INFO]" "Temp dir found" -fi - -# FILEMAPSDIR -if [ ! -d "$FILEMAPSDIR" ] -then - mkdir -p "$FILEMAPSDIR" - if [ "$?" == 0 ] - then - logit "[INFO]" "Folder $FILEMAPSDIR created!" - else - logit "[ERROR]" "Problem occured while creating $FILEMAPSDIR" - echo "[ERROR] Can't create $FILEMAPSDIR" - exit 1 - fi -else - logit "[INFO]" "Mapsdir found" -fi - -# CHKDIR -if [ ! -d "$CHKDIR" ] -then - mkdir -p "$CHKDIR" - if [ "$?" == 0 ] - then - logit "[INFO]" "Folder $CHKDIR created!" - else - logit "[ERROR]" "Problem occured while creating $CHKDIR" - echo "[ERROR] Can't create $CHKDIR" - exit 1 - fi -else - logit "[INFO]" "Workdir found" -fi - -# Uncomment next line in case you want to debug the resulting script as well -# echo 'set -xe' > $TEMPORARYDIR/cmd_queue.sh - -# We get the SHA512 hash for the $FILE given -CHECKSUM=$(sha512sum "$FILE"|awk '{print $1}') - -# We split the file into 1048576 bytes and output the chunks into TECHDIR -split -b 1048576 --additional-suffix ".chk" -d "$FILE" "$TECHDIR$(basename "$FILE")-" - -# We go over there... -cd $TECHDIR - -# We get every chunks' SHA512 and we craft a script to rename the chunks and -# move them to CHKDIR -sha512sum * > $TEMPORARYDIR/map; while IFS="" read -r p || [ -n "$p" ] -do - echo $p | awk '{print "mv " $2 " '$CHKDIR'" $1}' >> $TEMPORARYDIR/cmd_queue.sh -done < $TEMPORARYDIR/map - -# We run the crafted script -sh $TEMPORARYDIR/cmd_queue.sh - -# and we delete it -rm $TEMPORARYDIR/cmd_queue.sh - -# We inform the map about the original $FILE name and SHA512 -echo "$CHECKSUM $(basename "$FILE")" >> $TEMPORARYDIR/map - -# We get the SHA512 hash of the resulted map file -MAPFILEHASH="$(sha512sum $TEMPORARYDIR/map | awk '{ print $1 }')" - -# and we rename it with it and move it to FILEMAPSDIR -`sha512sum $TEMPORARYDIR/map | awk '{print "mv " $2 " '$FILEMAPSDIR'" $1}'` - -# We remove the TEMPORARYDIR -rm -rf $TEMPORARYDIR - -# and print the MAPFILEHASH -echo "$MAPFILEHASH" diff --git a/bin/ak-folders b/bin/ak-folders index 234592a..df88ca1 100755 --- a/bin/ak-folders +++ b/bin/ak-folders @@ -1,6 +1,6 @@ #!/bin/bash # The following creates a mixtape data message -# We can extend it by calling the pack_z_block.sh mixtape/add data +# 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 @@ -61,7 +61,7 @@ main(){ FOLDER="$TEMPASSIN/$1" ak-logthis "Adding $FOLDER to IPFS..." - FOLDER_IPFS_HASH=$(ipfs add -rQ $FOLDER) + FOLDER_IPFS_HASH=$(ak-ipfs-add $FOLDER) if [ $? == 0 ]; then ak-logthis "done" else @@ -79,7 +79,7 @@ main(){ # fi # # ak-logthis "Adding signature to IPFS" -# SIGNATURE=$(ipfs add -q $TEMPASSIN/$SIGN_FOLDER) +# SIGNATURE=$(ak-ipfs-add $TEMPASSIN/$SIGN_FOLDER) # if [ $? == 0 ]; then # ak-logthis "Added" # else @@ -98,7 +98,7 @@ echo "Printing data..." cat $TEMPASSIN/data echo "Publishing..." - pack_z_block folders/add data + ak-pack_z_block folders/add data if [ $? == 0 ] then echo "cool" diff --git a/bin/ak-follow b/bin/ak-follow index a72ba8b..9177c7f 100755 --- a/bin/ak-follow +++ b/bin/ak-follow @@ -3,7 +3,7 @@ FOLLOWING="$HOME/.arching-kaos/following" if [ ! -z $1 ] then echo $1 >> $FOLLOWING - IPFS=$(ipfs add -q $FOLLOWING) + IPFS=$(ak-ipfs-add $FOLLOWING) if [ $? == 0 ] then profile set following $IPFS diff --git a/bin/ak-get-akid b/bin/ak-get-akid index 17dcf74..61bc563 100755 --- a/bin/ak-get-akid +++ b/bin/ak-get-akid @@ -1,5 +1,5 @@ #!/bin/bash # Resolves the IPNS key "ak-config" to its current IPFS value # Return IPFS CIDv0 without /ipfs/ prefix -ipfs name resolve /ipns/$(ipfs key list -l | grep ak-config | awk '{print $1}') | sed -e 's/\/ipfs\///' +ak-ipfs-name-resolve /ipns/$(ak-ipfs-key-list-full | grep ak-config | awk '{print $1}') | sed -e 's/\/ipfs\///' diff --git a/bin/ak-get-chain-minified b/bin/ak-get-chain-minified index 259cc36..d8c3fff 100755 --- a/bin/ak-get-chain-minified +++ b/bin/ak-get-chain-minified @@ -1 +1 @@ -enter | jq --compact-output +ak-enter | jq --compact-output diff --git a/bin/ak-get-ipfs-hashes-from-my-zchain b/bin/ak-get-ipfs-hashes-from-my-zchain index 3640cc5..4d60d13 100755 --- a/bin/ak-get-ipfs-hashes-from-my-zchain +++ b/bin/ak-get-ipfs-hashes-from-my-zchain @@ -1,2 +1,2 @@ #!/bin/bash -enter | jq -M | grep Qm | sed -e 's/{"zblock":"//g; s/",//; s/".*".*: "//g; s/"//g; s/{//g; s/://g; s/ //g' +ak-enter | jq -M | grep Qm | sed -e 's/{"zblock":"//g; s/",//; s/".*".*: "//g; s/"//g; s/{//g; s/://g; s/ //g' diff --git a/bin/ak-get-latest b/bin/ak-get-latest index e770d1c..36de493 100755 --- a/bin/ak-get-latest +++ b/bin/ak-get-latest @@ -1,2 +1,2 @@ #!/bin/bash -ipfs files stat /zlatest | head -n 1| tr -d '\n' +ak-ipfs-files-stat /zlatest | head -n 1| tr -d '\n' diff --git a/bin/ak-get-only-ipfs-key-values-from-our-or-a-zchain b/bin/ak-get-only-ipfs-key-values-from-our-or-a-zchain index 2b9f580..303d595 100755 --- a/bin/ak-get-only-ipfs-key-values-from-our-or-a-zchain +++ b/bin/ak-get-only-ipfs-key-values-from-our-or-a-zchain @@ -2,7 +2,7 @@ # Outputs all the "ipfs" values from the DATA blocks of our ZCHAIN if [ ! -z $1 ] then - enter $1 | jq | grep ipfs | awk '{print $2}' | sed -e 's/"//g;s/,//g' + ak-enter $1 | jq | grep ipfs | awk '{print $2}' | sed -e 's/"//g;s/,//g' else - enter | jq | grep ipfs | awk '{print $2}' | sed -e 's/"//g;s/,//g' + ak-enter | jq | grep ipfs | awk '{print $2}' | sed -e 's/"//g;s/,//g' fi diff --git a/bin/ak-get-only-ipfs-key-values-from-our-zchain b/bin/ak-get-only-ipfs-key-values-from-our-zchain index 8334f66..747bb55 100755 --- a/bin/ak-get-only-ipfs-key-values-from-our-zchain +++ b/bin/ak-get-only-ipfs-key-values-from-our-zchain @@ -1,3 +1,3 @@ #!/bin/bash # Outputs all the "ipfs" values from the DATA blocks of our ZCHAIN -enter | jq | grep ipfs | awk '{print $2}' | sed -e 's/"//g;s/,//g' | sort | uniq +ak-enter | jq | grep ipfs | awk '{print $2}' | sed -e 's/"//g;s/,//g' | sort | uniq diff --git a/bin/ak-ipfs-add b/bin/ak-ipfs-add new file mode 100755 index 0000000..5887b24 --- /dev/null +++ b/bin/ak-ipfs-add @@ -0,0 +1,3 @@ +#!/bin/bash + +ipfs add -Qr $1 diff --git a/bin/ak-ipfs-block-stat b/bin/ak-ipfs-block-stat new file mode 100755 index 0000000..54b6b40 --- /dev/null +++ b/bin/ak-ipfs-block-stat @@ -0,0 +1,3 @@ +#!/bin/bash + +ipfs block stat "$1" diff --git a/bin/ak-ipfs-cat b/bin/ak-ipfs-cat new file mode 100755 index 0000000..2c29458 --- /dev/null +++ b/bin/ak-ipfs-cat @@ -0,0 +1,2 @@ +#!/bin/bash +ipfs --timeout=10s cat $1 diff --git a/bin/ak-ipfs-check b/bin/ak-ipfs-check index 721693e..0ee3e3c 100755 --- a/bin/ak-ipfs-check +++ b/bin/ak-ipfs-check @@ -5,7 +5,7 @@ logit(){ } -ipfs files ls /zarchive > /dev/null +ak-ipfs-files-ls /zarchive > /dev/null if [ $? != 0 ] then logit "[ERROR]" "/zarchive is missing" @@ -14,7 +14,7 @@ else fi -ipfs files ls /zlatest > /dev/null +ak-ipfs-files-ls /zlatest > /dev/null if [ $? != 0 ] then logit "[ERROR]" "/zlatest is missing" @@ -22,10 +22,10 @@ else logit "[INFO]" "/zlatest is OK" fi -ipfs key list | grep zchain > /dev/null +ak-ipfs-key-list | grep zchain > /dev/null if [ $? != 0 ]; then logit "[WARNING]" "zchain key is missing" - ipfs key gen zchain > $ZCHAIN + ak-ipfs-key-gen zchain > $ZCHAIN if [ $? != 0 ]; then logit "[ERROR]" "zchain fails to create" else @@ -35,10 +35,10 @@ else logit "[INFO]" "zchain is there" fi -ipfs key list | grep ak-config > /dev/null +ak-ipfs-key-list | grep ak-config > /dev/null if [ $? != 0 ]; then logit "[WARNING]" "ak-config key is missing" - ipfs key gen ak-config + ak-ipfs-key-gen ak-config if [ $? != 0 ]; then logit "[ERROR]" "ak-config fails to create" else diff --git a/bin/ak-ipfs-files-cp b/bin/ak-ipfs-files-cp new file mode 100755 index 0000000..70dd701 --- /dev/null +++ b/bin/ak-ipfs-files-cp @@ -0,0 +1,3 @@ +#!/bin/bash + +ipfs files cp "$1" "$2" diff --git a/bin/ak-ipfs-files-ls b/bin/ak-ipfs-files-ls new file mode 100755 index 0000000..78a7002 --- /dev/null +++ b/bin/ak-ipfs-files-ls @@ -0,0 +1,3 @@ +#!/bin/bash + +ipfs files ls "$1" diff --git a/bin/ak-ipfs-files-mkdir b/bin/ak-ipfs-files-mkdir new file mode 100755 index 0000000..a81ffe4 --- /dev/null +++ b/bin/ak-ipfs-files-mkdir @@ -0,0 +1,3 @@ +#!/bin/bash + +ipfs files mkdir "$1" diff --git a/bin/ak-ipfs-files-mv b/bin/ak-ipfs-files-mv new file mode 100755 index 0000000..e69de29 diff --git a/bin/ak-ipfs-files-rm b/bin/ak-ipfs-files-rm new file mode 100755 index 0000000..1c4d597 --- /dev/null +++ b/bin/ak-ipfs-files-rm @@ -0,0 +1,3 @@ +#!/bin/bash + +ipfs files rm "$1" diff --git a/bin/ak-ipfs-files-stat b/bin/ak-ipfs-files-stat new file mode 100755 index 0000000..49e70e8 --- /dev/null +++ b/bin/ak-ipfs-files-stat @@ -0,0 +1,3 @@ +#!/bin/bash + +ipfs files stat "$1" diff --git a/bin/ak-ipfs-get b/bin/ak-ipfs-get new file mode 100755 index 0000000..8eee9be --- /dev/null +++ b/bin/ak-ipfs-get @@ -0,0 +1,3 @@ +#!/bin/bash + +ipfs get $1 diff --git a/bin/ak-ipfs-key-gen b/bin/ak-ipfs-key-gen new file mode 100755 index 0000000..29a30f9 --- /dev/null +++ b/bin/ak-ipfs-key-gen @@ -0,0 +1,2 @@ +#!/bin/bash +ipfs key gen "$1" diff --git a/bin/ak-ipfs-key-list b/bin/ak-ipfs-key-list new file mode 100755 index 0000000..dd33848 --- /dev/null +++ b/bin/ak-ipfs-key-list @@ -0,0 +1 @@ +ipfs key list diff --git a/bin/ak-ipfs-key-list-full b/bin/ak-ipfs-key-list-full new file mode 100755 index 0000000..f777225 --- /dev/null +++ b/bin/ak-ipfs-key-list-full @@ -0,0 +1,2 @@ +#!/bin/bash +ipfs key list -l diff --git a/bin/ak-ipfs-name-publish b/bin/ak-ipfs-name-publish new file mode 100755 index 0000000..321ba89 --- /dev/null +++ b/bin/ak-ipfs-name-publish @@ -0,0 +1,3 @@ +#!/bin/bash + +ipfs name publish $1 $2 diff --git a/bin/ak-ipfs-name-resolve b/bin/ak-ipfs-name-resolve new file mode 100755 index 0000000..d27c57a --- /dev/null +++ b/bin/ak-ipfs-name-resolve @@ -0,0 +1,3 @@ +#!/bin/bash + +ipfs name resolve "$1" diff --git a/bin/ak-ipfs-swarm-peers b/bin/ak-ipfs-swarm-peers new file mode 100755 index 0000000..5d6e904 --- /dev/null +++ b/bin/ak-ipfs-swarm-peers @@ -0,0 +1 @@ +ipfs swarm peers diff --git a/bin/ak-ipns-resolve b/bin/ak-ipns-resolve index f8bb767..e93218e 100755 --- a/bin/ak-ipns-resolve +++ b/bin/ak-ipns-resolve @@ -13,7 +13,7 @@ logit(){ } if [ ! -z $1 ] then - rsld=$(ipfs name resolve $1) + rsld=$(ak-ipfs-name-resolve $1) if [ "$?" != 0 ] then logit "[ERROR]" "Failed to resolve $1" diff --git a/bin/ak-json2bash b/bin/ak-json2bash index 171a7df..ee64f66 100755 --- a/bin/ak-json2bash +++ b/bin/ak-json2bash @@ -7,5 +7,5 @@ # Strips " , { } from input and replaces ":" with = # # Usage: -# ipfs cat | ak-json2bash +# ak-ipfs-cat | ak-json2bash sed -e 's/{//g' | sed -e 's/}//g' | sed -e 's/":"/=/g' | sed -e 's/"//g' | sed -e 's/,//g' | sed -e 's/ //g' diff --git a/bin/ak-mempool b/bin/ak-mempool index b0d6d4b..83b0dfb 100755 --- a/bin/ak-mempool +++ b/bin/ak-mempool @@ -5,14 +5,14 @@ # They also are a part of our swarm. # So should we ask for our peers? -ipfs swarm peers > tmp_peers +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..." - ipfs cat /ipns/$peer/zlatest + ak-ipfs-cat /ipns/$peer/zlatest done < tmp_peers rm tmp_peers diff --git a/bin/ak-miner-script b/bin/ak-miner-script index 5e686c5..7b83848 100755 --- a/bin/ak-miner-script +++ b/bin/ak-miner-script @@ -31,7 +31,7 @@ proofofwork(){ usage(){ echo "$PROGRAM " - echo " hit enter after that !!! " + echo " hit ak-enter after that !!! " } if [ -z "$1" ] ; diff --git a/bin/ak-mixtapes b/bin/ak-mixtapes index a40f33b..c78a709 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 pack_z_block.sh mixtape/add data +# We can extend it by calling the ak-pack_z_block.sh mixtape/add data usage(){ title @@ -10,12 +10,12 @@ usage(){ main(){ echo $MIXTAPE_FILE "by" $MIXTAPE_ARTIST "named as" $MIXTAPE_TITLE - MIXTAPE_IPFS_HASH=$(ipfs add -q $MIXTAPE_FILE) + MIXTAPE_IPFS_HASH=$(ak-ipfs-add $MIXTAPE_FILE) MIXTAPE_SIGN_FILE=$MIXTAPE_FILE".asc" gpg2 --detach-sign --sign-with $FINGERPRINT --armor --output $MIXTAPE_SIGN_FILE $MIXTAPE_FILE - MIXTAPE_SIGNATURE=$(ipfs add -q $MIXTAPE_SIGN_FILE) + MIXTAPE_SIGNATURE=$(ak-ipfs-add $MIXTAPE_SIGN_FILE) cat > data <" "$1" "$2" +} + 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" + if [ "$?" == 0 ]; then + logit "[INFO]" "$ZNEWSDIR created" + else + logit "[ERROR]" "$ZNEWSDIR couldn't be created" + exit 1 + fi else - echo "znewsdir found" + logit "[INFO]" "$ZNEWSDIR found" fi + +cd $ZNEWSDIR + tempassin(){ if [ ! -z $1 ] then @@ -27,6 +35,7 @@ tempassin(){ fi cd $TEMPASSIN } + create(){ tempassin $TEMP curpath="$(pwd)" @@ -35,15 +44,12 @@ create(){ echo "Renaming..." TITLE="$(head -n 1 $NEWS_FILE)" TO_FILE=$NEWS_FILE-$(echo $TITLE | tr '[:upper:]' '[:lower:]' | sed -e 's/ /\_/g' ) - IPFS_FILE=$(ipfs add -q $NEWS_FILE) + IPFS_FILE=$(ak-ipfs-add $NEWS_FILE) mv $NEWS_FILE $ZNEWSDIR/$TO_FILE sed -e 's,Qm.*,'"$IPFS_FILE"',g' $ZNEWSDIR/README add $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 } index(){ @@ -53,13 +59,13 @@ index(){ do DATE=$(echo $FILE | cut -d - -f 1 | awk '{print $1}') TITLE=$(head -n 1 $ZNEWSDIR/$FILE) - echo $i \| $DATE \| $TITLE + IPFS_HASH=$(ak-ipfs-addn $ZNEWSDIR/$FILE) + echo $i \| $IPFS_HASH \| $DATE \| $TITLE let i+=1 done } title(){ - echo ak-news-cli - echo "--------------" + echo $PROGRAM } import(){ echo "#TODO" @@ -93,10 +99,10 @@ add2(){ echo "Adding news from " $FILE DATETIME=$(echo $FILE | cut -d - -f 1 | awk '{print $1}') TITLE=$(head -n 1 $FILE) - FILE_IPFS_HASH=$(ipfs add -q $FILE) + FILE_IPFS_HASH=$(ak-ipfs-add $FILE) FILE_SIGN_FILE=$FILE".asc" gpg --detach-sign --sign-with $FINGERPRINT --armor --output $FILE_SIGN_FILE $FILE - FILE_SIGNATURE=$(ipfs add -q $FILE_SIGN_FILE) + FILE_SIGNATURE=$(ak-ipfs-add $FILE_SIGN_FILE) cat > data < data < #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" @@ -167,7 +173,7 @@ title if [ ! -z $1 ]; then case $1 in help) usage; exit;; - index) index; exit;; + local-index) index; exit;; import) import $2; exit;; add) add2 $2; exit;; create) create; exit;; diff --git a/bin/ak-pack_z_block b/bin/ak-pack_z_block index 9252122..76e87df 100755 --- a/bin/ak-pack_z_block +++ b/bin/ak-pack_z_block @@ -15,6 +15,7 @@ # FINGERPRINT="$(gpg2 --list-keys | grep kaos@kaos.kaos -1 | head -n1 | awk '{print $1}')" PROGRAM="$(basename $0)" +set -xe # Logging patch logit(){ @@ -42,7 +43,7 @@ main(){ # We check firstly if the encapsulated value of the "ipfs" key has already # appeared in the zchain. TO_CHECK="$(cat $MESSAGE | jq | grep ipfs | awk '{print $2}' | sed -e 's/"//g;s/,//g')" - enter | jq | grep ipfs | awk '{print $2}' | sed -e 's/"//g;s/,//g' | sort | uniq > tempisalreadythere + ak-enter | jq | grep ipfs | awk '{print $2}' | sed -e 's/"//g;s/,//g' | sort | uniq > tempisalreadythere while IFS="" read -r p || [ -n "$p" ] do if [ "$p" == "$TO_CHECK" ] @@ -55,22 +56,22 @@ main(){ logit "[INFO]" "We are doing" $ACTION "with content" $MESSAGE # We add it to IPFS - MESSAGE_HASH=$(ipfs add -q $MESSAGE) + MESSAGE_HASH=$(ak-ipfs-add $MESSAGE) # We create a detached and armor signature of it MESSAGE_SIGN_FILE=$MESSAGE".asc" gpg2 --detach-sign --sign-with $FINGERPRINT --armor --output $MESSAGE_SIGN_FILE $MESSAGE # We add the signature to IPFS - MESSAGE_SIGNATURE=$(ipfs add -q $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" gpg2 --armour --output $KEY --export $FINGERPRINT - GPG_PUB_KEY=$(ipfs add -q $KEY) + GPG_PUB_KEY=$(ak-ipfs-add $KEY) # Acquire last block of information, to chain this one with previous posted - PREVIOUS=$(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 < zblock << EOF @@ -103,7 +104,7 @@ EOF EOF ZBL="zblock" # and we add it on IPFS - ZBLOCK=$(ipfs add -q $ZBL) + ZBLOCK=$(ak-ipfs-add $ZBL) echo $ZBLOCK } @@ -124,36 +125,36 @@ then # python send_as_ak_tx $ZBLOCK # or for "offline" use echo $ZBLOCK > $ZLATEST - 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 - 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" - 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 - ipfs files cp /zlatest /zarchive/$(date -u +%s)-$(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 - 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 - 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-profile b/bin/ak-profile index 1aa6e9c..63df6fd 100755 --- a/bin/ak-profile +++ b/bin/ak-profile @@ -42,7 +42,7 @@ show(){ if [ ! -z $1 ] then logit "[INFO]" "Working with $1" - ipfs cat $(echo $(ipfs cat $1) | jq '.ipfs' -r) + ak-ipfs-cat $(echo $(ak-ipfs-cat $1) | jq '.ipfs' -r) else echo "No DATA provided" exit 1 @@ -75,7 +75,7 @@ EOF if [ $? == 0 ] then echo "Added successfully... proceeding" - IPFS_FILE=$(ipfs add -q $ZPROPERTY_FILE) + IPFS_FILE=$(ak-ipfs-add $ZPROPERTY_FILE) echo "Prop writting,,, $IPFS_FILE" add $ZPROPERTY_KEY echo "Adding to git repo..." @@ -167,10 +167,10 @@ add(){ if [ -f $ZPROFILEDIR/$1 ]; then FILE="$ZPROFILEDIR/$1" echo "Adding from " $FILE - FILE_IPFS_HASH=$(ipfs add -q $FILE) + FILE_IPFS_HASH=$(ak-ipfs-add $FILE) FILE_SIGN_FILE=$(pwd)/$1".asc" gpg2 --detach-sign --sign-with $FINGERPRINT --armor --output $FILE_SIGN_FILE $FILE - FILE_SIGNATURE=$(ipfs add -q $FILE_SIGN_FILE) + FILE_SIGNATURE=$(ak-ipfs-add $FILE_SIGN_FILE) cat > data < data < data <" +} + +cdaw(){ + pwd > tmp_holder +} + +cdaw + +CURDIR="$(cat tmp_holder)" + +TMPWD="/tmp/rjs" + +if [ ! -d "$TMPWD" ] +then + mkdir -p "$TMPWD" + if [ "$?" != 0 ] + then + echo "Can't create $TMPWD dir" + exit 1 + fi +fi + +MAPSDIR="$AK_WORKDIR/fmp" + +CHKDIR="$AK_WORKDIR/ftr" + +cd $CHKDIR +if [ "$?" != 0 ] +then + echo "Can't get dir" + exit 1 +fi + + + +if [ ! -z $1 ] +then + MAPSFILE="$1" + + echo '#!/bin/bash' > script + + # We create a script to copy all the chunks and rename them to their serialized + # name produced by split when we splitted the file + awk '{print "cp '$CHKDIR'/"$1" '$TMPWD'/"$2" "}' $MAPSDIR/$MAPSFILE| grep chk >> script + + bash script + + if [ "$?" != 0 ] + then + echo "Error executing copy script" + exit 1 + fi + rm script + + cd $TMPWD + + echo "$PWD" + + # Final name we are going to rename to + OUTPUT="$(tail -n1 $MAPSDIR/$MAPSFILE | awk '{print $2}')" + + echo $OUTPUT + + # We grep the MAPSFILE for chk filenames in lines and we print them all in + # one line so the first `cat` will concatenate all chunks to OUTPUT + cat $(echo -n $(cat $MAPSDIR/$MAPSFILE|grep chk|awk '{print $2" "}'|tr -d '\n')) > $OUTPUT + + # We check if everything is okay + sha512sum -c $MAPSDIR/$MAPSFILE + if [ "$?" != "0" ]; then + logit "[ERROR]" "Error while checking sums" + exit 1 + fi + + mv $OUTPUT $CURDIR + + rm -rf "$TMPWD" + + rm $CURDIR/tmp_holder +else + usage +fi diff --git a/bin/ak-sm-files b/bin/ak-sm-files new file mode 100755 index 0000000..7eb3b7d --- /dev/null +++ b/bin/ak-sm-files @@ -0,0 +1,156 @@ +#!/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)" +#set -xe +logit(){ + ak-logthis "<$PROGRAM>" "$1" "$2" +} +if [ ! -d $ZFILESDIR ]; then + mkdir $ZFILESDIR + if [ $? == 0 ] + then + logit "[INFO]" "Folder $ZFILESDIR created!" + else + logit "[ERROR]" "Failed to create $ZFILESDIR folder" + exit 1 + fi + cd $ZFILESDIR +else + logit "[INFO]" "$ZFILESDIR found!" +fi +tempassin(){ + if [ ! -z $1 ]; + then + TEMPASSIN="$1" + else + TIMESTAMP="$(date -u +%s)" + TEMPASSIN="/tmp/aktmp_$TIMESTAMP" + fi + if [ ! -d $TEMPASSIN ]; then + mkdir $TEMPASSIN + fi + cd $TEMPASSIN + echo "$TEMPASSIN" + +} + +usage(){ + echo "$PROGRAM - file" + echo " add " + echo " index" +} + +add(){ + CRP="$(pwd)" + FILENAME="$1" + main $FILENAME $CRP + cat $TEMPASSIN/data | jq -M +} +main(){ + FILENAME="$1" + CRP="$2" + echo "Adding $FILENAME" + logit "[INFO]" "Switching to tmp folder..." + TEMPASSIN="$(tempassin)" + + cd $TEMPASSIN + if [ $? == 0 ]; then + logit "[INFO]" "Success" + else + logit "[ERROR]" "Error with tmp folder" + exit 5 + fi + logit "[INFO]" "Copying $1 to $TEMPASSIN" + + cp $2/$1 $TEMPASSIN/$1 + 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) + if [ $? == 0 ]; then + logit "[INFO]" "Added $FILE to IPFS" + else + logit "[ERROR]" "Error in adding the $FILE to IPFS" + fi + + logit "[INFO]" "Adding $FILE to SHAMAPSYS..." + FILEMAP_SHA512_HASH=$(ak-sm-filesplitter $FILE) + if [ $? == 0 ]; then + logit "[INFO]" "Added $FILE to SHAMAPSYS" + else + logit "[ERROR]" "Error in adding the $FILE to SHAMAPSYS" + fi + + logit "[INFO]" "Signing..." + SIGN_FILE=$FILENAME".asc" + gpg2 --detach-sign --sign-with $FINGERPRINT --armor --output $SIGN_FILE $FILE + if [ $? == 0 ]; then + logit "[INFO]" "Signed" + else + logit "[ERROR]" "Error while signing" + fi + + logit "[INFO]" "Adding signature to IPFS" + SIGNATURE=$(ak-ipfs-add $TEMPASSIN/$SIGN_FILE) + if [ $? == 0 ]; then + logit "[INFO]" "Added" + else + logit "[ERROR]" "Error while adding" + fi + + logit "[INFO]" "Adding signature to SHAMAPSYS" + SHAMAPSIGMAP=$(ak-sm-filesplitter $TEMPASSIN/$SIGN_FILE) + if [ $? == 0 ]; then + logit "[INFO]" "Added" + else + logit "[ERROR]" "Error while adding" + fi + + cat > $TEMPASSIN/data <" "$1" "$2" +} + +# Checking directories and create them if necessary + +# TECHDIR +if [ ! -d "$TECHDIR" ] +then + mkdir -p "$TECHDIR" + if [ "$?" == 0 ] + then + logit "[INFO]" "Folder $TECHDIR created!" + else + logit "[ERROR]" "Problem occured while creating $TECHDIR" + echo "[ERROR] Can't create $TECHDIR" + exit 1 + fi +else + logit "[INFO]" "Temp dir found" +fi + +# FILEMAPSDIR +if [ ! -d "$FILEMAPSDIR" ] +then + mkdir -p "$FILEMAPSDIR" + if [ "$?" == 0 ] + then + logit "[INFO]" "Folder $FILEMAPSDIR created!" + else + logit "[ERROR]" "Problem occured while creating $FILEMAPSDIR" + echo "[ERROR] Can't create $FILEMAPSDIR" + exit 1 + fi +else + logit "[INFO]" "Mapsdir found" +fi + +# CHKDIR +if [ ! -d "$CHKDIR" ] +then + mkdir -p "$CHKDIR" + if [ "$?" == 0 ] + then + logit "[INFO]" "Folder $CHKDIR created!" + else + logit "[ERROR]" "Problem occured while creating $CHKDIR" + echo "[ERROR] Can't create $CHKDIR" + exit 1 + fi +else + logit "[INFO]" "Workdir found" +fi + +# Uncomment next line in case you want to debug the resulting script as well +# echo 'set -xe' > $TEMPORARYDIR/cmd_queue.sh + +# We get the SHA512 hash for the $FILE given +CHECKSUM=$(sha512sum "$FILE"|awk '{print $1}') + +# We split the file into 1048576 bytes and output the chunks into TECHDIR +split -b 1048576 --additional-suffix ".chk" -d "$FILE" "$TECHDIR$(basename "$FILE")-" + +# We go over there... +cd $TECHDIR + +# We get every chunks' SHA512 and we craft a script to rename the chunks and +# move them to CHKDIR +sha512sum * > $TEMPORARYDIR/map; while IFS="" read -r p || [ -n "$p" ] +do + echo $p | awk '{print "mv " $2 " '$CHKDIR'" $1}' >> $TEMPORARYDIR/cmd_queue.sh +done < $TEMPORARYDIR/map + +# We run the crafted script +sh $TEMPORARYDIR/cmd_queue.sh + +# and we delete it +rm $TEMPORARYDIR/cmd_queue.sh + +# We inform the map about the original $FILE name and SHA512 +echo "$CHECKSUM $(basename "$FILE")" >> $TEMPORARYDIR/map + +# We get the SHA512 hash of the resulted map file +MAPFILEHASH="$(sha512sum $TEMPORARYDIR/map | awk '{ print $1 }')" + +# and we rename it with it and move it to FILEMAPSDIR +`sha512sum $TEMPORARYDIR/map | awk '{print "mv " $2 " '$FILEMAPSDIR'" $1}'` + +# We remove the TEMPORARYDIR +rm -rf $TEMPORARYDIR + +# and print the MAPFILEHASH +echo "$MAPFILEHASH" diff --git a/bin/ak-todos b/bin/ak-todos index b95b3a8..218feda 100755 --- a/bin/ak-todos +++ b/bin/ak-todos @@ -34,7 +34,7 @@ create(){ ak-logthis "Renaming..." TITLE="$(head -n 1 $TODOS_FILE)" TO_FILE=$TODOS_FILE-$(echo $TITLE | tr '[:upper:]' '[:lower:]' | sed -e 's/ /\_/g' ) - IPFS_FILE=$(ipfs add -q $TODOS_FILE) + IPFS_FILE=$(ak-ipfs-add $TODOS_FILE) mv $TODOS_FILE $ZTODOSDIR/$TO_FILE sed -e 's,Qm.*,'"$IPFS_FILE"',g' $ZTODOSDIR/README add $ZTODOSDIR/$TO_FILE @@ -89,10 +89,10 @@ add(){ ak-logthis "Adding todos from $FILE" DATETIME=$(echo $FILE | cut -d - -f 1 | awk '{print $1}') TITLE=$(head -n 1 $FILE) - FILE_IPFS_HASH=$(ipfs add -q $FILE) + FILE_IPFS_HASH=$(ak-ipfs-add $FILE) FILE_SIGN_FILE=$FILE".asc" gpg --detach-sign --sign-with $FINGERPRINT --armor --output $FILE_SIGN_FILE $FILE - FILE_SIGNATURE=$(ipfs add -q $FILE_SIGN_FILE) + FILE_SIGNATURE=$(ak-ipfs-add $FILE_SIGN_FILE) cat > data < data < block < zblock << EOF @@ -95,7 +95,7 @@ makeZBlock(){ EOF ZBL="zblock" # and we add it on IPFS - ZBLOCK=$(ipfs add -q $ZBL) + ZBLOCK=$(ak-ipfs-add $ZBL) echo $ZBLOCK } @@ -108,11 +108,11 @@ then # We ask for a ZBLOCK or GENESIS to put in the BLOCK PREVIOUS="$2" - ipfs cat "$BLOCK_TO_ADD" + ak-ipfs-cat "$BLOCK_TO_ADD" if [ "$?" == 0 ]; then echo "Nice! We found the block" - 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 @@ -128,11 +128,11 @@ then # python send_as_ak_tx $ZBLOCK # or for "offline" use echo $ZBLOCK > $ZLATEST - ipfs name publish --key=zchain $ZBLOCK > /dev/null 2>&1 - ipfs files mkdir /zarchive > /dev/null 2>&1 - ipfs files cp /zlatest /zarchive/$(date -u +%s)-$(ipfs files stat /zlatest | head -n 1) > /dev/null 2>&1 - ipfs files rm /zlatest > /dev/null 2>&1 - 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-zchain-chk b/bin/ak-zchain-chk index a57e722..946919a 100755 --- a/bin/ak-zchain-chk +++ b/bin/ak-zchain-chk @@ -27,7 +27,7 @@ elif [ ! -z "$1" ] then entrance="$1" else - # By default we enter from the latest block + # By default we ak-enter from the latest block # We can alter this by changing this value entrance="$(cat $ZLATEST)" fi @@ -76,7 +76,7 @@ do # We concatenate the zblock's contents, pipe them through filter # ak-json2bash and output them to tmp-file - ipfs cat $zblock | ak-json2bash > $TEMPASSIN/tmp-zblock + ak-ipfs-cat $zblock | ak-json2bash > $TEMPASSIN/tmp-zblock ak-logthis "[INFO]" "ZBLOCK $zblock READ" # Supposingly you are on a safe environment and you only have @@ -88,7 +88,7 @@ do # Same as above applies to BLOCK and DATA subparts of each ZBLOCK # BLOCKS - ipfs cat $block | ak-json2bash > $TEMPASSIN/tmp-block + ak-ipfs-cat $block | ak-json2bash > $TEMPASSIN/tmp-block source $TEMPASSIN/tmp-block ak-logthis "[INFO]" "BLOCK $block SOURCED" touch $BLOCKDIR/$block @@ -119,7 +119,7 @@ do for value in ${blocks_found[@]} do echo $value - 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 96a59d1..4c7895a 100755 --- a/bin/ak-zchain-rebase +++ b/bin/ak-zchain-rebase @@ -20,24 +20,24 @@ rebase (){ if [ $? != 0 ]; then exit 1; fi echo "Make sure /zarchive folder exists within IPFS FS" - ipfs files mkdir /zarchive + ak-ipfs-files-mkdir /zarchive if [ $? != 0 ]; then echo "Folder already there"; fi echo "Archive the previous ZLATEST" - ipfs files cp /zlatest /zarchive/$(date -u +%s)-$(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" - ipfs files rm /zlatest + ak-ipfs-files-rm /zlatest if [ $? != 0 ]; then exit 1; fi echo "Copying rebased ZLATEST" CZLATEST="$(cat $ZLATEST)" - ipfs files cp /ipfs/$CZLATEST /zlatest + ak-ipfs-files-cp /ipfs/$CZLATEST /zlatest if [ $? != 0 ]; then exit 1; fi echo "Publishing new (rebased) ZLATEST" - ipfs name publish --key=zchain /ipfs/$(cat $ZLATEST) + ak-ipfs-name-publish --key=zchain /ipfs/$(cat $ZLATEST) if [ $? != 0 ]; then exit 1; fi echo "Rebase was successful" diff --git a/bin/ak-zchain-reset b/bin/ak-zchain-reset index 813dc33..e80fabe 100755 --- a/bin/ak-zchain-reset +++ b/bin/ak-zchain-reset @@ -19,24 +19,24 @@ reset (){ if [ $? != 0 ]; then exit 1; fi echo "Make sure /zarchive folder exists within IPFS FS" - ipfs files mkdir /zarchive + ak-ipfs-files-mkdir /zarchive if [ $? != 0 ]; then echo "Folder already there"; fi echo "Archive the previous ZLATEST" - ipfs files cp /zlatest /zarchive/$(date -u +%s)-$(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" - ipfs files rm /zlatest + ak-ipfs-files-rm /zlatest if [ $? != 0 ]; then exit 1; fi echo "Copying reset ZLATEST" CZLATEST="$(cat $ZLATEST)" - ipfs files cp /ipfs/$CZLATEST /zlatest + ak-ipfs-files-cp /ipfs/$CZLATEST /zlatest if [ $? != 0 ]; then exit 1; fi echo "Publishing new (reset) ZLATEST" - ipfs name publish --key=zchain /ipfs/$(cat $ZLATEST) + ak-ipfs-name-publish --key=zchain /ipfs/$(cat $ZLATEST) if [ $? != 0 ]; then exit 1; fi echo "Reset was successful" -- cgit v1.2.3