From 286b71a6ead8c7234cfbc0b8ece05c8239a4f32c Mon Sep 17 00:00:00 2001 From: kaotisk Date: Wed, 29 Mar 2023 23:45:49 +0300 Subject: Renamed everything --- bin/ak-articles | 141 +++++++++++ bin/ak-calculate-size | 9 + bin/ak-categories | 141 +++++++++++ bin/ak-clean | 2 + bin/ak-comments | 118 +++++++++ bin/ak-config | 60 +++++ bin/ak-enter | 277 +++++++++++++++++++++ bin/ak-extract-cids | 8 + bin/ak-file.c | 27 ++ bin/ak-filejoiner | 78 ++++++ bin/ak-filesplitter | 111 +++++++++ bin/ak-find-latest-mined-sblock | 76 ++++++ bin/ak-follow | 14 ++ bin/ak-following | 10 + bin/ak-get-akid | 5 + bin/ak-get-chain-minified | 1 + bin/ak-get-gpg | 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 | 8 + bin/ak-get-only-ipfs-key-values-from-our-zchain | 3 + bin/ak-ipfs-check | 49 ++++ bin/ak-ipfs-starter | 2 + bin/ak-ipns-resolve | 27 ++ bin/ak-json2bash | 11 + bin/ak-logfollow | 2 + bin/ak-logthis | 3 + bin/ak-mempool | 19 ++ bin/ak-miner-script | 50 ++++ bin/ak-mixtapes | 48 ++++ bin/ak-network | 5 + bin/ak-news | 177 +++++++++++++ bin/ak-pack_z_block | 166 ++++++++++++ bin/ak-profile | 227 +++++++++++++++++ bin/ak-reference | 154 ++++++++++++ bin/ak-repositories | 168 +++++++++++++ bin/ak-roadmap | 32 +++ bin/ak-show_sblock | 9 + bin/ak-tempassin | 9 + bin/ak-todos | 140 +++++++++++ bin/ak-transactions | 50 ++++ bin/ak-unfollow | 25 ++ bin/ak-zblock-manipulator | 140 +++++++++++ bin/ak-zchain-chk | 143 +++++++++++ bin/ak-zchain-rebase | 53 ++++ bin/ak-zchain-reset | 52 ++++ bin/ak2html | 45 ++++ bin/akconfig | 60 ----- bin/calculate-size | 9 - bin/clean | 2 - bin/comments | 118 --------- bin/enter | 277 --------------------- bin/extract-cids | 8 - bin/filejoiner | 78 ------ bin/filesplitter | 111 --------- bin/follow | 14 -- bin/following | 10 - bin/get-latest | 2 - bin/ipfs-check | 49 ---- bin/ipfs-starter | 2 - bin/ipns-resolve | 27 -- bin/json2bash | 11 - bin/logfollow | 2 - bin/logthis | 3 - bin/mixtapes | 48 ---- bin/news | 177 ------------- bin/pack_z_block | 166 ------------ bin/profile | 227 ----------------- bin/reference | 154 ------------ bin/repositories | 168 ------------- bin/tempassin | 9 - bin/unfollow | 25 -- bin/zchain-chk | 143 ----------- bin/zchain-rebase | 53 ---- bin/zchain-reset | 52 ---- 75 files changed, 2901 insertions(+), 2005 deletions(-) create mode 100755 bin/ak-articles create mode 100755 bin/ak-calculate-size create mode 100755 bin/ak-categories create mode 100755 bin/ak-clean create mode 100755 bin/ak-comments create mode 100755 bin/ak-config create mode 100755 bin/ak-enter create mode 100755 bin/ak-extract-cids create mode 100644 bin/ak-file.c create mode 100755 bin/ak-filejoiner create mode 100755 bin/ak-filesplitter create mode 100755 bin/ak-find-latest-mined-sblock create mode 100755 bin/ak-follow create mode 100755 bin/ak-following create mode 100755 bin/ak-get-akid create mode 100755 bin/ak-get-chain-minified create mode 100755 bin/ak-get-gpg create mode 100755 bin/ak-get-ipfs-hashes-from-my-zchain create mode 100755 bin/ak-get-latest create mode 100755 bin/ak-get-only-ipfs-key-values-from-our-or-a-zchain create mode 100755 bin/ak-get-only-ipfs-key-values-from-our-zchain create mode 100755 bin/ak-ipfs-check create mode 100755 bin/ak-ipfs-starter create mode 100755 bin/ak-ipns-resolve create mode 100755 bin/ak-json2bash create mode 100755 bin/ak-logfollow create mode 100755 bin/ak-logthis create mode 100755 bin/ak-mempool create mode 100755 bin/ak-miner-script create mode 100755 bin/ak-mixtapes create mode 100755 bin/ak-network create mode 100755 bin/ak-news create mode 100755 bin/ak-pack_z_block create mode 100755 bin/ak-profile create mode 100755 bin/ak-reference create mode 100755 bin/ak-repositories create mode 100755 bin/ak-roadmap create mode 100755 bin/ak-show_sblock create mode 100755 bin/ak-tempassin create mode 100755 bin/ak-todos create mode 100755 bin/ak-transactions create mode 100755 bin/ak-unfollow create mode 100755 bin/ak-zblock-manipulator create mode 100755 bin/ak-zchain-chk create mode 100755 bin/ak-zchain-rebase create mode 100755 bin/ak-zchain-reset create mode 100755 bin/ak2html delete mode 100755 bin/akconfig delete mode 100755 bin/calculate-size delete mode 100755 bin/clean delete mode 100755 bin/comments delete mode 100755 bin/enter delete mode 100755 bin/extract-cids delete mode 100755 bin/filejoiner delete mode 100755 bin/filesplitter delete mode 100755 bin/follow delete mode 100755 bin/following delete mode 100755 bin/get-latest delete mode 100755 bin/ipfs-check delete mode 100755 bin/ipfs-starter delete mode 100755 bin/ipns-resolve delete mode 100755 bin/json2bash delete mode 100755 bin/logfollow delete mode 100755 bin/logthis delete mode 100755 bin/mixtapes delete mode 100755 bin/news delete mode 100755 bin/pack_z_block delete mode 100755 bin/profile delete mode 100755 bin/reference delete mode 100755 bin/repositories delete mode 100755 bin/tempassin delete mode 100755 bin/unfollow delete mode 100755 bin/zchain-chk delete mode 100755 bin/zchain-rebase delete mode 100755 bin/zchain-reset (limited to 'bin') diff --git a/bin/ak-articles b/bin/ak-articles new file mode 100755 index 0000000..18959ad --- /dev/null +++ b/bin/ak-articles @@ -0,0 +1,141 @@ +#!/bin/bash +ZARTICLESDIR="$WORKDIR/articles" +TEMP="/tmp/aktmp" +echo $ZARTICLESDIR +if [ ! -d $ZARTICLESDIR ]; then + mkdir $ZARTICLESDIR + cd $ZARTICLESDIR + git init + echo "Articles repository" > README + echo "Qmetc" >> README + git add README + git commit -m "Initiated articles repository" + echo "zarticlesdir created along with git repo" +else + echo "zarticlesdir 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 +} +create(){ + tempassin $TEMP + pwd + export ARTICLES_FILE="$(date +%Y%m%d_%H%M%S)" + vi $ARTICLES_FILE + 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) + mv $ARTICLES_FILE $ZARTICLESDIR/$TO_FILE + sed -e 's,Qm.*,'"$IPFS_FILE"',g' $ZARTICLESDIR/README + add $ZARTICLESDIR/$TO_FILE + echo "Adding to git repo..." + cd $ZARTICLESDIR + git add $TO_FILE README + git commit -m "Added $TO_FILE with $(head -n 1 $ZARTICLESDIR/$TO_FILE)" + git clean --force + # rm -rf $TEMP +} +index(){ + FILES="$(ls -1 $ZARTICLESDIR)" + i=0 + for FILE in $FILES + do + DATE=$(echo $FILE | cut -d - -f 1 | awk '{print $1}') + TITLE=$(head -n 1 $ZARTICLESDIR/$FILE) + echo $i \| $DATE \| $TITLE + let i+=1 + done +} +title(){ + echo ak-articles-cli + echo "--------------" +} +import(){ + echo "#TODO" + if [ ! -z $1 ] + then + if [ ! -d $1 ] + then + echo "Folder does not exists" + exit 4 + else + echo "Folder $1 exists" + fl="$(ls -1 $1)" + for f in $fl + do + add $1/$f + done + fi + else + echo "No value" + exit 6 + fi + exit 224 +} +add(){ + tempassin + if [ -f $1 ]; then + FILE="$1" + 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_SIGN_FILE=$FILE".asc" + gpg --detach-sign --sign-with $FINGERPRINT --armor --output $FILE_SIGN_FILE $FILE + FILE_SIGNATURE=$(ipfs add -q $FILE_SIGN_FILE) + cat > data < #TODO" + echo "add Creates a data file from the articles file you point to" + echo "create Vim is going to pop up, you will write and save your" + echo " articlesletter and it's going to be saved" + exit 0 +} +title +if [ ! -z $1 ]; then + case $1 in + help) usage; exit;; + index) index; exit;; + import) import $2; exit;; + add) add $2; exit;; + create) create; exit;; + * ) usage;; + esac +else usage +fi diff --git a/bin/ak-calculate-size b/bin/ak-calculate-size new file mode 100755 index 0000000..640d841 --- /dev/null +++ b/bin/ak-calculate-size @@ -0,0 +1,9 @@ +#!/bin/bash +extract-cids > to_stats +sum=0 ; while IFS="" read -r p || [ -n "$p" ] +do + num=$(ipfs block stat $p | grep Size | sed -e 's/Size: //g') + sum=$(expr $sum + $num ) +done < to_stats +echo "Chain is : $sum bytes" +rm to_stats diff --git a/bin/ak-categories b/bin/ak-categories new file mode 100755 index 0000000..cd6f55b --- /dev/null +++ b/bin/ak-categories @@ -0,0 +1,141 @@ +#!/bin/bash +ZNEWSDIR="$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" +else + echo "znewsdir 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 +} +create(){ + tempassin $TEMP + pwd + export NEWS_FILE="$(date +%Y%m%d_%H%M%S)" + vi $NEWS_FILE + 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) + 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 +} +index(){ + FILES="$(ls -1 $ZNEWSDIR)" + i=0 + for FILE in $FILES + do + DATE=$(echo $FILE | cut -d - -f 1 | awk '{print $1}') + TITLE=$(head -n 1 $ZNEWSDIR/$FILE) + echo $i \| $DATE \| $TITLE + let i+=1 + done +} +title(){ + echo ak-news-cli + echo "--------------" +} +import(){ + echo "#TODO" + if [ ! -z $1 ] + then + if [ ! -d $1 ] + then + echo "Folder does not exists" + exit 4 + else + echo "Folder $1 exists" + fl="$(ls -1 $1)" + for f in $fl + do + add $1/$f + done + fi + else + echo "No value" + exit 6 + fi + exit 224 +} +add(){ + tempassin + if [ -f $1 ]; then + FILE="$1" + 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_SIGN_FILE=$FILE".asc" + gpg --detach-sign --sign-with $FINGERPRINT --armor --output $FILE_SIGN_FILE $FILE + FILE_SIGNATURE=$(ipfs add -q $FILE_SIGN_FILE) + cat > 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" + echo " newsletter and it's going to be saved" + exit 0 +} +title +if [ ! -z $1 ]; then + case $1 in + help) usage; exit;; + index) index; exit;; + import) import $2; exit;; + add) add $2; exit;; + create) create; exit;; + * ) usage;; + esac +else usage +fi diff --git a/bin/ak-clean b/bin/ak-clean new file mode 100755 index 0000000..c30324e --- /dev/null +++ b/bin/ak-clean @@ -0,0 +1,2 @@ +#!/bin/bash +rm -rf /tmp/aktmp* diff --git a/bin/ak-comments b/bin/ak-comments new file mode 100755 index 0000000..fc226b2 --- /dev/null +++ b/bin/ak-comments @@ -0,0 +1,118 @@ +#!/bin/bash +ZCOMMENTSDIR="$WORKDIR/comments" +TEMP="/tmp/aktmp" +if [ ! -d $ZCOMMENTSDIR ]; then + mkdir $ZCOMMENTSDIR + cd $ZCOMMENTSDIR + git init + logthis "[INFO]" "zcommentsdir created along with git repo" +else + logthis "[INFO]" "zcommentsdir 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 +} +create(){ + if [ ! -z $1 ] + then + REFER_TO="$1" + else + logthis "[ERROR]" "No reference given" + echo "[ERROR]" "No reference given" + exit 1 + fi + tempassin $TEMP + export COMMENTS_FILE="$(date -u +%s)" + vi $COMMENTS_FILE + echo "Renaming..." + TO_FILE=$COMMENTS_FILE + IPFS_FILE=$(ipfs add -q $COMMENTS_FILE) + mv $COMMENTS_FILE $ZCOMMENTSDIR/$TO_FILE + add $TO_FILE + 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 + for FILE in $FILES + do + DATE=$(echo $FILE | cut -d - -f 1 | awk '{print $1}') + TITLE=$(head -n 1 $ZCOMMENTSDIR/$FILE) + echo $i \| $DATE \| $TITLE + let i+=1 + done +} +title(){ + echo comments +} +add(){ + tempassin + if [ -f "$ZCOMMENTSDIR/$1" ]; then + FILE=$ZCOMMENTSDIR/$1 + echo "Adding comments from " $FILE + DATETIME="$1" + FILE_IPFS_HASH=$(ipfs add -q $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) + cat > data < Creates a data file from the comments file you point to" + echo "create Vim is going to pop up, you will write and save your" + echo " commentsletter and it's going to be saved" + exit 0 +} + +if [ ! -z $1 ]; then + case $1 in + help) usage; exit;; + index) index; exit;; + add) add $2 $3; exit;; + create) create $2; exit;; + * ) usage;; + esac +else usage +fi diff --git a/bin/ak-config b/bin/ak-config new file mode 100755 index 0000000..bc06e49 --- /dev/null +++ b/bin/ak-config @@ -0,0 +1,60 @@ +#!/bin/bash +PROGRAM="$(basename $0)" +title(){ + echo "Arching Kaos Configuration Tool" + echo "===============================" +} +usage(){ + title + echo "" + echo "Usage: $PROGRAM [ | ]" + echo "" + echo " show Show current configuration (from FileSystem)" + echo " publish Publish current configuration" + echo " get-published Get published ak-config (from IPFS)" + echo "" + exit 0 +} + +show(){ + echo ' +{ + "profile":'$(profile index | json_pp)', + "genesis":"'$(cat $HOME/.arching-kaos/config/zgenesis)'", + "gpg":"'$GPG_PUB_KEY'", + "zchain":"'$(cat $HOME/.arching-kaos/config/zchain)'" +}'; +} + +publish(){ + show | json_pp > tmpfile + ipfs name publish --key=ak-config /ipfs/$(ipfs add -q tmpfile) + if [ "$?" != 0 ] + then + echo -e "\033[0;34mError on publishing\033[0;0m\nYour information:\n" + cat tmpfile + exit 1 + fi + rm tmpfile +} + +published(){ + 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) +rm $KEY + +if [ ! -z $1 ]; then + case $1 in + show) show;exit;; + publish) publish;exit;; + get-published) published;exit;; + *) usage;exit;; + esac +else + usage +fi diff --git a/bin/ak-enter b/bin/ak-enter new file mode 100755 index 0000000..584d0e0 --- /dev/null +++ b/bin/ak-enter @@ -0,0 +1,277 @@ +#!/bin/bash +# 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 +# $ZLATEST environment variable. +# +# enter [-n IPNS_LINK] +# enter [IPFS CID] +# enter -nV +# enter +# +# Returns a JSON array representing the chain retrieved. +# Logs messages to $LOGSFILE. + +PROGRAM="$(basename $0)" + +logit(){ + logthis "<$PROGRAM>" "$1" "$2" +} + +usage(){ + echo "$PROGRAM - Crawl an arching kaos chain" + echo "-----------------------------------" + echo "Usage:" + echo " --help, -h Print this help and exit" + echo " --chain , -n Crawl specified chain" + echo " --no-verify, -nV Don't verify signatures" + echo " Specify IPFS CID for entrance" + echo "" + echo "Note that combined flags don't work for now" + echo "Running with no flags crawls your chain based on ZLATEST environment variable" +} +# 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" ] && [ "$1" == "-nV" ] || [ "$1" == "--no-verify" ] +then + verify=0 + entrance="$(cat $ZLATEST)" +elif [ ! -z "$1" ] && [ "$1" == "-n" ] +then + entrance="$(ipns-resolve $2)" +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 enter from the latest block + # We can alter this by changing this value + entrance="$(cat $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 $ZGENESIS)" + +# We assume that we found the entrance inside a block, hence +# ZBLOCK is labeled as previous +zblock="$entrance" + +# Enter temp folder +TEMPASSIN="/tmp/aktmp_$(date -u +%s)" +mkdir $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 json2bash and output + # them to tmp-file + # + # We check if any $zblock at all + ipfs --timeout=10s 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 + ipfs --timeout=10s cat $zblock | json_pp > /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 + ipfs --timeout=10s cat $zblock | json2bash > $TEMPASSIN/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 + 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=' $TEMPASSIN/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 $TEMPASSIN/tmp-zblock + logit "[INFO]" "ZBLOCK SOURCED" + + # Same as above applies to BLOCK and DATA subparts of each ZBLOCK + # BLOCKS + echo -n '"block":"'$block'",' + ipfs --timeout=10s cat $block | json2bash > $TEMPASSIN/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 + if [ "$?" -ne 0 ] + then + logit "[ERROR]" "BLOCK $block is NOT a valid block" + exit 1 + fi + logit "[INFO]" "BLOCK $block is a block" + + source $TEMPASSIN/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 + 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 + 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" + 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 + #ipfs --timeout=10s 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 + #echo "$zblock after $previous" + logit "[INFO]" "Found a previous block for $zblock: $previous" + echo -n '"previous":"'$previous'"},' + zblock=$previous + fi + + # Now check if it is equal to the seed + # which apparently means we reached the seed. + elif [ "$zblock" == "$seed" ] + then + #echo "$zblock is GENESIS block" + #echo '"'$zblock'":{ "GENESIS":"GENESIS"}] ' + echo -n '{"genesis":"genesis"}]' + logit "[INFO]" "Reached $seed, counted $counter zblocks." + 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-extract-cids b/bin/ak-extract-cids new file mode 100755 index 0000000..06b7ebc --- /dev/null +++ b/bin/ak-extract-cids @@ -0,0 +1,8 @@ +#!/bin/bash +# +# Extracts unique IPFS CIDs from an entered zchain +# +# Previously: +# 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 diff --git a/bin/ak-file.c b/bin/ak-file.c new file mode 100644 index 0000000..3d2ae17 --- /dev/null +++ b/bin/ak-file.c @@ -0,0 +1,27 @@ +/* + * ===================================================================================== + * + * Filename: file.c + * + * Description: + * + * Version: 1.0 + * Created: 08/12/22 07:23:49 + * Revision: none + * Compiler: gcc + * + * Author: Kaotisk Hund (kh), kaotisk@arching-kaos.org + * Company: ArchingKaos.Com + * + * ===================================================================================== + */ + +#include + +int main(int argc, char **argv) +{ + (void)argc; + (void)argv; + printf("printf used\n"); + return 0; +} diff --git a/bin/ak-filejoiner b/bin/ak-filejoiner new file mode 100755 index 0000000..88d965c --- /dev/null +++ b/bin/ak-filejoiner @@ -0,0 +1,78 @@ +#!/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="$WORKDIR/fmp" + +CHKDIR="$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-filesplitter b/bin/ak-filesplitter new file mode 100755 index 0000000..0f7919b --- /dev/null +++ b/bin/ak-filesplitter @@ -0,0 +1,111 @@ +#!/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 + +CHKDIR="$WORKDIR/ftr/" +FILEMAPSDIR="$WORKDIR/fmp/" +TEMPORARYDIR="/tmp/tltmp" +TECHDIR="/tmp/tltmp/chks/" +CURRENTDIR="$(pwd)/" +# BSFILE="$(basename $1)" +# echo $CURRENTDIR $BSFILE + +logit(){ + logthis "<$PROGRAM>" "$1" "$2" +} + +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 +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 +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 + +CHECKSUM=$(sha512sum "$FILE"|awk '{print $1}') +split -b 1048576 --additional-suffix ".chk" -d "$FILE" "$TECHDIR$(basename "$FILE")-" + +cd $TECHDIR + +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 + +sh $TEMPORARYDIR/cmd_queue.sh +rm $TEMPORARYDIR/cmd_queue.sh + +echo "$CHECKSUM $(basename "$FILE")" >> $TEMPORARYDIR/map + +MAPFILEHASH="$(sha512sum $TEMPORARYDIR/map | awk '{ print $1 }')" + +`sha512sum $TEMPORARYDIR/map | awk '{print "mv " $2 " '$FILEMAPSDIR'" $1}'` + +rm -rf $TEMPORARYDIR + +echo "$MAPFILEHASH" diff --git a/bin/ak-find-latest-mined-sblock b/bin/ak-find-latest-mined-sblock new file mode 100755 index 0000000..b9be842 --- /dev/null +++ b/bin/ak-find-latest-mined-sblock @@ -0,0 +1,76 @@ +#!/bin/bash +MINED_BLOCKS_DIR="/home/$USER/.arching-kaos/mined_blocks" +cd $MINED_BLOCKS_DIR +PROGRAM="$(basename $0)" +declare -A counters +logitnowint(){ + logthis "<$PROGRAM>" "$1" "$2" +} +further(){ + # logitnowint "[INFO]" "Diving into $1" + lookfor $1 +} + +lookfor(){ + echo -n $1 | grep -e '[0-9a-f]\{128\}' > /dev/null + if [ ! $? = 0 ] + then + logitnowint "[ERROR]" "Oops!!! The argument passed, does not match the regular expression!" + else + counters[$CHAIN_PARENT]="$(expr ${counters[$CHAIN_PARENT]} + 1)" + if [ ! $? = 0 ] + then + echo "$1, $counters[$1]" + exit 1 + fi + logitnowint "[INFO]" "Accessing file: $1" + # echo "$1 file:" + # cat "$1" | jq + NEXT_TARGET="$(cat "$1" | jq | grep previous | tr -d ' ' | sed -e 's/previous//g; s/[",:]//g;')" + if [ ! "$NEXT_TARGET" = "" ] + then + logitnowint "[INFO]" "Found previous: $NEXT_TARGET" + if [ ! -f "$NEXT_TARGET" ] + then + logitnowint "[WARNING]" "Could not find $NEXT_TARGET" + else + further "$NEXT_TARGET" + fi + else + + logitnowint "[WARNING]" "No next target found. So long for $1" + fi + fi +} + + +ls -1 > tmplistblock +while IFS="" read -r p || [ -n "$p" ] +do +# if [ ! "$p" = "" ] && [ ! "$p" = "tmplistblock" ] + if [ "$(echo $p | tr -d '\n' | wc -c)" = 128 ] + then + logitnowint "[INFO]" "Investigating $p..." + export CHAIN_PARENT="$p" + counters[$CHAIN_PARENT]=1 + lookfor "$p" + else + logitnowint "[WARNING]" "Nothing to do with $p" + fi +done < tmplistblock +rm tmplistblock +max=0 +max_holder=0 +for value in "${!counters[@]}" +do +# echo "${value} : ${counters[${value}]}" + if [ ${counters[${value}]} -gt $max ] + then + max="${counters[${value}]}" + max_holder="${value}" + logitnowint "[INFO]" "New MAX $max on $max_holder" + + + fi +done +echo '{"latest_block":"'$max_holder'"}' diff --git a/bin/ak-follow b/bin/ak-follow new file mode 100755 index 0000000..76851e0 --- /dev/null +++ b/bin/ak-follow @@ -0,0 +1,14 @@ +#!/bin/bash +FOLLOWING="$HOME/.arching-kaos/following" +if [ ! -z $1 ] +then + echo $1 >> $FOLLOWING + IPFS=$(ipfs add -q $FOLLOWING) + if [ $? == 0 ] + then + profile set following $IPFS + else + logthis "Addition aborted" + exit 1 + fi +fi diff --git a/bin/ak-following b/bin/ak-following new file mode 100755 index 0000000..b333e50 --- /dev/null +++ b/bin/ak-following @@ -0,0 +1,10 @@ +#!/bin/bash +FOLLOWING="$HOME/.arching-kaos/following" +if [ -f $FOLLOWING ] +then + cat $FOLLOWING +else + logthis "No following file, creating" + touch $FOLLOWING + echo "None found" +fi diff --git a/bin/ak-get-akid b/bin/ak-get-akid new file mode 100755 index 0000000..17dcf74 --- /dev/null +++ b/bin/ak-get-akid @@ -0,0 +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\///' + diff --git a/bin/ak-get-chain-minified b/bin/ak-get-chain-minified new file mode 100755 index 0000000..259cc36 --- /dev/null +++ b/bin/ak-get-chain-minified @@ -0,0 +1 @@ +enter | jq --compact-output diff --git a/bin/ak-get-gpg b/bin/ak-get-gpg new file mode 100755 index 0000000..14512f3 --- /dev/null +++ b/bin/ak-get-gpg @@ -0,0 +1,2 @@ +#!/bin/bash +akconfig show|jq| grep gpg | sed -e 's/"gpg": "//g; s/[," ]//g' diff --git a/bin/ak-get-ipfs-hashes-from-my-zchain b/bin/ak-get-ipfs-hashes-from-my-zchain new file mode 100755 index 0000000..db90ecb --- /dev/null +++ b/bin/ak-get-ipfs-hashes-from-my-zchain @@ -0,0 +1,2 @@ +#!/bin/bash +enter | json_pp | 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 new file mode 100755 index 0000000..e770d1c --- /dev/null +++ b/bin/ak-get-latest @@ -0,0 +1,2 @@ +#!/bin/bash +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 new file mode 100755 index 0000000..2b9f580 --- /dev/null +++ b/bin/ak-get-only-ipfs-key-values-from-our-or-a-zchain @@ -0,0 +1,8 @@ +#!/bin/bash +# 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' +else + 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 new file mode 100755 index 0000000..8334f66 --- /dev/null +++ b/bin/ak-get-only-ipfs-key-values-from-our-zchain @@ -0,0 +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 diff --git a/bin/ak-ipfs-check b/bin/ak-ipfs-check new file mode 100755 index 0000000..0e53599 --- /dev/null +++ b/bin/ak-ipfs-check @@ -0,0 +1,49 @@ +#!/bin/bash +PROGRAM="$(basename $0)" +logit(){ + logthis "<$PROGRAM>" "$1" "$2" +} + + +ipfs files ls /zarchive > /dev/null +if [ $? != 0 ] +then + logit "[ERROR]" "/zarchive is missing" +else + logit "[INFO]" "/zarchive OK" +fi + + +ipfs files ls /zlatest > /dev/null +if [ $? != 0 ] +then + logit "[ERROR]" "/zlatest is missing" +else + logit "[INFO]" "/zlatest is OK" +fi + +ipfs key list | grep zchain > /dev/null +if [ $? != 0 ]; then + logit "[WARNING]" "zchain key is missing" + 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 + +ipfs key list | grep ak-config > /dev/null +if [ $? != 0 ]; then + logit "[WARNING]" "ak-config key is missing" + 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 diff --git a/bin/ak-ipfs-starter b/bin/ak-ipfs-starter new file mode 100755 index 0000000..5cab1c3 --- /dev/null +++ b/bin/ak-ipfs-starter @@ -0,0 +1,2 @@ +#!/bin/bash +screen -dmS ipfs-daemon ipfs daemon diff --git a/bin/ak-ipns-resolve b/bin/ak-ipns-resolve new file mode 100755 index 0000000..6ea3799 --- /dev/null +++ b/bin/ak-ipns-resolve @@ -0,0 +1,27 @@ +#!/bin/bash +PROGRAM="$(basename $0)" +usage(){ + echo "$PROGRAM - Resolves IPNS to IPFS" + echo "------------------------------------" + echo "Usage:" + echo " $PROGRAM " + echo "" + echo "Returns the resolved IPFS CIDv0" +} +logit(){ + logthis "<$PROGRAM>" "$1" "$2" +} +if [ ! -z $1 ] +then + rsld=$(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 + usage +fi + diff --git a/bin/ak-json2bash b/bin/ak-json2bash new file mode 100755 index 0000000..347ca93 --- /dev/null +++ b/bin/ak-json2bash @@ -0,0 +1,11 @@ +#!/bin/bash +# +# json2bash +# +# Kaotisk Hund +# +# Strips " , { } from input and replaces ":" with = +# +# Usage: +# ipfs cat | 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-logfollow b/bin/ak-logfollow new file mode 100755 index 0000000..f9f6ec9 --- /dev/null +++ b/bin/ak-logfollow @@ -0,0 +1,2 @@ +#!/bin/bash +tail -f $LOGSFILE diff --git a/bin/ak-logthis b/bin/ak-logthis new file mode 100755 index 0000000..347fd0b --- /dev/null +++ b/bin/ak-logthis @@ -0,0 +1,3 @@ +#!/bin/bash +echo "$(date -u +%s)" "$1" "$2" "$3" >> $LOGSFILE + diff --git a/bin/ak-mempool b/bin/ak-mempool new file mode 100755 index 0000000..b0d6d4b --- /dev/null +++ b/bin/ak-mempool @@ -0,0 +1,19 @@ +#!/bin/bash +# Assumptions: +# I suppose each ak node is connected to some IP. +# They also run IPFS. +# They also are a part of our swarm. +# So should we ask for our peers? + +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 +done < tmp_peers + +rm tmp_peers + diff --git a/bin/ak-miner-script b/bin/ak-miner-script new file mode 100755 index 0000000..5e686c5 --- /dev/null +++ b/bin/ak-miner-script @@ -0,0 +1,50 @@ +#!/bin/bash +PROGRAM="$(basename $0)" +proofofwork(){ + TEST="$1" + PRE="$2" + MINER="$3" + i=1 + l=1; while [ $l = 1 ] + do + TIMESTAMP="$(date -u +%s)" + SHA="$(echo $TEST'"zpairs":'$(cat /home/$USER/.arching-kaos/mempool/szch)',"nonce":"'$i'","previous":"'$PRE'","timestamp":"'$TIMESTAMP'","miner":"'$MINER'","reward":"40"}' | sha512sum | awk '{ print $1 }')" + + # Static difficulty for securing the sblock + echo $SHA | grep -e '^000' + if [ "$?" == 0 ] ; + then + echo "SHA512 is $SHA" + echo "Mined block:" + echo $TEST'"zpairs":'$(cat /home/$USER/,arching-kaos/mempool/szch)',"nonce":"'$i'","previous":"'$PRE'","timestamp":"'$TIMESTAMP'","miner":"'$MINER'","reward":"40"}' | jq --compact-output > /home/$USER/.arching-kaos/mined_blocks/$SHA + cat /home/$USER/.arching-kaos/mined_blocks/$SHA | jq + # exit 0 + # Instead of exiting, we will now sleep for 60 seconds + # after that we continue mining on top of the just mined + # block. + sleep 60 + proofofwork "$1" "$SHA" "$MINER" + fi + i=$(expr $i + 1); + done +} + +usage(){ + echo "$PROGRAM " + echo " hit enter after that !!! " +} + +if [ -z "$1" ] ; +then + usage + exit; +elif [ ! -z "$1" ] && [ ! -z "$2" ] && [ ! -z "$3" ] +then + proofofwork "$1" "$2" "$3"; +else + usage +fi + +exit + + diff --git a/bin/ak-mixtapes b/bin/ak-mixtapes new file mode 100755 index 0000000..aefaf26 --- /dev/null +++ b/bin/ak-mixtapes @@ -0,0 +1,48 @@ +#!/bin/bash +# The following creates a mixtape data message +# We can extend it by calling the pack_z_block.sh mixtape/add data + +usage(){ + title + echo "$0 - artist title file" +} + +main(){ + echo $MIXTAPE_FILE "by" $MIXTAPE_ARTIST "named as" $MIXTAPE_TITLE + + MIXTAPE_IPFS_HASH=$(ipfs add -q $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) + + cat > data < README + echo "Qmetc" >> README + git add README + git commit -m "Initiated news repository" + echo "znewsdir created along with git repo" +else + echo "znewsdir 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 +} +create(){ + tempassin $TEMP + curpath="$(pwd)" + export NEWS_FILE="$(date +%Y%m%d_%H%M%S)" + vi $NEWS_FILE + 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) + 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(){ + FILES="$(ls -1 $ZNEWSDIR)" + i=0 + for FILE in $FILES + do + DATE=$(echo $FILE | cut -d - -f 1 | awk '{print $1}') + TITLE=$(head -n 1 $ZNEWSDIR/$FILE) + echo $i \| $DATE \| $TITLE + let i+=1 + done +} +title(){ + echo ak-news-cli + echo "--------------" +} +import(){ + echo "#TODO" + if [ ! -z $1 ] + then + if [ ! -d "$1" ] + then + echo $1 + echo "Folder does not exist" + exit 4 + else + echo "Folder $1 exists" + fl="$(ls -1 $1)" + for f in $fl + do + echo $1 $f + add2 "$1/$f" + done + fi + else + echo "No value" + exit 6 + fi + exit 224 +} +add2(){ + tempassin + if [ -f $1 ]; then + FILE="$1" + cp $FILE $ZNEWSDIR + 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_SIGN_FILE=$FILE".asc" + gpg --detach-sign --sign-with $FINGERPRINT --armor --output $FILE_SIGN_FILE $FILE + FILE_SIGNATURE=$(ipfs add -q $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" + echo " newsletter and it's going to be saved" + exit 0 +} +title +if [ ! -z $1 ]; then + case $1 in + help) usage; exit;; + index) index; exit;; + import) import $2; exit;; + add) add2 $2; exit;; + create) create; exit;; + * ) usage;; + esac +else usage +fi diff --git a/bin/ak-pack_z_block b/bin/ak-pack_z_block new file mode 100755 index 0000000..71aa4b7 --- /dev/null +++ b/bin/ak-pack_z_block @@ -0,0 +1,166 @@ +#!/bin/bash +# This file describe the structure of the ArchingKaos messages in their basis. +# +# As previously thought, we exchange one IPFS hash through whatever means we can. +# +# GPG is mentioned as a signing algorithm for encryption, decryption and signing. +# Let's say we have a file named as `example` +# +# We can extend this with calling the encoder and further send the transaction +# + +#FINGERPRINT="CHANGE THIS TO YOUR DEFAULT FINGERPRINT" +# We acquire the GPG fingerprint by email address +# The following example finds kaos@kaos.kaos' GPG fingerprint like this +# FINGERPRINT="$(gpg2 --list-keys | grep kaos@kaos.kaos -1 | head -n1 | awk '{print $1}')" + +PROGRAM="$(basename $0)" + +# Logging patch +logit(){ + logthis "<$PROGRAM>" "$1" "$2" +} + +# Below, the usage information +usage(){ + echo "" + echo "Usage:" + echo "$PROGRAM " + echo "" + echo " Creates and publishes a ZBLOCK based on ACTION and DATA file." + echo "" + echo " action An action for the render to grasp" + echo " data_file A data file that according to the action is valid" + echo "" + echo "#TODO:" + echo "implement flags to change the inputs so we can manufacture" + echo "zblocks directly from IPFS hashes refering to blocks." +} + + +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 + while IFS="" read -r p || [ -n "$p" ] + do + if [ "$p" == "$TO_CHECK" ] + then + logit "[ERROR]" "Value $TO_CHECK already mentioned on the zchain" + exit 1 + fi + done < tempisalreadythere + rm tempisalreadythere + + logit "[INFO]" "We are doing" $ACTION "with content" $MESSAGE + # We add it to IPFS + MESSAGE_HASH=$(ipfs add -q $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) + + # 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) + + # Acquire last block of information, to chain this one with previous posted + PREVIOUS=$(ipfs files stat /zlatest | head -n 1) + + # We create a block of json like this: + cat > block < zblock << EOF +{ + "block":"$BLOCK", + "block_signature":"$BLOCK_SIGNATURE" +} +EOF + ZBL="zblock" + # and we add it on IPFS + ZBLOCK=$(ipfs add -q $ZBL) + echo $ZBLOCK +} + +if [ ! -z $2 ]; +then + PWD="$(pwd)" + MESSAGE="$PWD/$2" + ACTION="$1" + if [ -f "$MESSAGE" ]; then + main + else + logit "[ERROR]" "File does not exist. Aborting..." + exit 1 + fi + + # cat $PWD/zblock | json_pp + # Optional or extending with + # python send_as_ak_tx $ZBLOCK + # or for "offline" use + echo $ZBLOCK > $ZLATEST + 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 + if [ "$?" -ne 0 ] + then + logit "[WARNING]" "/zarchive does not exist" + 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 + if [ "$?" -ne 0 ] + then + logit "[ERROR]" "Could not back up previous /zlatest" + exit 1 + fi + 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 + if [ "$?" -ne 0 ] + then + logit "[ERROR]" "Could not copy $ZBLOCK to /zlatest" + exit 1 + fi +else + usage + exit 0 +fi + diff --git a/bin/ak-profile b/bin/ak-profile new file mode 100755 index 0000000..ed83d29 --- /dev/null +++ b/bin/ak-profile @@ -0,0 +1,227 @@ +#!/bin/bash +PROGRAM="$(basename $0)" +ZPROFILEDIR="$WORKDIR/profile" +TEMP="/tmp/aktmp" + +# Outputs to log file in the classic format :) +logit(){ + logthis "<$PROGRAM>" "$1" "$2" +} + +# Whatever the command is, we check if $ZPROFILEDIR is there. +# If NOT we create it and we change dir there. +if [ ! -d $ZPROFILEDIR ]; then + mkdir $ZPROFILEDIR + cd $ZPROFILEDIR + logit "[INFO]" "zprofiledir created" +else + logit "[INFO]" "zprofiledir 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" +} + +# This is working with DATA blocks. DATA that matched profile/add ACTION +# +# The profile settings/configuration is part of the blockchain produced. +# Hence, we need a specific DATA block that actually has the announcement of a +# {"key":"value"} pair. +show(){ + if [ ! -z $1 ] + then + logit "[INFO]" "Working with $1" + ipfs cat $(echo $(ipfs cat $1) | jq '.ipfs' -r) + else + echo "No DATA provided" + exit 1 + fi +} + +# This should retrieve a specific value from our profile otherwise it dumps the +# whole profile values. +propget(){ + if [ ! -z $1 ] + then + if [ ! -f $ZPROFILEDIR/$1 ] + then + echo "property not found" + else + cat $ZPROFILEDIR/$1 + fi + else + echo "No particular property... indexing" + index + fi +} + +propwrite(){ + cat > $ZPROPERTY_FILE << EOF +{ + "$ZPROPERTY_KEY":"${ZPROPERTY_VALUE}" +} +EOF + if [ $? == 0 ] + then + echo "Added successfully... proceeding" + IPFS_FILE=$(ipfs add -q $ZPROPERTY_FILE) + echo "Prop writting,,, $IPFS_FILE" + add $ZPROPERTY_KEY + echo "Adding to git repo..." + cd $ZPROFILEDIR + else + echo "Couldn't write to file $ZPROFILEDIR/$TO_FILE" + exit 1 + fi +} + +propset(){ + if [ ! -z $1 ] + then + ZPROPERTY_FILE="$ZPROFILEDIR/$1" + ZPROPERTY_KEY="$1" + if [ ! -f $ZPROPERTY_FILE ] + then + echo "No such property: $ZPROPERTY_KEY ... creating" + ZPROPERTY_VALUE="$2" + if [ ! -z "$ZPROPERTY_VALUE" ] + then + touch $ZPROPERTY_FILE + echo "$ZPROPERTY_KEY = $ZPROPERTY_VALUE in file $ZPROPERTY_FILE" + propwrite #"$ZPROPERTY_FILE" "${ZPROPERTY_VALUE}" + else + echo "No value for $1" + fi + else + echo found $ZPROPERTY_FILE + echo "$ZPROPERTY_KEY = $ZPROPERTY_VALUE in file $ZPROPERTY_FILE" + ZPROPERTY_VALUE="$2" + read -p "Overwrite $1 with ${ZPROPERTY_VALUE} ? " yn + case $yn in + [Yy]* ) propwrite;;# "$ZPROPERTY_" "${ZPROPERTY_VALUE}";; + [Nn]* ) exit 130;; + * ) echo "Answer please";; + esac + echo $IPFS_FILE + show $IPFS_FILE + fi + else + echo "conditions unmet" + exit 244 + fi +} +index(){ + FILES="$(ls -1 $ZPROFILEDIR)" + i=0 + echo -n "{" + for FILE in $FILES + do + if [ $FILE != "README" ]; then + if [ $i != "0" ]; then + echo -n ","; + fi + PROP=$(echo $(cat $ZPROFILEDIR/$FILE | json2bash) | cut -d '=' -f 1 | awk '{print $0}') + VAL=$(echo $(cat $ZPROFILEDIR/$FILE | json2bash) | cut -d '=' -f 2 | awk '{print $1}') + echo -n '"'$PROP'":"'$VAL'"'; + let i+=1 + fi + done + echo "}" +} +import(){ + if [ ! -z $1 ] + then + if [ ! -d $1 ] + then + echo "Profile folder check: Folder $1 does not exist. Stopping..." + exit 4 + else + echo "Profile folder check: Folder $1 exists." + fl="$(ls -1 $1)" + for f in $fl + do + add $1/$f + done + fi + else + echo "No value" + exit 6 + fi + exit 224 +} + +# Adds a file as a profile/add ACTION on the zchain. +add(){ + tempassin + if [ -f $ZPROFILEDIR/$1 ]; then + FILE="$ZPROFILEDIR/$1" + echo "Adding from " $FILE + FILE_IPFS_HASH=$(ipfs add -q $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) + cat > data <\t\t\tShow profile entry from specified DATA IPFS CIDv0" + echo -e "\tset \t\tSets a profile value" + echo -e "\tget \t\t\tGets a profile value from the on-disk file." + echo "" + echo "Advanced (use with caution may produce duplicate entries):" + echo -e "\tadd \t\t\tCreates a data file from the profile file you point to (file should already be in ZPROFILEDIR." + echo -e "\timport \t\t\tImport a folder to zchain #TODO" + echo "" + exit 0 +} +if [ ! -z $1 ]; then + case $1 in + help) usage; exit;; + index) index; exit;; + show) show $2; exit;; + import) import $2; exit;; + add) add $2; exit;; + set) propset $2 "$3"; exit;; + get) propget $2; exit;; + * ) usage;; + esac +else usage +fi diff --git a/bin/ak-reference b/bin/ak-reference new file mode 100755 index 0000000..59eaa04 --- /dev/null +++ b/bin/ak-reference @@ -0,0 +1,154 @@ +#!/bin/bash +ZREFERENCESDIR="$WORKDIR/references" +TEMP="/tmp/aktmp" +echo $ZREFERENCESDIR +if [ ! -d $ZREFERENCESDIR ]; then + mkdir $ZREFERENCESDIR + cd $ZREFERENCESDIR + git init + echo "References repository" > README + echo "Qmetc" >> README + git add README + git commit -m "Initiated references repository" + echo "zreferencesdir created along with git repo" +else + logthis "zreferencesdir 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 +} +create(){ + tempassin $TEMP + #pwd + export REFERENCEFILE="$(date -u +%s)" + if [ ! -z $1 ] && [ ! -z $2 ] + then + TO_FILE="$(date -u +%s)-$1-$2" + cat > $REFERENCEFILE << EOF +$1 +$2 +EOF + + else + vi $REFERENCEFILE + fi + REFERENCE="$(head -n 1 $REFERENCEFILE)" + REFER_TO="$(tail -n 1 $REFERENCEFILE)" + TO_FILE="$REFERENCEFILE-$REFERENCE-$REFER_TO" + mv $REFERENCEFILE $ZREFERENCESDIR/$TO_FILE + echo $TO_FILE + IPFS_FILE=$(ipfs add -q $ZREFERENCESDIR/$TO_FILE) + sed -e 's,Qm.*,'"$IPFS_FILE"',g' $ZREFERENCESDIR/README + add $ZREFERENCESDIR/$TO_FILE + echo "Adding to git repo..." + cd $ZREFERENCESDIR + git add $TO_FILE README + git commit -m "Added $TO_FILE with $(head -n 1 $ZREFERENCESDIR/$TO_FILE)" + git clean --force +} +index(){ + FILES="$(ls -1 $ZREFERENCESDIR)" + i=0 + for FILE in $FILES + do + DATE=$(echo $FILE | cut -d - -f 1 | awk '{print $1}') + TITLE=$(head -n 1 $ZREFERENCESDIR/$FILE) + REFE=$(tail -n 1 $ZREFERENCESDIR/$FILE) + echo $i \| $DATE \| $TITLE \| $REFE + let i+=1 + done +} +title(){ + echo ak-references-cli + echo "--------------" +} +import(){ + echo "#TODO" + if [ ! -z $1 ] + then + if [ ! -d $1 ] + then + echo "Folder does not exists" + exit 4 + else + echo "Folder $1 exists" + fl="$(ls -1 $1)" + for f in $fl + do + add $1/$f + done + fi + else + echo "No value" + exit 6 + fi + exit 224 +} +add(){ + tempassin + if [ -f $1 ]; then + FILE="$1" + echo "Adding references from " $FILE + DATETIME=$(echo $FILE | cut -d - -f 1 | awk '{print $1}') + #FILE=$(head -n 1 $FILE) + FILE_IPFS_HASH=$(ipfs add -q $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) + cat > data < #TODO" + echo "add Creates a data file from the references file you point to" + echo "create [ref] [to] Vim is going to pop up, you will write and save your" + echo " referencesletter and it's going to be saved" + exit 0 +} + +if [ ! -z $1 ]; then + case $1 in + help) usage; exit;; + index) index; exit;; + import) import $2; exit;; + add) add $2; exit;; + create) create $2 $3; exit;; + * ) usage;; + esac +else usage +fi diff --git a/bin/ak-repositories b/bin/ak-repositories new file mode 100755 index 0000000..3cd415f --- /dev/null +++ b/bin/ak-repositories @@ -0,0 +1,168 @@ +#!/bin/bash +REPODIR="$HOME/projects" +BAREDIR="$HOME/bare" +REPOSTORE="$HOME/.arching-kaos/repostore" +if [ ! -d $BAREDIR ]; then mkdir $BAREDIR; fi +if [ ! -d $REPODIR ]; then echo "no $REPODIR" && exit; fi +if [ ! -f $REPOSTORE ]; then touch $REPOSTORE; fi +import(){ + REPOS="$(ls -1 $REPODIR)" + for PROJECT in $REPOS + do + cd $BAREDIR + # Can be as well be + # git clone --bare $REPODIR/$PROJECT/.git + # or whatever form git let's you use + git clone --bare http://git.h.kaotisk-hund.com/$PROJECT/.git + if [ $? == 0 ] + then + cd $PROJECT.git + git repack -a + IPFS="$(ipfs add -Qr .)" + ipfs key gen "$PROJECT.git" + ipfs name publish --key="$PROJECT.git" /ipfs/$IPFS + cd $HOME/bare + else + echo "$PROJECT not a git repo" + fi + done +} + +update(){ + if [ ! -z $1 ] + then + USING="$1" + REPO="$REPODIR/$1/.git" + BARE="$BAREDIR/$1.git" + BARENAME="$1.git" + if [ -d $BARE ] + then + cd $BARE + git pull + git repack -a + IPFS="$(ipfs add -Qr .)" + ipfs name publish --key="$BARENAME" /ipfs/$IPFS + echo "DONE" + else + echo "NO BARE TO UPDATE" + echo "updating all..." + fi + else + BARES="$(ls