diff options
Diffstat (limited to 'lib/_ak_zblock')
-rwxr-xr-x | lib/_ak_zblock | 100 |
1 files changed, 50 insertions, 50 deletions
diff --git a/lib/_ak_zblock b/lib/_ak_zblock index 0095c3d..b9fb91a 100755 --- a/lib/_ak_zblock +++ b/lib/_ak_zblock @@ -20,7 +20,7 @@ _ak_zblock_show(){ echo $1 | grep -e 'Qm.\{44\}' >/dev/null if [ $? -ne 0 ] then - logit "ERROR" "Argument provided ($1) was not an IPFS CIDv0 string" + _ak_log_error "Argument provided ($1) was not an IPFS CIDv0 string" exit 1 fi entrance="$1" @@ -38,7 +38,7 @@ _ak_zblock_show(){ # Reset timestamp since it's introduced later timestamp='' # Announce to logs which ZBLOCK is being read at the moment - logit "INFO" "Examining $zblock" + _ak_log_info "Examining $zblock" _ak_ipfs_cid_v0_check "$zblock" @@ -46,10 +46,10 @@ _ak_zblock_show(){ _ak_ipfs_cat $zblock | jq -c -M > $AK_ZBLOCKDIR/$zblock if [ "$?" -ne 0 ] then - logit "ERROR" "ZBLOCK $zblock READ failed" + _ak_log_error "ZBLOCK $zblock READ failed" exit 1 fi - logit "INFO" "ZBLOCK $zblock READ" + _ak_log_info "ZBLOCK $zblock READ" echo -n '{' # echo -n '"id":"'$counter'",' echo -n '"zblock":"'$zblock'",' @@ -58,11 +58,11 @@ _ak_zblock_show(){ cat $AK_ZBLOCKDIR/$zblock | jq -M > /dev/null 2>&1 if [ $? -ne 0 ] then - logit "ERROR" "ZBLOCK $zblock is not JSON" + _ak_log_error "ZBLOCK $zblock is not JSON" cat /dev/null > $AK_ZBLOCKDIR/$zblock > /dev/null 2>&1 exit 1 fi - logit "INFO" "ZBLOCK $zblock is JSON" + _ak_log_info "ZBLOCK $zblock is JSON" # Be sure that there are the expected values # We need 'block' and 'block_signature' inside a 'zblock' @@ -70,20 +70,20 @@ _ak_zblock_show(){ block="$(cat $AK_ZBLOCKDIR/$zblock | jq -M -r .block)" if [ "$block" == "null" ] then - logit "ERROR" "ZBLOCK $zblock has no block" + _ak_log_error "ZBLOCK $zblock has no block" exit 1 fi _ak_ipfs_cid_v0_check "$block" - logit "INFO" "ZBLOCK $zblock has block" + _ak_log_info "ZBLOCK $zblock has block" block_signature="$(cat $AK_ZBLOCKDIR/$zblock | jq -M -r .block_signature)" if [ "$block_signature" == "null" ] then - logit "ERROR" "ZBLOCK $zblock doesn't contain a block_signature" + _ak_log_error "ZBLOCK $zblock doesn't contain a block_signature" exit 1 fi _ak_ipfs_cid_v0_check "$block_signature" - logit "INFO" "ZBLOCK $zblock contains a block_signature" + _ak_log_info "ZBLOCK $zblock contains a block_signature" # Same as above applies to BLOCK and DATA subparts of each ZBLOCK # BLOCKS @@ -92,24 +92,24 @@ _ak_zblock_show(){ cat $AK_BLOCKDIR/$block | jq -M > /dev/null 2>&1 if [ "$?" -ne 0 ] then - logit "ERROR" "BLOCK $block READ failed" + _ak_log_error "BLOCK $block READ failed" exit 1 fi grep -e 'timestamp' -e 'gpg' -e 'data' -e 'action' -e 'detach' -e 'previous' $AK_BLOCKDIR/$block > /dev/null 2>&1 if [ "$?" -ne 0 ] then - logit "ERROR" "BLOCK $block is NOT a valid block" + _ak_log_error "BLOCK $block is NOT a valid block" exit 1 fi - logit "INFO" "BLOCK $block is a block" + _ak_log_info "BLOCK $block is a block" action="$(cat $AK_BLOCKDIR/$block | jq -M -r .action)" module="$(echo $action | sed -e 's/\// /g' | awk '{ print $1 }')" - logit "INFO" "DATA is $module module." + _ak_log_info "DATA is $module module." command="$(echo $action | sed -e 's/\// /g' | awk '{ print $2 }')" - logit "INFO" "COMMAND is $command" + _ak_log_info "COMMAND is $command" timestamp="$(cat $AK_BLOCKDIR/$block | jq -M -r .timestamp)" if [ "$timestamp" != "null" ] @@ -134,39 +134,39 @@ _ak_zblock_show(){ _ak_ipfs_get $gpg > /dev/null 2>&1 if [ "$?" -ne 0 ] then - logit "ERROR" "Could not get GPG key: $gpg ." + _ak_log_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 ." + _ak_log_error "Could not import GPG key: $gpg ." exit 1 fi _ak_ipfs_get $block_signature > /dev/null 2>&1 if [ "$?" -ne 0 ] then - logit "ERROR" "Error while getting $block_signature for $block" + _ak_log_error "Error while getting $block_signature for $block" exit 1 fi mv $block_signature $block.asc - logit "INFO" "Block signature downloaded" + _ak_log_info "Block signature downloaded" _ak_ipfs_get $block > /dev/null 2>&1 if [ "$?" -ne 0 ] then - logit "ERROR" "Could not get $block block" + _ak_log_error "Could not get $block block" exit 1 fi - logit "INFO" "Downloaded block $block." + _ak_log_info "Downloaded block $block." _ak_gpg_verify_signature $block.asc $block > /dev/null 2>&1 if [ "$?" -ne 0 ] then - logit "ERROR" "Could not verify $block with GPG key $gpg." + _ak_log_error "Could not verify $block with GPG key $gpg." exit 1 fi - logit "GPG" "$gpg signature of $block is verified." + _ak_log_info "$gpg signature of $block is verified." fi data="$(cat $AK_BLOCKDIR/$block | jq -M -r .data)" @@ -174,7 +174,7 @@ _ak_zblock_show(){ ak-data-expand $data $gpg if [ "$?" -ne 0 ] then - logit "ERROR" "Failed on data signature verification [data: $data, gpg: $gpg, zblock: $zblock]" + _ak_log_error "Failed on data signature verification [data: $data, gpg: $gpg, zblock: $zblock]" exit 1 fi @@ -189,15 +189,15 @@ _ak_zblock_show(){ previous="$(cat $AK_BLOCKDIR/$block | jq -M -r .previous)" if [ -v $previous ] then - logit "WARNING" "Block $block has no previous zblock, appending pseudo genesis to exit with 2." + _ak_log_warning "Block $block has no previous zblock, appending pseudo genesis to exit with 2." echo -n '"previous":"'$seed'"},{"genesis":"genesis"}]' - logit "INFO" "Reached pseudo-genesis, counted $counter zblocks." + _ak_log_info "Reached pseudo-genesis, counted $counter zblocks." exit 2 # Otherwise, we inform of the sequence else #echo "$zblock after $previous" - logit "INFO" "Found a previous block for $zblock: $previous" + _ak_log_info "Found a previous block for $zblock: $previous" echo -n '"previous":"'$previous'"}' zblock=$previous fi @@ -207,7 +207,7 @@ _ak_zblock_show(){ elif [ "$zblock" == "$seed" ] then echo -n '{"genesis":"genesis"}]' - logit "INFO" "Reached $seed, counted $counter zblocks." + _ak_log_info "Reached $seed, counted $counter zblocks." exit 0 fi # And finally, if nothing is there exit with error @@ -265,7 +265,7 @@ _ak_zblock_show(){ # # main(){ # -# logit "INFO" "We are doing" $BLOCK_TO_ADD "with content" $PREVIOUS +# _ak_log_info "We are doing" $BLOCK_TO_ADD "with content" $PREVIOUS # # We add it to IPFS # MESSAGE_HASH=$(_ak_ipfs_add $MESSAGE) # @@ -369,7 +369,7 @@ _ak_zblock_gen_html(){ # Check if there are enough arguments if [ $# -lt 1 ] then - logit "ERROR" "Not enough arguments provided" + _ak_log_error "Not enough arguments provided" _ak_help exit 1 fi @@ -421,12 +421,12 @@ _ak_zblock_cache(){ # if [ "$(sha512sum $AK_ZBLOCKDIR/$1 | awk '{ print $1 }')" == "$(_ak_zblock_show $1 | sha512sum | awk '{ print $1 }')" ] if [ ! -f $FZBLOCKSDIR/$1 ] then - logit "INFO" "No cache found. Caching..." + _ak_log_info "No cache found. Caching..." _ak_zblock_show "$1" > $FZBLOCKSDIR/$1 fi if [ ! -f $FZBLOCKSDIR/$1 ] then - logit "INFO" "Caching failed..." + _ak_log_info "Caching failed..." exit 1 fi cat $FZBLOCKSDIR/$1 @@ -434,15 +434,15 @@ _ak_zblock_cache(){ _ak_zblock_show "$1" > $FZBLOCKSDIR/$1 if [ $? -ne "0" ] then - logit "ERROR" "_ak_zblock_show failed..." + _ak_log_error "_ak_zblock_show failed..." exit 2 fi - logit "ERROR" "Could not find zblock $1..." + _ak_log_error "Could not find zblock $1..." exit 1 fi exit 0 else - logit "ERROR" "No arguments..." + _ak_log_error "No arguments..." exit 1 fi @@ -462,13 +462,13 @@ _ak_zblock_pack(){ do if [ "$p" == "$TO_CHECK" ] then - logit "ERROR" "Value $TO_CHECK already mentioned on the zchain" + _ak_log_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" + _ak_log_info "We are doing $ACTION with content $MESSAGE" # We add it to IPFS MESSAGE_HASH=$(_ak_ipfs_add $MESSAGE) @@ -507,7 +507,7 @@ _ak_zblock_pack(){ ZBLOCK=$(_ak_ipfs_add $ZBL) echo $ZBLOCK else - logit "ERROR" "File does not exist. Aborting..." + _ak_log_error "File does not exist. Aborting..." exit 1 fi @@ -519,46 +519,46 @@ _ak_zblock_pack(){ _ak_ipfs_name_publish --key=zchain $ZBLOCK > /dev/null 2>&1 if [ $? -ne 0 ] then - logit "ERROR" "Failed publishing ZBLOCK: $ZBLOCK" + _ak_log_error "Failed publishing ZBLOCK: $ZBLOCK" exit 1 fi _ak_ipfs_files_ls /zarchive > /dev/null 2>&1 if [ $? -ne 0 ] then - logit "WARNING" "/zarchive does not exist" + _ak_log_warning "/zarchive does not exist" _ak_ipfs_files_mkdir /zarchive > /dev/null 2>&1 if [ $? -ne 0 ] then - logit "ERROR" "Could not create /zarchive directory. Aborting." + _ak_log_error "Could not create /zarchive directory. Aborting." exit 1 fi fi _ak_ipfs_files_cp /zlatest /zarchive/$(date -u +%s)-$(_ak_ipfs_files_stat /zlatest | head -n 1) > /dev/null 2>&1 if [ $? -ne 0 ] then - logit "ERROR" "Could not back up previous /zlatest" + _ak_log_error "Could not back up previous /zlatest" exit 1 fi _ak_ipfs_files_rm /zlatest > /dev/null 2>&1 if [ $? -ne 0 ] then - logit "ERROR" "Could not remove previous /zlatest" + _ak_log_error "Could not remove previous /zlatest" exit 1 fi _ak_ipfs_files_cp /ipfs/$ZBLOCK /zlatest > /dev/null 2>&1 if [ $? -ne 0 ] then - logit "ERROR" "Could not copy $ZBLOCK to /zlatest" + _ak_log_error "Could not copy $ZBLOCK to /zlatest" exit 1 fi ak-config --publish if [ $? -ne 0 ] then - logit "ERROR" "Could not publish new configuration" + _ak_log_error "Could not publish new configuration" exit 1 fi else - logit "ERROR" "Not enough arguments" + _ak_log_error "Not enough arguments" exit 1 fi @@ -575,9 +575,9 @@ _ak_zblock_announce(){ 2>/dev/null | jq -M -c > /dev/null if [ $? -ne 0 ] then - logit "ERROR" "zblock $zblock announcement failed" + _ak_log_error "zblock $zblock announcement failed" else - logit "INFO" "zblock $zblock announced" + _ak_log_info "zblock $zblock announced" fi else curl \ @@ -588,9 +588,9 @@ _ak_zblock_announce(){ 2>/dev/null | jq -M -c > /dev/null if [ $? -ne 0 ] then - logit "ERROR" "zblock $zblock announcement failed" + _ak_log_error "zblock $zblock announcement failed" else - logit "INFO" "zblock $zblock announced" + _ak_log_info "zblock $zblock announced" fi fi } |