diff options
-rwxr-xr-x | Makefile | 2 | ||||
-rwxr-xr-x | bin/ak-data-expand | 156 | ||||
-rwxr-xr-x | bin/ak-find-latest-mined-sblock | 82 | ||||
-rwxr-xr-x | bin/ak-following | 8 | ||||
-rwxr-xr-x | bin/ak-fs-add | 21 | ||||
-rwxr-xr-x | bin/ak-mempool | 6 | ||||
-rwxr-xr-x | bin/ak-miner-script | 56 | ||||
-rwxr-xr-x | bin/ak-network | 2 | ||||
-rwxr-xr-x | bin/ak-sblock-show | 4 | ||||
-rwxr-xr-x | bin/ak-sm-filejoiner | 64 | ||||
-rwxr-xr-x | bin/ak-sm-filesplitter | 68 | ||||
-rwxr-xr-x | bin/ak-zchain-calculate-size | 2 | ||||
-rwxr-xr-x | bin/ak-zchain-reset | 74 | ||||
-rwxr-xr-x | install.sh | 32 | ||||
-rwxr-xr-x | lib/_ak_gpg | 5 | ||||
-rwxr-xr-x | lib/_ak_script | 5 | ||||
-rwxr-xr-x | lib/_ak_zblock | 158 |
17 files changed, 378 insertions, 367 deletions
@@ -9,4 +9,4 @@ SOURCE=./api/index.js CFLAGS=pkg all: - $(CC) $(CFLAGS) $(TARGET) --output $(OUTPUT) $(SOURCE) + $(CC) $(CFLAGS) $(TARGET) --output $(OUTPUT) $(SOURCE) diff --git a/bin/ak-data-expand b/bin/ak-data-expand index a19ca65..8ee54c9 100755 --- a/bin/ak-data-expand +++ b/bin/ak-data-expand @@ -11,94 +11,94 @@ fi if [ ! -z "$1" ] && [ ! -z "$2" ] then - echo -n "$1" | grep -e 'Qm.\{44\}' >/dev/null - if [ "$?" -ne 0 ] - then - logit "ERROR" "Invalid hash format for $1" - exit 1 - fi - _ak_ipfs_cat $1 > /dev/null - if [ "$?" -ne 0 ] - then - logit "ERROR" "Error while reading $1" - exit 1 - fi - _ak_ipfs_cat $1 | jq -M > /dev/null - if [ "$?" -ne 0 ] - then - logit "ERROR" "Error while parsing JSON for $1" - exit 1 - fi - _ak_ipfs_cat $1 | jq | grep ipfs > /dev/null - if [ "$?" -ne 0 ] - then - logit "ERROR" "Error while extracting data from JSON for $1" - exit 1 - fi - DATA="$(_ak_ipfs_cat $1 | jq | grep ipfs | sed -e 's/"ipfs": "//g; s/[",]//g; s/ //g')" - if [ "$?" -ne 0 ] - then - logit "ERROR" "Error while extracting data from JSON for $1" - exit 1 - fi - _ak_ipfs_cat $1 | jq | grep detach > /dev/null - if [ "$?" -ne 0 ] - then - logit "ERROR" "Error while extracting data from JSON for $1" - exit 1 - fi - DETACH="$(_ak_ipfs_cat $1 | jq | grep detach | sed -e 's/"detach": "//g; s/[",]//g; s/ //g')" - if [ "$?" -ne 0 ] - then - logit "ERROR" "Error while extracting data from JSON for $1" - exit 1 - fi - echo -n "$2" | grep -e 'Qm.\{44\}' >/dev/null - if [ "$?" -ne 0 ] - then - logit "ERROR" "Invalid hash format for $2" - exit 1 - fi + echo -n "$1" | grep -e 'Qm.\{44\}' >/dev/null + if [ "$?" -ne 0 ] + then + logit "ERROR" "Invalid hash format for $1" + exit 1 + fi + _ak_ipfs_cat $1 > /dev/null + if [ "$?" -ne 0 ] + then + logit "ERROR" "Error while reading $1" + exit 1 + fi + _ak_ipfs_cat $1 | jq -M > /dev/null + if [ "$?" -ne 0 ] + then + logit "ERROR" "Error while parsing JSON for $1" + exit 1 + fi + _ak_ipfs_cat $1 | jq | grep ipfs > /dev/null + if [ "$?" -ne 0 ] + then + logit "ERROR" "Error while extracting data from JSON for $1" + exit 1 + fi + DATA="$(_ak_ipfs_cat $1 | jq | grep ipfs | sed -e 's/"ipfs": "//g; s/[",]//g; s/ //g')" + if [ "$?" -ne 0 ] + then + logit "ERROR" "Error while extracting data from JSON for $1" + exit 1 + fi + _ak_ipfs_cat $1 | jq | grep detach > /dev/null + if [ "$?" -ne 0 ] + then + logit "ERROR" "Error while extracting data from JSON for $1" + exit 1 + fi + DETACH="$(_ak_ipfs_cat $1 | jq | grep detach | sed -e 's/"detach": "//g; s/[",]//g; s/ //g')" + if [ "$?" -ne 0 ] + then + logit "ERROR" "Error while extracting data from JSON for $1" + exit 1 + fi + echo -n "$2" | grep -e 'Qm.\{44\}' >/dev/null + if [ "$?" -ne 0 ] + then + logit "ERROR" "Invalid hash format for $2" + exit 1 + fi gpg="$2" _ak_ipfs_get $gpg > /dev/null 2>&1 if [ "$?" -ne 0 ] then - logit "ERROR" "Could not get GPG key: $gpg" - exit 1 + logit "ERROR" "Could not get GPG key: $gpg" + exit 1 fi _ak_gpg_key_import_from_file $gpg > /dev/null 2>&1 if [ "$?" -ne 0 ] then - logit "ERROR" "Could not import GPG key: $gpg" - exit 1 - fi - _ak_ipfs_get $DETACH > /dev/null 2>&1 - if [ "$?" -ne 0 ] - then - logit "ERROR" "Error while getting signature: $DETACH for data: $DATA" - exit 1 - fi - mv $DETACH $DATA.asc - logit "INFO" "Block signature downloaded" - _ak_ipfs_get $DATA > /dev/null 2>&1 - if [ "$?" -ne 0 ] - then - logit "ERROR" "Error while getting data: $DATA" - exit 1 - fi - logit "INFO" "Data downloaded: $DATA" - _ak_gpg_verify_signature $DATA.asc $DATA > /dev/null 2>&1 - if [ "$?" -ne 0 ] - then - logit "ERROR" "Error while verifying signature for $DATA" - exit 1 - fi + logit "ERROR" "Could not import GPG key: $gpg" + exit 1 + fi + _ak_ipfs_get $DETACH > /dev/null 2>&1 + if [ "$?" -ne 0 ] + then + logit "ERROR" "Error while getting signature: $DETACH for data: $DATA" + exit 1 + fi + mv $DETACH $DATA.asc + logit "INFO" "Block signature downloaded" + _ak_ipfs_get $DATA > /dev/null 2>&1 + if [ "$?" -ne 0 ] + then + logit "ERROR" "Error while getting data: $DATA" + exit 1 + fi + logit "INFO" "Data downloaded: $DATA" + _ak_gpg_verify_signature $DATA.asc $DATA > /dev/null 2>&1 + if [ "$?" -ne 0 ] + then + logit "ERROR" "Error while verifying signature for $DATA" + exit 1 + fi mv $DATA $AK_WORKDIR/ipfs - logit "INFO" "Block signature verified" + logit "INFO" "Block signature verified" echo -n '"data":"'$1'","'$1'":'$(_ak_ipfs_cat $1|jq -M -c)',' - exit 0 + exit 0 else - echo "Usage: $PROGRAM HASH GPG" - exit 1 + echo "Usage: $PROGRAM HASH GPG" + exit 1 fi diff --git a/bin/ak-find-latest-mined-sblock b/bin/ak-find-latest-mined-sblock index 8ef104c..772e884 100755 --- a/bin/ak-find-latest-mined-sblock +++ b/bin/ak-find-latest-mined-sblock @@ -15,63 +15,63 @@ then fi further(){ - # logit "INFO" "Diving into $1" - lookfor $1 + # logit "INFO" "Diving into $1" + lookfor $1 } lookfor(){ - echo -n $1 | grep -e '[0-9a-f]\{128\}' > /dev/null - if [ ! $? = 0 ] - then - logit "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 - logit "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 - logit "INFO" "Found previous: $NEXT_TARGET" - if [ ! -f "$NEXT_TARGET" ] - then - logit "WARNING" "Could not find $NEXT_TARGET" - else - further "$NEXT_TARGET" - fi - else - logit "WARNING" "No next target found. So long for $1" - fi - fi + echo -n $1 | grep -e '[0-9a-f]\{128\}' > /dev/null + if [ ! $? = 0 ] + then + logit "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 + logit "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 + logit "INFO" "Found previous: $NEXT_TARGET" + if [ ! -f "$NEXT_TARGET" ] + then + logit "WARNING" "Could not find $NEXT_TARGET" + else + further "$NEXT_TARGET" + fi + else + logit "WARNING" "No next target found. So long for $1" + fi + fi } templistblock="$(mktemp)" find . -type f | sed 's/^\.\/000/000/g' | grep '^000' | sort > $templistblock while IFS="" read -r p || [ -n "$p" ] do -# if [ ! "$p" = "" ] && [ ! "$p" = "tmplistblock" ] - if [ "$(echo $p | tr -d '\n' | wc -c)" = 128 ] - then +# if [ ! "$p" = "" ] && [ ! "$p" = "tmplistblock" ] + if [ "$(echo $p | tr -d '\n' | wc -c)" = 128 ] + then filename="$(basename $p)" - logit "INFO" "Investigating $filename..." - export CHAIN_PARENT="$filename" - counters[$CHAIN_PARENT]=1 - lookfor "$filename" - else - logit "WARNING" "Nothing to do with $filename" - fi + logit "INFO" "Investigating $filename..." + export CHAIN_PARENT="$filename" + counters[$CHAIN_PARENT]=1 + lookfor "$filename" + else + logit "WARNING" "Nothing to do with $filename" + fi done < $templistblock rm $templistblock max=0 max_holder=0 for value in "${!counters[@]}" do - # echo "${value} : ${counters[${value}]}" + # echo "${value} : ${counters[${value}]}" if [ ${counters[${value}]} -gt $max ] then max="${counters[${value}]}" diff --git a/bin/ak-following b/bin/ak-following index 0446ed8..7b37be3 100755 --- a/bin/ak-following +++ b/bin/ak-following @@ -5,9 +5,9 @@ source $AK_LIBDIR/_ak_log FOLLOWING="$HOME/.arching-kaos/following" if [ -f $FOLLOWING ] then - cat $FOLLOWING + cat $FOLLOWING else - logit "INFO" "No following file, creating" - touch $FOLLOWING - echo "None found" + logit "INFO" "No following file, creating" + touch $FOLLOWING + echo "None found" fi diff --git a/bin/ak-fs-add b/bin/ak-fs-add index d00367d..34ee3c0 100755 --- a/bin/ak-fs-add +++ b/bin/ak-fs-add @@ -24,12 +24,20 @@ # Uncomment next line if you want to debug # set -xe PROGRAM="$(basename $0)" +source $AK_LIBDIR/_ak_fs +source $AK_LIBDIR/_ak_log if [ ! -f "$1" ] then - echo "ERROR File not found" + logit "ERROR" "File $1 not found" exit 1 else + # TODO + # Side hustle, save the original hash and original filename + # This won't be expected in general + # The idea is: + # sha256sum as quick pointer to root of the tree + # base64 $1 > file FILE="file" fi @@ -57,12 +65,11 @@ rm -rf $TEMPORARYDIR if [ ! -d "$TECHDIR" ] then mkdir -p "$TECHDIR" - if [ "$?" == 0 ] + 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 @@ -73,12 +80,11 @@ fi if [ ! -d "$FILEMAPSDIR" ] then mkdir -p "$FILEMAPSDIR" - if [ "$?" == 0 ] + 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 @@ -89,12 +95,11 @@ fi if [ ! -d "$CHKDIR" ] then mkdir -p "$CHKDIR" - if [ "$?" == 0 ] + 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 @@ -105,7 +110,7 @@ fi if [ ! -d "$MERKLEDIR" ] then mkdir -p "$MERKLEDIR" - if [ "$?" == 0 ] + if [ $? == 0 ] then logit "INFO" "Folder $MERKLEDIR created!" else diff --git a/bin/ak-mempool b/bin/ak-mempool index a4e11c9..cb659c2 100755 --- a/bin/ak-mempool +++ b/bin/ak-mempool @@ -12,9 +12,9 @@ _ak_ipfs_swarm_peers > tmp_peers while IFS="" read -r p || [ -n "$p" ] do - peer="$(echo "$p" | sed -e 's/^.*\///')" - logit "INFO" "Peer $peer found! Examining..." - _ak_ipfs_cat /ipns/$peer/zlatest + peer="$(echo "$p" | sed -e 's/^.*\///')" + logit "INFO" "Peer $peer found! Examining..." + _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 28bb056..002c27d 100755 --- a/bin/ak-miner-script +++ b/bin/ak-miner-script @@ -1,43 +1,43 @@ #!/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'"nonce":"'$i'","previous":"'$PRE'","timestamp":"'$TIMESTAMP'","miner":"'$MINER'","reward":"40"}' | sha512sum | awk '{ print $1 }')" + TEST="$1" + PRE="$2" + MINER="$3" + i=1 + l=1; while [ $l = 1 ] + do + TIMESTAMP="$(date -u +%s)" + SHA="$(echo $TEST'"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'"nonce":"'$i'","previous":"'$PRE'","timestamp":"'$TIMESTAMP'","miner":"'$MINER'","reward":"40"}' | jq --compact-output > $AK_MINEDBLOCKSDIR/$SHA - cat $AK_MINEDBLOCKSDIR/$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 + echo $SHA | grep -e '^000' + if [ "$?" == 0 ] ; + then + echo "SHA512 is $SHA" + echo "Mined block:" + echo $TEST'"nonce":"'$i'","previous":"'$PRE'","timestamp":"'$TIMESTAMP'","miner":"'$MINER'","reward":"40"}' | jq --compact-output > $AK_MINEDBLOCKSDIR/$SHA + cat $AK_MINEDBLOCKSDIR/$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 <somethings> <previous> <miner_address>" - echo " hit ak-enter after that !!! " + echo "$PROGRAM <somethings> <previous> <miner_address>" + echo " hit ak-enter after that !!! " } if [ -z "$1" ] ; then - usage - exit; + usage + exit; elif [ ! -z "$1" ] && [ ! -z "$2" ] && [ ! -z "$3" ] then proofofwork "$1" "$2" "$3"; diff --git a/bin/ak-network b/bin/ak-network index 3a65d7b..c506879 100755 --- a/bin/ak-network +++ b/bin/ak-network @@ -1,5 +1,5 @@ #!/bin/bash while true do - cat $ZLATEST | nc -lv 127.0.0.1 5050 + cat $ZLATEST | nc -lv 127.0.0.1 5050 done diff --git a/bin/ak-sblock-show b/bin/ak-sblock-show index 0a92c54..e840740 100755 --- a/bin/ak-sblock-show +++ b/bin/ak-sblock-show @@ -3,7 +3,7 @@ PROGRAM="$(basename $0)" if [ ! -z $1 ] then - cat $AK_MINEDBLOCKSDIR/$1 | jq + cat $AK_MINEDBLOCKSDIR/$1 | jq else - echo "No sblock hash input" + echo "No sblock hash input" fi diff --git a/bin/ak-sm-filejoiner b/bin/ak-sm-filejoiner index 69b1297..3f3604c 100755 --- a/bin/ak-sm-filejoiner +++ b/bin/ak-sm-filejoiner @@ -5,11 +5,11 @@ set -xe PROGRAM="$(basename $0)" usage(){ - echo "$PROGRAM <hash>" + echo "$PROGRAM <hash>" } cdaw(){ - pwd > tmp_holder + pwd > tmp_holder } cdaw @@ -20,12 +20,12 @@ TMPWD="/tmp/rjs" if [ ! -d "$TMPWD" ] then - mkdir -p "$TMPWD" - if [ "$?" != 0 ] - then - echo "Can't create $TMPWD dir" - exit 1 - fi + mkdir -p "$TMPWD" + if [ "$?" != 0 ] + then + echo "Can't create $TMPWD dir" + exit 1 + fi fi MAPSDIR="$AK_WORKDIR/fmp" @@ -35,54 +35,54 @@ CHKDIR="$AK_WORKDIR/ftr" cd $CHKDIR if [ "$?" != 0 ] then - echo "Can't get dir" - exit 1 + echo "Can't get dir" + exit 1 fi if [ ! -z $1 ] then - MAPSFILE="$1" + MAPSFILE="$1" + + echo '#!/bin/bash' > script - 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 + awk '{print "cp '$CHKDIR'/"$1" '$TMPWD'/"$2" "}' $MAPSDIR/$MAPSFILE| grep chk >> script - bash script + bash script - if [ "$?" != 0 ] - then - echo "Error executing copy script" - exit 1 - fi - rm script + if [ "$?" != 0 ] + then + echo "Error executing copy script" + exit 1 + fi + rm script - cd $TMPWD + cd $TMPWD - echo "$PWD" + echo "$PWD" # Final name we are going to rename to - OUTPUT="$(tail -n1 $MAPSDIR/$MAPSFILE | awk '{print $2}')" + OUTPUT="$(tail -n1 $MAPSDIR/$MAPSFILE | awk '{print $2}')" - echo $OUTPUT + 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 + 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 + sha512sum -c $MAPSDIR/$MAPSFILE if [ "$?" != "0" ]; then logit "ERROR" "Error while checking sums" exit 1 fi - - mv $OUTPUT $CURDIR - rm -rf "$TMPWD" + mv $OUTPUT $CURDIR + + rm -rf "$TMPWD" - rm $CURDIR/tmp_holder + rm $CURDIR/tmp_holder else - usage + usage fi diff --git a/bin/ak-sm-filesplitter b/bin/ak-sm-filesplitter index d607c15..f9f5cff 100755 --- a/bin/ak-sm-filesplitter +++ b/bin/ak-sm-filesplitter @@ -23,10 +23,10 @@ PROGRAM="$(basename $0)" if [ ! -f "$1" ] then - echo "ERROR File not found" - exit 1 + echo "ERROR File not found" + exit 1 else - FILE="$1" + FILE="$1" fi # The directory where the chunked data will be living at @@ -48,49 +48,49 @@ source $AK_LIBDIR/_ak_log # 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 + 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" + 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 + 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" + 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 + 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" + logit "INFO" "Workdir found" fi # Uncomment next line in case you want to debug the resulting script as well @@ -109,7 +109,7 @@ cd $TECHDIR # 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 + echo $p | awk '{print "mv " $2 " '$CHKDIR'" $1}' >> $TEMPORARYDIR/cmd_queue.sh done < $TEMPORARYDIR/map # We run the crafted script diff --git a/bin/ak-zchain-calculate-size b/bin/ak-zchain-calculate-size index 51c4202..5603221 100755 --- a/bin/ak-zchain-calculate-size +++ b/bin/ak-zchain-calculate-size @@ -22,7 +22,7 @@ do else num=0 fi - sum=$(expr $sum + $num ) + sum=$(expr $sum + $num ) done < to_stats echo "Chain is : $sum bytes" diff --git a/bin/ak-zchain-reset b/bin/ak-zchain-reset index b415c44..4d9e099 100755 --- a/bin/ak-zchain-reset +++ b/bin/ak-zchain-reset @@ -3,43 +3,43 @@ PROGRAM=$(basename $0) source $AK_LIBDIR/_ak_ipfs usage(){ - echo "$PROGRAM - Zchain reset" - echo "" - echo "Description:" - echo "Backs up your latest block into IPFS filesystem, replaces it with an empty file (GENESIS hardcode) and pushes its IPFS link as your chain's latest block." - echo "" - echo "Disclaimer:" - echo "This program, does NOT delete anything from your IPFS repository, neither denies access to previously created blocks." - echo "" - echo "Usage:" - echo " $PROGRAM reset" - exit 0 + echo "$PROGRAM - Zchain reset" + echo "" + echo "Description:" + echo "Backs up your latest block into IPFS filesystem, replaces it with an empty file (GENESIS hardcode) and pushes its IPFS link as your chain's latest block." + echo "" + echo "Disclaimer:" + echo "This program, does NOT delete anything from your IPFS repository, neither denies access to previously created blocks." + echo "" + echo "Usage:" + echo " $PROGRAM reset" + exit 0 } reset (){ - echo "Reseting ZLATEST to ZGENESIS" - cp $ZGENESIS $ZLATEST - if [ $? != 0 ]; then exit 1; fi + echo "Reseting ZLATEST to ZGENESIS" + cp $ZGENESIS $ZLATEST + if [ $? != 0 ]; then exit 1; fi - echo "Make sure /zarchive folder exists within IPFS FS" - _ak_ipfs_files_mkdir /zarchive - if [ $? != 0 ]; then echo "Folder already there"; fi + echo "Make sure /zarchive folder exists within IPFS FS" + _ak_ipfs_files_mkdir /zarchive + if [ $? != 0 ]; then echo "Folder already there"; fi - echo "Archive the previous ZLATEST" - _ak_ipfs_files_cp /zlatest /zarchive/$(date -u +%s)-$(_ak_ipfs_files_stat /zlatest | head -n 1) - if [ $? != 0 ]; then exit 1; fi + echo "Archive the previous ZLATEST" + _ak_ipfs_files_cp /zlatest /zarchive/$(date -u +%s)-$(_ak_ipfs_files_stat /zlatest | head -n 1) + if [ $? != 0 ]; then exit 1; fi - echo "Removing previous /zlatest entry" - _ak_ipfs_files_rm /zlatest - if [ $? != 0 ]; then exit 1; fi + echo "Removing previous /zlatest entry" + _ak_ipfs_files_rm /zlatest + if [ $? != 0 ]; then exit 1; fi - echo "Copying reset ZLATEST" - CZLATEST="$(cat $ZLATEST)" - _ak_ipfs_files_cp /ipfs/$CZLATEST /zlatest - if [ $? != 0 ]; then exit 1; fi + echo "Copying reset ZLATEST" + CZLATEST="$(cat $ZLATEST)" + _ak_ipfs_files_cp /ipfs/$CZLATEST /zlatest + if [ $? != 0 ]; then exit 1; fi - echo "Publishing new (reset) ZLATEST" - _ak_ipfs_name_publish --key=zchain /ipfs/$(cat $ZLATEST) - if [ $? != 0 ]; then exit 1; fi + echo "Publishing new (reset) ZLATEST" + _ak_ipfs_name_publish --key=zchain /ipfs/$(cat $ZLATEST) + if [ $? != 0 ]; then exit 1; fi ak-config publish if [ "$?" -ne 0 ] @@ -47,15 +47,15 @@ reset (){ logit "ERROR" "Could not publish new configuration" exit 1 fi - - echo "Reset was successful" - exit 0 + + echo "Reset was successful" + exit 0 } if [ ! -z $1 ]; then - case $1 in - reset) reset; exit;; - * ) usage;; - esac + case $1 in + reset) reset; exit;; + * ) usage;; + esac else usage fi @@ -161,40 +161,40 @@ if [ ! -d $AK_GPGHOME ]; then mkdir $AK_GPGHOME && chmod 700 -R $AK_GPGHOME; fi touch $AK_WORKDIR/logs logthis(){ - echo "Install script: $1" >> $AK_WORKDIR/logs + echo "Install script: $1" >> $AK_WORKDIR/logs } HAK=".arching-kaos" logthis "Searching for $HAK folder and files" if [ ! -d $HOME/$HAK ]; then - mkdir $HOME/$HAK - logthis "$HAK created in $HOME"; + mkdir $HOME/$HAK + logthis "$HAK created in $HOME"; fi logthis "Searching for rc" if [ ! -f $HOME/$HAK/rc ]; then - echo export PATH=$PATH:$HOME/$HAK/bin > $HOME/$HAK/rc - cat config.sh >> $HOME/$HAK/rc - logthis "New rc export to file"; + echo export PATH=$PATH:$HOME/$HAK/bin > $HOME/$HAK/rc + cat config.sh >> $HOME/$HAK/rc + logthis "New rc export to file"; fi logthis "Searching for shell" if [ $SHELL == "/usr/bin/zsh" ]; then - SHELLRC=".zshrc" - logthis "ZSH found"; + SHELLRC=".zshrc" + logthis "ZSH found"; elif [ $SHELL == "/usr/bin/bash" ]; then - SHELLRC='.bashrc' - logthis "BASH found"; + SHELLRC='.bashrc' + logthis "BASH found"; else - logthis "Unknown shell... defaulting to bash" - SHELLRC='.bashrc' + logthis "Unknown shell... defaulting to bash" + SHELLRC='.bashrc' fi logthis "Searching if rc is already there" grep "source $HOME/$HAK/rc" $HOME/$SHELLRC > /dev/null 2>&1 if [ $? == 0 ]; then - logthis "Already installed"; + logthis "Already installed"; else - echo "source $HOME/$HAK/rc" >> $HOME/$SHELLRC - logthis "$HAK installed at $HOME and sourced it in $SHELLRC" - source $HOME/$HAK/rc; + echo "source $HOME/$HAK/rc" >> $HOME/$SHELLRC + logthis "$HAK installed at $HOME and sourced it in $SHELLRC" + source $HOME/$HAK/rc; fi sh ipfs-check-install-setup-init-update source ./config.sh diff --git a/lib/_ak_gpg b/lib/_ak_gpg index d1f7e68..4c73188 100755 --- a/lib/_ak_gpg +++ b/lib/_ak_gpg @@ -1,5 +1,6 @@ #!/bin/bash source $AK_LIBDIR/_ak_log +source $AK_LIBDIR/_ak_ipfs _ak_gpg(){ gpg2 --homedir $AK_GPGHOME $* @@ -31,7 +32,7 @@ _ak_gpg_key_self_get_fingerprint_from_config(){ _ak_gpg_key_self_get_fingerprint(){ if [ -z $1 ] then - ak-ipfs-cat "$(_ak_gpg_key_self_get_fingerprint_from_config)" | \ + _ak_ipfs_cat "$(_ak_gpg_key_self_get_fingerprint_from_config)" | \ _ak_gpg --show-keys 2>&1 | \ head -n 2 | \ tail -n 1 | \ @@ -44,7 +45,7 @@ _ak_gpg_key_self_get_fingerprint(){ _ak_gpg_key_get_fingerprint_from_ipfs(){ if [ -n "$1" ] then - ak-ipfs-cat "$1" | \ + _ak_ipfs_cat "$1" | \ _ak_gpg --show-keys 2>&1 | \ head -n 2 | \ tail -n 1 | \ diff --git a/lib/_ak_script b/lib/_ak_script index 543f597..3a7f635 100755 --- a/lib/_ak_script +++ b/lib/_ak_script @@ -62,3 +62,8 @@ _ak_usage(){ _ak_title_description _ak_help } + +_ak_not_implemented(){ + _ak_title_description + printf 'Not implemented: %s\n' "$*" +} diff --git a/lib/_ak_zblock b/lib/_ak_zblock index 72d94ab..07f4981 100755 --- a/lib/_ak_zblock +++ b/lib/_ak_zblock @@ -52,52 +52,52 @@ _ak_zblock_show(){ # source $AK_LIBDIR/_ak_gpg # # usage(){ -# echo "Usage:" -# echo "$PROGRAM -b block_file | -h block_hash | dunno" -# echo "Creates and publishes a ZBLOCK based on a block and a previous" -# echo "zblock." -# echo "" -# echo "Either -b or -h is needed. If both, -h is used." -# echo "" -# echo "-b block_file Points to a block file that we want to fix." -# echo "-h block_hash If we don't have the block as a file, we can" -# echo " use it's hash to retrieve it and edit it." -# echo "-p previous_hash We refering to a previous hash for a ZBLOCK." -# echo "" -# echo "#TODO:" -# echo "-t timestamp Unix UTC timestamp in seconds." -# echo "-a \"module/action\" Change the action tag. Format: object/verb." -# echo " In sense, \"Add news -> news/add\"." -# echo "-d data In case you want to change the data, you 'll" -# echo " be changing potentially the key of the block" -# echo " and the data signature, otherwise your block" |