From 89d00fcbc75e128cba516009db100daec4b794a9 Mon Sep 17 00:00:00 2001 From: kaotisk Date: Sat, 28 Dec 2024 15:59:04 +0200 Subject: refactoring --- lib/_ak_cjdns | 37 +++++++++++++++--------------- lib/_ak_coin | 2 +- lib/_ak_config | 7 +++--- lib/_ak_fs | 20 ---------------- lib/_ak_gpg | 52 +++++++++++++++++++++--------------------- lib/_ak_html | 5 ++-- lib/_ak_ipfs | 69 ++++++++++++++++++++++++++++---------------------------- lib/_ak_log | 21 ++++++++--------- lib/_ak_network | 46 +++++++++++++++++-------------------- lib/_ak_node | 4 ++-- lib/_ak_sblock | 2 +- lib/_ak_schain | 19 +++++++--------- lib/_ak_settings | 8 +++---- lib/_ak_smfiles | 38 +++---------------------------- lib/_ak_zblock | 68 ++++++------------------------------------------------- 15 files changed, 140 insertions(+), 258 deletions(-) (limited to 'lib') diff --git a/lib/_ak_cjdns b/lib/_ak_cjdns index 30229ca..69e5ffc 100755 --- a/lib/_ak_cjdns +++ b/lib/_ak_cjdns @@ -25,7 +25,7 @@ cjdns_src_git_repo_url="https://github.com/cjdelisle/cjdns" cjdnstoolspath="$HOME/cjdns/tools" cargo_env="$HOME/.cargo/env" -_ak_cjdns_check_availability(){ +function _ak_cjdns_check_availability(){ declare -a cjdns_bins=("cjdroute" "makekeys" "mkpasswd" "privatetopublic" "publictoip6" "randombytes" "sybilsim") for cbin in "${cjdns_bins[@]}" do @@ -40,19 +40,20 @@ _ak_cjdns_check_availability(){ done } -_ak_cargo_rust_check_install(){ - if [ ! -f $cargo_env ] +function _ak_cargo_rust_check_install(){ + if [ ! -f ${cargo_env} ] then - curl --proto '=https' --tlsv1.2 -sSf $rust_sh_install_url | sh + curl --proto '=https' --tlsv1.2 -sSf ${rust_sh_install_url} | sh fi - source $cargo_env + source ${cargo_env} } -_ak_cjdns_install(){ +function _ak_cjdns_install(){ _ak_cargo_rust_check_install - git clone $cjdns_src_git_repo_url + git clone ${cjdns_src_git_repo_url} + cjdns_install_script="./do" cd cjdns - sh do + sh ${cjdns_install_script} if [ $? -ne 0 ] then _ak_log_error "Failed to compile cjdns" @@ -66,25 +67,24 @@ _ak_cjdns_install(){ sudo cp cjdns/target/release/publictoip6 /usr/bin/publictoip6 sudo cp cjdns/target/release/randombytes /usr/bin/randombytes sudo cp cjdns/target/release/sybilsim /usr/bin/sybilsim - ln -s "$(realpath cjdns/tools/dumpLinks)" $HOME/.arching-kaos/bin/dumpLinks - ln -s "$(realpath cjdns/tools/cexec)" $HOME/.arching-kaos/bin/cjdns-cexec - ln -s "$(realpath cjdns/tools/peerStats)" $HOME/.arching-kaos/bin/peerStats + ln -s "$(realpath cjdns/tools/dumpLinks)" ${HOME}/.arching-kaos/bin/dumpLinks + ln -s "$(realpath cjdns/tools/cexec)" ${HOME}/.arching-kaos/bin/cjdns-cexec + ln -s "$(realpath cjdns/tools/peerStats)" ${HOME}/.arching-kaos/bin/peerStats which systemctl 2> /dev/null 1>&2 if [ $? -ne 0 ] then _ak_log_error "Systemctl not found... TODO" else - sudo cp "$(realpath cjdns/contrib/systemd/cjdns.service)" /etc/systemd/system/cjdns.service - sudo cp "$(realpath cjdns/contrib/systemd/cjdns-resume.service)" /etc/systemd/system/cjdns-resume.service + sudo cp cjdns/contrib/systemd/cjdns.service /etc/systemd/system/cjdns.service + sudo cp cjdns/contrib/systemd/cjdns-resume.service /etc/systemd/system/cjdns-resume.service sudo systemctl enable --now cjdns.service fi } -_ak_cjdns_read_peers_to_vars_with_jq(){ +function _ak_cjdns_read_peers_to_vars_with_jq(){ totalpeers="$(jq '. | length' < $peersfile)" number="0" interface="0" - while [ $number -lt $totalpeers ] do address="$(jq -r '.['$number'].address' < $peersfile)" @@ -103,7 +103,7 @@ _ak_cjdns_read_peers_to_vars_with_jq(){ done } -_ak_cjdns_read_peers_to_vars_natively(){ +function _ak_cjdns_read_peers_to_vars_natively(){ number=-1 cat $peersfile | tr -d $'\n' | sed -e 's/]$/\n/g' | tr -d ' ' | sed -e 's/"//g; s/,/,\n/g; s/}//g; s/,//g' | while read line do @@ -150,8 +150,7 @@ _ak_cjdns_read_peers_to_vars_natively(){ rm peerfile } - -_ak_cjdns_connect_peers(){ +function _ak_cjdns_connect_peers(){ _ak_network_cjdns_connect exit $? # @@ -187,7 +186,7 @@ _ak_cjdns_connect_peers(){ fi } -_ak_cjdns_get_ip(){ +function _ak_cjdns_get_ip(){ which ip > /dev/null 2>&1 if [ $? -ne 0 ] then diff --git a/lib/_ak_coin b/lib/_ak_coin index dd895a0..4c58e2d 100755 --- a/lib/_ak_coin +++ b/lib/_ak_coin @@ -26,7 +26,7 @@ COINBASE=100000000000 GENESIS="00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" -_ak_coin_stats(){ +function _ak_coin_stats(){ echo "Coinbase: $COINBASE" echo "Genesis: $GENESIS" } diff --git a/lib/_ak_config b/lib/_ak_config index 0a4d55c..d8705d8 100755 --- a/lib/_ak_config +++ b/lib/_ak_config @@ -19,7 +19,7 @@ ### source $AK_LIBDIR/_ak_node -_ak_config_show(){ +function _ak_config_show(){ # We will be using our public key also to put it in the block later KEY="self.pub" ak-gpg --export-key-self-to-file @@ -27,7 +27,6 @@ _ak_config_show(){ GPG_PUB_KEY=$(_ak_ipfs_add $KEY) rm $KEY profile="$(ak-profile -l)" - echo ' { "profile":'$profile', @@ -38,7 +37,7 @@ _ak_config_show(){ }'| jq; } -_ak_config_publish(){ +function _ak_config_publish(){ _ak_config_show | jq -c -M > tmpfile ipfs_hash="$(_ak_ipfs_add tmpfile)" _ak_ipfs_config_publish $ipfs_hash @@ -51,7 +50,7 @@ _ak_config_publish(){ rm tmpfile } -_ak_config_published(){ +function _ak_config_published(){ _ak_ipfs_cat $(_ak_node_info_ipfs_hash) | jq } diff --git a/lib/_ak_fs b/lib/_ak_fs index bea850c..525b108 100755 --- a/lib/_ak_fs +++ b/lib/_ak_fs @@ -88,17 +88,14 @@ function _ak_fs_import(){ # # 6. We are done! # - # A temporary root dir to work on TEMPDIR="$(_ak_make_temp_directory)" # A subdir to split the files there TCHKDIR="$TEMPDIR/chks" # A pin point to return from where we came from CURRENTDIR="$(pwd)" - # Checking directories and create them if necessary # rm -rf $TEMPDIR - _ak_check_and_create_dir $TCHKDIR _ak_fs_dir_init_setup if [ ! -f "$1" ] @@ -118,10 +115,8 @@ function _ak_fs_import(){ base64 $1 > file FILE="file" fi - # Uncomment next line in case you want to debug the resulting script as well # echo 'set -xe' > $TEMPDIR/cmd_queue.sh - # We get the SHA512 hash for the $FILE given CHECKSUM=$(sha512sum "$FILE"|awk '{print $1}') FILE_SIZE="$( (du -b $FILE||stat -f %z $FILE)2>/dev/null | awk '{ print $1 }')" @@ -140,7 +135,6 @@ function _ak_fs_import(){ split -a 13 -b $FACTOR -d "$FILE" "$TCHKDIR/chunk-" fi _ak_log_info "File done splitting" - # We go over there... cd $TCHKDIR #set -xe @@ -164,7 +158,6 @@ function _ak_fs_import(){ done _ak_log_debug "Ran $timesRan times" _ak_log_debug "Total chunks $totalChunks" - workingIndex="$TEMPDIR/map" c=$timesRan while [ $c -ne 0 ] @@ -193,7 +186,6 @@ function _ak_fs_import(){ totalChunks=`cat $workingIndex | wc -l` c=`expr $c - 1` done - if [ -f level.1.map ] then sha512sum level.1.map @@ -202,12 +194,10 @@ function _ak_fs_import(){ ak_log_error "Got error an error, level.1.map is missing" exit 1 fi - # Reset file with uniq cat $TEMPDIR/map | uniq > $TEMPDIR/map2 cat $TEMPDIR/map2 > $TEMPDIR/map rm $TEMPDIR/map2 - counter=0 while IFS="" read -r p || [ -n "$p" ] do @@ -216,31 +206,22 @@ function _ak_fs_import(){ cp $(echo $p | awk '{ print $2 }') $AK_CHUNKSDIR/$(echo $p | awk '{ print $1 }') counter=`expr "$counter" + 1` done < $TEMPDIR/map - # We run the crafted script # sh $TEMPDIR/cmd_queue.sh - # and we delete it # rm $TEMPDIR/cmd_queue.sh - # We inform the map about the original $FILE name and SHA512 # echo "$CHECKSUM $(basename "$FILE")" >> $TEMPDIR/map - # We get the SHA512 hash of the resulted map file # MAPFILEHASH="$(sha512sum $TEMPDIR/map | awk '{ print $1 }')" - # and we rename it with it and move it to AK_MAPSDIR # `sha512sum $TEMPDIR/map | awk '{print "mv " $2 " '$AK_MAPSDIR/'" $1}'` - mp512p="$(sha512sum $TEMPDIR/3rd_gen_map | awk '{print $1}')" cp $TEMPDIR/3rd_gen_map $AK_MAPSDIR/$mp512p - # We remove the TEMPDIR rm -rf $TEMPDIR - # and print the MAPFILEHASH echo "$mp512p" - } function _ak_fs_find_depth(){ @@ -325,7 +306,6 @@ function _ak_fs_cat(){ done < workspace.$counter counter="$(expr $counter + 1)" done - base64 -d output _ak_log_info "Recreation of $treeRootHash succeeded!" } diff --git a/lib/_ak_gpg b/lib/_ak_gpg index 1450c60..bdb8829 100755 --- a/lib/_ak_gpg +++ b/lib/_ak_gpg @@ -24,11 +24,11 @@ source $AK_LIBDIR/_ak_settings export AK_FINGERPRINT="$(_ak_settings_get gpg.fingerprint)" -_ak_gpg(){ +function _ak_gpg(){ gpg2 --homedir $AK_GPGHOME $* } -_ak_gpg_check_or_create(){ +function _ak_gpg_check_or_create(){ _ak_gpg --list-keys | grep kaos@kaos.kaos -B 1 if [ $? -ne 0 ] then @@ -38,7 +38,7 @@ _ak_gpg_check_or_create(){ fi } -_ak_gpg_create_key(){ +function _ak_gpg_create_key(){ _ak_log_debug "Key name: $1" if [ -z $1 ] || [ ! -n "$1" ] then @@ -56,7 +56,7 @@ _ak_gpg_create_key(){ _ak_gpg --batch --passphrase '' --quick-add-key $FINGERPRINT rsa4096 encrypt 0 } -_ak_gpg_key_import_from_file(){ +function _ak_gpg_key_import_from_file(){ if [ -z $1 ] then _ak_log_error "No argument given" @@ -75,11 +75,11 @@ _ak_gpg_key_import_from_file(){ _ak_gpg --import $AK_IPFS_ARTIFACTS/$1 > /dev/null 2>&1 } -_ak_gpg_key_self_get_fingerprint_from_config(){ +function _ak_gpg_key_self_get_fingerprint_from_config(){ _ak_config_show | jq -r '.gpg' } -_ak_gpg_key_self_get_fingerprint(){ +function _ak_gpg_key_self_get_fingerprint(){ if [ -z $1 ] then _ak_ipfs_cat "$(_ak_gpg_key_self_get_fingerprint_from_config)" | \ @@ -92,7 +92,7 @@ _ak_gpg_key_self_get_fingerprint(){ fi } -_ak_gpg_key_get_fingerprint_from_ipfs(){ +function _ak_gpg_key_get_fingerprint_from_ipfs(){ if [ -n "$1" ] then _ak_ipfs_cat "$1" | \ @@ -105,7 +105,7 @@ _ak_gpg_key_get_fingerprint_from_ipfs(){ fi } -_ak_gpg_sign(){ +function _ak_gpg_sign(){ if [ ! -z $1 ] && [ -n "$1" ] && [ ! -z $2 ] && [ -n "$2" ] then _ak_gpg --sign --sign-with $AK_FINGERPRINT --armor --output $1 $2 @@ -114,7 +114,7 @@ _ak_gpg_sign(){ fi } -_ak_gpg_sign_detached(){ +function _ak_gpg_sign_detached(){ if [ ! -z $1 ] && [ -n "$1" ] && [ ! -z $2 ] && [ -n "$2" ] then _ak_gpg --detach-sign --sign-with $AK_FINGERPRINT --armor --output $1 $2 @@ -124,7 +124,7 @@ _ak_gpg_sign_detached(){ fi } -_ak_gpg_sign_clear(){ +function _ak_gpg_sign_clear(){ if [ ! -z $1 ] && [ -n "$1" ] && [ ! -z $2 ] && [ -n "$2" ] then _ak_gpg --clear-sign --sign-with $AK_FINGERPRINT --armor --output $1 $2 @@ -133,7 +133,7 @@ _ak_gpg_sign_clear(){ fi } -_ak_gpg_encrypt_sign(){ +function _ak_gpg_encrypt_sign(){ if [ ! -z $1 ] && [ -n "$1" ] && [ ! -z $2 ] && [ -n "$2" ] && [ ! -z $3 ] && [ -n "$3" ] then _ak_gpg --sign-with $AK_FINGERPRINT --encypt -r $3 --armor --output $1 $2 @@ -142,7 +142,7 @@ _ak_gpg_encrypt_sign(){ fi } -_ak_gpg_encrypt_sign_for_self(){ +function _ak_gpg_encrypt_sign_for_self(){ if [ ! -z $1 ] && [ -n "$1" ] && [ ! -z $2 ] && [ -n "$2" ] then _ak_gpg --sign-with $AK_FINGERPRINT --encypt -r $AK_FINGERPRINT --armor --output $1 $2 @@ -151,7 +151,7 @@ _ak_gpg_encrypt_sign_for_self(){ fi } -_ak_gpg_encrypt(){ +function _ak_gpg_encrypt(){ if [ ! -z $1 ] && [ -n "$1" ] && [ ! -z $2 ] && [ -n "$2" ] && [ ! -z $3 ] && [ -n "$3" ] then _ak_gpg --encypt -r $3 --armor --output $1 $2 @@ -160,7 +160,7 @@ _ak_gpg_encrypt(){ fi } -_ak_gpg_encrypt_for_self(){ +function _ak_gpg_encrypt_for_self(){ if [ ! -z $1 ] && [ -n "$1" ] && [ ! -z $2 ] && [ -n "$2" ] then _ak_gpg --encypt -r $AK_FINGERPRINT --armor --output $1 $2 @@ -169,7 +169,7 @@ _ak_gpg_encrypt_for_self(){ fi } -_ak_gpg_verify_clear_signature(){ +function _ak_gpg_verify_clear_signature(){ if [ ! -z $1 ] && [ -n "$1" ] && [ -f "$1" ] then fingerprint="$(cat $1 | _ak_gpg 2>&1 | grep RSA | awk '{print $5}')" @@ -186,7 +186,7 @@ _ak_gpg_verify_clear_signature(){ fi } -_ak_gpg_verify_signature(){ +function _ak_gpg_verify_signature(){ if [ ! -z $1 ] && [ -n "$1" ] && [ -f "$1" ] && [ ! -z $2 ] && [ -n "$2" ] && [ -f "$2" ] then _ak_gpg --verify $1 $2 > /dev/null 2>&1 @@ -196,7 +196,7 @@ _ak_gpg_verify_signature(){ fi } -_ak_gpg_key_self_export(){ +function _ak_gpg_key_self_export(){ if [ ! -z $1 ] && [ -n "$1" ] then _ak_gpg --armour --output $1 --export $AK_FINGERPRINT @@ -205,15 +205,15 @@ _ak_gpg_key_self_export(){ fi } -_ak_gpg_list_keys_plain(){ +function _ak_gpg_list_keys_plain(){ _ak_gpg --list-keys } -_ak_gpg_list_keys(){ +function _ak_gpg_list_keys(){ _ak_gpg --list-keys | grep '^ ' | awk '{print $1}' } -_ak_gpg_list_keys_long(){ +function _ak_gpg_list_keys_long(){ _ak_gpg --list-keys | \ grep -A 1 '^ \{6\}' | \ tr $'\n' ' ' | \ @@ -224,15 +224,15 @@ _ak_gpg_list_keys_long(){ uniq } -_ak_gpg_list_secret_keys_plain(){ +function _ak_gpg_list_secret_keys_plain(){ _ak_gpg --list-secret-keys } -_ak_gpg_list_secret_keys(){ +function _ak_gpg_list_secret_keys(){ _ak_gpg --list-secret-keys | grep '^ ' | awk '{print $1}' } -_ak_gpg_list_secret_keys_long(){ +function _ak_gpg_list_secret_keys_long(){ _ak_gpg --list-secret-keys | \ grep -A 1 '^ \{6\}' | \ tr $'\n' ' ' | \ @@ -243,7 +243,7 @@ _ak_gpg_list_secret_keys_long(){ uniq } -_ak_gpg_select_key(){ +function _ak_gpg_select_key(){ select x in $(_ak_gpg_list_secret_keys | tr '\n' ' ') do if [ -n "$x" ] @@ -257,7 +257,7 @@ _ak_gpg_select_key(){ done } -_ak_gpg_delete_key(){ +function _ak_gpg_delete_key(){ select x in $(_ak_gpg_list_keys | tr '\n' ' ') do if [ -n "$x" ] @@ -277,7 +277,7 @@ _ak_gpg_delete_key(){ done } -_ak_gpg_delete_secret_key(){ +function _ak_gpg_delete_secret_key(){ if [ ! -z $1 ] then x="$1" diff --git a/lib/_ak_html b/lib/_ak_html index 5a47836..491cb6c 100755 --- a/lib/_ak_html +++ b/lib/_ak_html @@ -19,7 +19,7 @@ ### source $AK_LIBDIR/_ak_log -_ak_generate_html_header(){ +function _ak_generate_html_header(){ printf '\n\n\n' printf 'Arching Kaos Chain Data\n' printf ' \n' @@ -82,7 +82,7 @@ _ak_generate_html_header(){ printf '\n' } -_ak_generate_html_zblock(){ +function _ak_generate_html_zblock(){ if [ ! -z $1 ] && [ -n "$1" ] then arg="$1" @@ -160,7 +160,6 @@ _ak_generate_html_zblock(){ _ak_log_error "Empty datablock value" exit 1 fi - # Output data in HTML format printf '

%s

\n' "$PROGRAM" printf '

🔎 %szblock

\n' "$zblock" diff --git a/lib/_ak_ipfs b/lib/_ak_ipfs index 1297949..f2e0629 100755 --- a/lib/_ak_ipfs +++ b/lib/_ak_ipfs @@ -25,7 +25,7 @@ then mkdir -p $AK_IPFS_ARTIFACTS fi -_ak_ipfs(){ +function _ak_ipfs(){ export IPFS_PATH=$AK_IPFS_REPO; kubo $* if [ $? -ne 0 ] then @@ -34,12 +34,12 @@ _ak_ipfs(){ fi } -_ak_ipfs_daemon(){ +function _ak_ipfs_daemon(){ _ak_ipfs daemon --routing=dht --migrate & printf '%s' "$!" > $AK_WORKDIR/akipfsd.pid } -_ak_ipfs_swarm_connect(){ +function _ak_ipfs_swarm_connect(){ if [ ! -z $1 ] && [ -n "$1" ] then _ak_ipfs swarm connect "$1" @@ -48,7 +48,7 @@ _ak_ipfs_swarm_connect(){ fi } -_ak_ipfs_get_peers(){ +function _ak_ipfs_get_peers(){ _ak_ipfs swarm peers 1> /dev/null 2>&1 if [ $? -eq 0 ] then @@ -56,7 +56,7 @@ _ak_ipfs_get_peers(){ fi } -_ak_ipfs_scanner(){ +function _ak_ipfs_scanner(){ peersIPFSfile="$AK_WORKDIR/peers.ipfs" ak_peersIPFSfile="$AK_WORKDIR/ipfs.peers.akn" if [ ! -f $peersIPFSfile ] @@ -104,7 +104,7 @@ _ak_ipfs_scanner(){ mv walk.aknet $ak_peersIPFSfile } -_ak_ipfs_add(){ +function _ak_ipfs_add(){ if [ -z $1 ] || [ ! -n "$1" ] then _ak_log_error "no argument given" @@ -120,7 +120,7 @@ _ak_ipfs_add(){ fi } -_ak_ipfs_block_stat(){ +function _ak_ipfs_block_stat(){ if [ -z $1 ] || [ ! -n "$1" ] then _ak_log_error "no argument given" @@ -134,7 +134,7 @@ _ak_ipfs_block_stat(){ fi } -_ak_ipfs_files_cp(){ +function _ak_ipfs_files_cp(){ if [ -z $1 ] || [ ! -n "$1" ] then _ak_log_error "Source: No argument given" @@ -153,7 +153,7 @@ _ak_ipfs_files_cp(){ fi } -_ak_ipfs_files_ls(){ +function _ak_ipfs_files_ls(){ _ak_ipfs files ls "$1" if [ $? -ne 0 ] then @@ -162,7 +162,7 @@ _ak_ipfs_files_ls(){ fi } -_ak_ipfs_files_mkdir(){ +function _ak_ipfs_files_mkdir(){ if [ -z $1 ] || [ ! -n "$1" ] then _ak_log_error "No argument given" @@ -176,7 +176,7 @@ _ak_ipfs_files_mkdir(){ fi } -_ak_ipfs_files_mv(){ +function _ak_ipfs_files_mv(){ if [ -z $1 ] || [ ! -n "$1" ] then _ak_log_error "No argument given" @@ -195,7 +195,7 @@ _ak_ipfs_files_mv(){ fi } -_ak_ipfs_files_rm(){ +function _ak_ipfs_files_rm(){ if [ -z $1 ] || [ ! -n "$1" ] then _ak_log_error "No argument given" @@ -209,7 +209,7 @@ _ak_ipfs_files_rm(){ fi } -_ak_ipfs_files_stat(){ +function _ak_ipfs_files_stat(){ if [ -z $1 ] || [ ! -n "$1" ] then _ak_log_error "No argument given" @@ -223,7 +223,7 @@ _ak_ipfs_files_stat(){ fi } -_ak_ipfs_get(){ +function _ak_ipfs_get(){ if [ -z $1 ] || [ ! -n "$1" ] then _ak_log_error "No argument given" @@ -244,7 +244,7 @@ _ak_ipfs_get(){ fi } -_ak_ipfs_cat(){ +function _ak_ipfs_cat(){ if [ -z $1 ] || [ ! -n "$1" ] then _ak_log_error "no argument given" @@ -262,8 +262,7 @@ _ak_ipfs_cat(){ fi } - -_ak_ipfs_key_gen(){ +function _ak_ipfs_key_gen(){ if [ -z $1 ] || [ ! -n "$1" ] then _ak_log_error "No argument given" @@ -277,7 +276,7 @@ _ak_ipfs_key_gen(){ fi } -_ak_ipfs_key_list(){ +function _ak_ipfs_key_list(){ _ak_ipfs key list if [ $? -ne 0 ] then @@ -286,7 +285,7 @@ _ak_ipfs_key_list(){ fi } -_ak_ipfs_key_list_full(){ +function _ak_ipfs_key_list_full(){ _ak_ipfs key list -l if [ $? -ne 0 ] then @@ -295,7 +294,7 @@ _ak_ipfs_key_list_full(){ fi } -_ak_ipfs_name_publish(){ +function _ak_ipfs_name_publish(){ if [ -z $1 ] || [ ! -n "$1" ] then _ak_log_error "No argument given" @@ -314,7 +313,7 @@ _ak_ipfs_name_publish(){ fi } -_ak_ipfs_config_publish(){ +function _ak_ipfs_config_publish(){ if [ -z $1 ] || [ ! -n "$1" ] then _ak_log_error "No argument given" @@ -324,7 +323,7 @@ _ak_ipfs_config_publish(){ _ak_ipfs_name_publish "ak-config" $1 } -_ak_ipfs_name_resolve(){ +function _ak_ipfs_name_resolve(){ if [ -z $1 ] || [ ! -n "$1" ] then _ak_log_error "No argument given" @@ -338,7 +337,7 @@ _ak_ipfs_name_resolve(){ fi } -_ak_ipfs_swarm_peers(){ +function _ak_ipfs_swarm_peers(){ _ak_ipfs swarm peers if [ $? -ne 0 ] then @@ -347,7 +346,7 @@ _ak_ipfs_swarm_peers(){ fi } -_ak_ipfs_starter(){ +function _ak_ipfs_starter(){ _ak_ipfs_daemon if [ $? -ne 0 ] then @@ -363,7 +362,7 @@ _ak_ipfs_starter(){ fi } -_ak_ipns_resolve(){ +function _ak_ipns_resolve(){ if [ ! -z $1 ] then rsld=$(_ak_ipfs_name_resolve $1) @@ -380,7 +379,7 @@ _ak_ipns_resolve(){ fi } -_ak_ipfs_check_config_key(){ +function _ak_ipfs_check_config_key(){ _ak_ipfs_key_list | grep ak-config > /dev/null if [ $? -ne 0 ] then @@ -397,7 +396,7 @@ _ak_ipfs_check_config_key(){ fi } -_ak_ipfs_check_zchain_key(){ +function _ak_ipfs_check_zchain_key(){ _ak_ipfs_key_list | grep zchain > /dev/null if [ $? -ne 0 ] then @@ -414,7 +413,7 @@ _ak_ipfs_check_zchain_key(){ fi } -_ak_ipfs_check_zarchive_dir(){ +function _ak_ipfs_check_zarchive_dir(){ _ak_ipfs_files_ls /zarchive > /dev/null if [ $? -ne 0 ] then @@ -424,7 +423,7 @@ _ak_ipfs_check_zarchive_dir(){ fi } -_ak_ipfs_check_zlatest_file(){ +function _ak_ipfs_check_zlatest_file(){ _ak_ipfs_files_ls /zlatest > /dev/null if [ $? -ne 0 ] then @@ -434,14 +433,14 @@ _ak_ipfs_check_zlatest_file(){ fi } -_ak_ipfs_check(){ +function _ak_ipfs_check(){ _ak_ipfs_check_zarchive_dir _ak_ipfs_check_zlatest_file _ak_ipfs_check_config_key _ak_ipfs_check_zchain_key } -_ak_ipfs_init(){ +function _ak_ipfs_init(){ if [ ! -d $AK_IPFS_REPO ] then mkdir $AK_IPFS_REPO @@ -449,7 +448,7 @@ _ak_ipfs_init(){ fi } -_ak_ipfs_download(){ +function _ak_ipfs_download(){ _ak_log_info "Attempting to install IPFS..." IPFS_VERSION="$(curl \ --connect-timeout 3 \ @@ -481,7 +480,7 @@ _ak_ipfs_download(){ fi } -_ak_ipfs_cid_v0_check(){ +function _ak_ipfs_cid_v0_check(){ if [ -z $1 ] || [ ! -n "$1" ] then _ak_log_error "_ak_ipfs_cid_v0_check: No argument given" @@ -501,7 +500,7 @@ _ak_ipfs_cid_v0_check(){ _ak_log_debug "_ak_ipfs_cid_v0_check: $1 provided is an IPFS CIDv0 string" } -_ak_ipfs_swarm_install(){ +function _ak_ipfs_swarm_install(){ SWARMSHA512SUM="7001e37412758c43d372a969e977ca11511e034c8c1e233a58dc3ce1c6f3c1aa7d2da8cba9944a5eabaa8885742bfe6cc6794224c146b7129da8f633b53b9cfc" if [ ! -f $AK_IPFS_REPO/swarm.key ] then @@ -516,6 +515,6 @@ _ak_ipfs_swarm_install(){ fi } -_ak_ipfs_get_config_ipns_key(){ +function _ak_ipfs_get_config_ipns_key(){ _ak_ipfs_key_list_full | grep 'ak-config' | cut -d ' ' -f 1 } diff --git a/lib/_ak_log b/lib/_ak_log index f6ffc21..8d6972d 100755 --- a/lib/_ak_log +++ b/lib/_ak_log @@ -18,7 +18,7 @@ ### along with this program. If not, see . ### -_ak_log_print_log_line(){ +function _ak_log_print_log_line(){ if [ -n "$1" ] then timestamp="$(echo "$*" | awk '{print $1}')" @@ -33,14 +33,14 @@ _ak_log_print_log_line(){ fi } -_ak_log_follow(){ +function _ak_log_follow(){ tail -f $AK_LOGSFILE | while read -r p || [ -n "$p" ] do _ak_log_print_log_line "$p" done } -_ak_log_grep(){ +function _ak_log_grep(){ if [ ! -z $1 ] && [ -n "$1" ] then if [ "$1" == "-h" ] || [ "$1" == "--help" ] @@ -50,7 +50,6 @@ _ak_log_grep(){ exit 1 fi fi - echo "The following scripts have entries in the log file." echo "Select one of those by entering the number of it below and hit enter:" select x in $(cat $AK_LOGSFILE | cut -d ' ' -f 2 | sort | uniq) @@ -63,7 +62,7 @@ _ak_log_grep(){ done } -_ak_log_rotate(){ +function _ak_log_rotate(){ if [ -f $AK_LOGSFILE ] then tar cvfz $AK_ARCHIVESDIR/logs_$(date -u +%s).tar.gz $AK_WORKDIR/logs @@ -76,7 +75,7 @@ _ak_log_rotate(){ fi } -_ak_log_message(){ +function _ak_log_message(){ TS="$(date -u +%s)" if [ ! -z $1 ] && [ -n "$1" ] then @@ -116,23 +115,23 @@ _ak_log_message(){ fi } -_ak_log_exit(){ +function _ak_log_exit(){ _ak_log_message "$PROGRAM" "EXIT" "$1" } -_ak_log_warning(){ +function _ak_log_warning(){ _ak_log_message "$PROGRAM" "WARNING" "$1" } -_ak_log_debug(){ +function _ak_log_debug(){ _ak_log_message "$PROGRAM" "DEBUG" "$1" } -_ak_log_error(){ +function _ak_log_error(){ _ak_log_message "$PROGRAM" "ERROR" "$1" } -_ak_log_info(){ +function _ak_log_info(){ _ak_log_message "$PROGRAM" "INFO" "$1" } diff --git a/lib/_ak_network b/lib/_ak_network index a6faf87..2bddfd5 100755 --- a/lib/_ak_network +++ b/lib/_ak_network @@ -22,7 +22,7 @@ source $AK_LIBDIR/_ak_ipfs cjdnstoolspath="$HOME/cjdns/tools" -_ak_network_stellar_show_ids(){ +function _ak_network_stellar_show_ids(){ i=0 flag=0 while [ "$i" -lt "$limit" ] @@ -47,19 +47,19 @@ _ak_network_stellar_show_ids(){ done } -_ak_network_stellar_get_next_page(){ +function _ak_network_stellar_get_next_page(){ cat $tempfile | jq -r '._links.next.href' # cat $tempfile | grep -1 next | grep https | sed -e 's/^.*https/https/' | sed -e 's/\u0026/\&/g; s/"//g; s/\\//g' } -_ak_network_stellar_proceed_to_next_page(){ +function _ak_network_stellar_proceed_to_next_page(){ nextURL="$(_ak_network_stellar_get_next_page)" curl \ --connect-timeout 3 \ "$nextURL" > $tempfile 2>/dev/null } -_ak_network_stellar_get_asset_holders(){ +function _ak_network_stellar_get_asset_holders(){ if [ ! -z $1 ] && [ $1 -gt 0 ] && [ -n "$1" ] then limit=$1 @@ -71,11 +71,10 @@ _ak_network_stellar_get_asset_holders(){ https://horizon.stellar.org/accounts\?asset\=ARCHINGKAOS:GB4QVKD6NW3CSNO5TNPARAWNPPXOPSSTKB35XCWB7PUNBIQTK3DVELB2\&limit\=$limit > $tempfile 2>/dev/null } -_ak_network_scan_stellar(){ +function _ak_network_scan_stellar(){ tempdir=`_ak_make_temp_directory` tempfile="$tempdir/tmp" tempaddr="$tempdir/tmpaddr" - stellarParticipants="$AK_WORKDIR/stellar-network-participants" stellarParticipantsOnline="$AK_WORKDIR/stellar-network-participants-online" if [ ! -f "$stellarParticipants" ] @@ -94,21 +93,18 @@ _ak_network_scan_stellar(){ then touch $tempaddr fi - if [ ! -z $1 ] && [ "$1" == "-l" ] && [ ! -z $2 ] then limit=$2 else limit=3 fi - _ak_network_stellar_get_asset_holders $limit while [ "$(tail -1 $stellarParticipants)" != "null" ] do _ak_network_stellar_show_ids _ak_network_stellar_proceed_to_next_page done - grep G $stellarParticipants > $tempaddr cat $tempaddr > $stellarParticipants rm $tempfile $tempaddr @@ -140,11 +136,11 @@ _ak_network_scan_stellar(){ done < $stellarParticipants } -_ak_network_scan_ipfs(){ +function _ak_network_scan_ipfs(){ _ak_not_implemented _ak_network_scan_ipfs } -_ak_network_scan_cjdns_dump(){ +function _ak_network_scan_cjdns_dump(){ # # Needs CJDNS tools in your PATH # @@ -208,7 +204,7 @@ _ak_network_scan_cjdns_dump(){ rm -rf $TEMPDIR } -_ak_network_scan_cjdns_full(){ +function _ak_network_scan_cjdns_full(){ # This scan is using HIA resources to scan the whole cjdns network for peers # # Ref: @@ -276,7 +272,7 @@ _ak_network_scan_cjdns_full(){ rm -rf $TEMPDIR } -_ak_network_scan_yggdrasil_full(){ +function _ak_network_scan_yggdrasil_full(){ # This scan is using HIA resources to scan the whole cjdns network for peers # # Ref: @@ -331,7 +327,7 @@ _ak_network_scan_yggdrasil_full(){ rm -rf $TEMPDIR } -_ak_network_scan_cjdns(){ +function _ak_network_scan_cjdns(){ if [ ! -z $1 ] && [ -n "$1" ] then case $1 in @@ -344,7 +340,7 @@ _ak_network_scan_cjdns(){ fi } -_ak_network_scan_yggdrasil(){ +function _ak_network_scan_yggdrasil(){ if [ ! -z $1 ] && [ -n "$1" ] then case $1 in @@ -355,7 +351,7 @@ _ak_network_scan_yggdrasil(){ fi } -_ak_network_scan(){ +function _ak_network_scan(){ if [ ! -z $1 ] && [ -n "$1" ] then case $1 in @@ -372,7 +368,7 @@ _ak_network_scan(){ _ak_network_scan_yggdrasil fi } -_ak_network_show_peers_stellar(){ +function _ak_network_show_peers_stellar(){ stellarParticipants="$AK_WORKDIR/stellar-network-participants" stellarParticipantsOnline="$AK_WORKDIR/stellar-network-participants-online" if [ -f "${stellarParticipantsOnline}" ] @@ -400,7 +396,7 @@ _ak_network_show_peers_stellar(){ fi } -_ak_network_show_peers_cjdns(){ +function _ak_network_show_peers_cjdns(){ if [ -f $AK_ZPEERSFILE.hyperboria ] then cat $AK_ZPEERSFILE.hyperboria | jq @@ -409,7 +405,7 @@ _ak_network_show_peers_cjdns(){ fi } -_ak_network_show_peers_yggdrasil(){ +function _ak_network_show_peers_yggdrasil(){ if [ -f $AK_ZPEERSFILE.yggdrasil ] then cat $AK_ZPEERSFILE.yggdrasil | jq @@ -418,11 +414,11 @@ _ak_network_show_peers_yggdrasil(){ fi } -_ak_network_show_peers_ipfs(){ +function _ak_network_show_peers_ipfs(){ _ak_not_implemented _ak_network_show_peers_ipfs } -_ak_network_show_peers(){ +function _ak_network_show_peers(){ if [ ! -z $1 ] && [ -n "$1" ] then case $1 in @@ -440,14 +436,14 @@ _ak_network_show_peers(){ fi } -_ak_network_ipfs_connect_bootstrap(){ +function _ak_network_ipfs_connect_bootstrap(){ curl -s "https://arching-kaos.net/files/ak_ipfs_bootstrap_peers" | while read peer do _ak_ipfs_swarm_connect "$peer" done } -_ak_network_cjdns_connect(){ +function _ak_network_cjdns_connect(){ if [ ! -z $1 ] && [ -n "$1" ] && [ -f $1 ] then peersfile="$1" @@ -481,11 +477,11 @@ _ak_network_cjdns_connect(){ fi } -_ak_network_cjdns_connect_bootstrap(){ +function _ak_network_cjdns_connect_bootstrap(){ _ak_network_cjdns_connect } -_ak_network_connect(){ +function _ak_network_connect(){ if [ ! -z $1 ] && [ -n "$1" ] then case $1 in diff --git a/lib/_ak_node b/lib/_ak_node index 1cc009a..04aa07b 100755 --- a/lib/_ak_node +++ b/lib/_ak_node @@ -21,12 +21,12 @@ source $AK_LIBDIR/_ak_ipfs # Resolves the IPNS key "ak-config" to its current IPFS value # Return IPFS CIDv0 without /ipfs/ prefix -_ak_node_info_ipfs_hash(){ +function _ak_node_info_ipfs_hash(){ _ak_ipfs_name_resolve /ipns/$(_ak_node_info_ipns_key) | sed -e 's/\/ipfs\///' } # Finds ak-config ipns key # Returns IPNS key -_ak_node_info_ipns_key(){ +function _ak_node_info_ipns_key(){ _ak_ipfs_key_list_full | grep ak-config | awk '{print $1}' } diff --git a/lib/_ak_sblock b/lib/_ak_sblock index 6af345a..22706d3 100755 --- a/lib/_ak_sblock +++ b/lib/_ak_sblock @@ -20,7 +20,7 @@ source $AK_LIBDIR/_ak_log -_ak_sblock_show(){ +function _ak_sblock_show(){ if [ ! -z $1 ] then cat $AK_MINEDBLOCKSDIR/$1 | jq diff --git a/lib/_ak_schain b/lib/_ak_schain index a858fa7..e232cd2 100755 --- a/lib/_ak_schain +++ b/lib/_ak_schain @@ -23,7 +23,7 @@ source $AK_LIBDIR/_ak_sblock AK_SCHAINSDIR=$AK_WORKDIR/schains GENESIS="00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" -_ak_schain_latest_cached(){ +function _ak_schain_latest_cached(){ if [ ! -f $AK_WORKDIR/schain.latest ] then _ak_schain_get_latest > $AK_WORKDIR/schain.latest @@ -31,7 +31,7 @@ _ak_schain_latest_cached(){ cat $AK_WORKDIR/schain.latest } -_ak_schain_tidy(){ +function _ak_schain_tidy(){ SLATEST=$(_ak_schain_get_latest | jq -r '.latest_block') if [ ! -d $AK_SCHAINSDIR ] then @@ -39,11 +39,11 @@ _ak_schain_tidy(){ fi } -_ak_schain_block_latest_block_hash(){ +function _ak_schain_block_latest_block_hash(){ _ak_schain_get_latest | jq -r '.latest_block' } -_ak_schain_crawl(){ +function _ak_schain_crawl(){ if [ ! -z $1 ] && [ -n "$1" ] then CUR_TARGET="$1" @@ -51,7 +51,6 @@ _ak_schain_crawl(){ _ak_log_warning "No next target found. So long for $1" exit 1 fi - if [ $counter -eq 0 ] then echo '[' @@ -69,7 +68,6 @@ _ak_schain_crawl(){ echo ',' counter=$(($counter + 1)) fi - if [ "$1" == "$GENESIS" ] then echo '{"genesis":"genesis"}' | jq @@ -77,7 +75,6 @@ _ak_schain_crawl(){ _ak_log_warning "Looks like genesis. Exiting with 0" exit 0 fi - if [ ! -f "$AK_MINEDBLOCKSDIR/$CUR_TARGET" ] then _ak_log_warning "Could not find $CUR_TARGET" @@ -90,7 +87,7 @@ _ak_schain_crawl(){ fi } -_ak_schain_crawl_interface(){ +function _ak_schain_crawl_interface(){ LIMIT_ENABLED="no" LIMIT=0 counter=0 @@ -113,7 +110,7 @@ _ak_schain_crawl_interface(){ fi } -_ak_schain_count_schain(){ +function _ak_schain_count_schain(){ echo -n $1 | grep -e '[0-9a-f]\{128\}' > /dev/null if [ $? -ne 0 ] then @@ -145,7 +142,7 @@ _ak_schain_count_schain(){ fi } -_ak_sblock_get_latest_from_haystack_of_sblocks(){ +function _ak_sblock_get_latest_from_haystack_of_sblocks(){ templistblock="$(_ak_make_temp_file)" tempcounters="$(_ak_make_temp_directory)" max="$(_ak_make_temp_file)" @@ -191,6 +188,6 @@ _ak_sblock_get_latest_from_haystack_of_sblocks(){ printf '{"latest_block":"%s"}' "$(cat $max_holder)" | tee $AK_WORKDIR/schain.latest } -_ak_schain_get_latest(){ +function _ak_schain_get_latest(){ _ak_sblock_get_latest_from_haystack_of_sblocks } diff --git a/lib/_ak_settings b/lib/_ak_settings index 725ab5c..5b6b0bb 100755 --- a/lib/_ak_settings +++ b/lib/_ak_settings @@ -20,7 +20,7 @@ source $AK_LIBDIR/_ak_script -_ak_settings_get(){ +function _ak_settings_get(){ if [ ! -z "$1" ] && [ -n "$1" ] then cd $AK_SETTINGS @@ -71,7 +71,7 @@ _ak_settings_get(){ fi } -_ak_settings_set(){ +function _ak_settings_set(){ if [ ! -z "$1" ] && [ -n "$1" ] then echo $1 | grep '\.\.' > /dev/null 2>&1 @@ -125,10 +125,10 @@ _ak_settings_set(){ fi } -_ak_settings_get_sub(){ +function _ak_settings_get_sub(){ _ak_not_implemented } -_ak_settings_get_all(){ +function _ak_settings_get_all(){ _ak_not_implemented } diff --git a/lib/_ak_smfiles b/lib/_ak_smfiles index 4663b45..6cb7ef8 100755 --- a/lib/_ak_smfiles +++ b/lib/_ak_smfiles @@ -73,17 +73,14 @@ else _ak_log_info "Workdir found" fi -cdaw(){ +function cdaw(){ pwd > tmp_holder } -_ak_sm_file_joiner(){ +function _ak_sm_file_joiner(){ cdaw - CURDIR="$(cat tmp_holder)" - TMPWD="/tmp/rjs" - if [ ! -d "$TMPWD" ] then mkdir -p "$TMPWD" @@ -93,46 +90,34 @@ _ak_sm_file_joiner(){ exit 1 fi fi - cd $CHKDIR if [ $? -ne 0 ] then _ak_log_error "Can't get dir" exit 1 fi - if [ ! -z $1 ] then MAPSFILE="$1" - echo '#!/usr/bin/env 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" "}' $FILEMAPSDIR/$MAPSFILE| grep chk >> script - bash script - if [ $? -ne 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 -n 1 $FILEMAPSDIR/$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 $FILEMAPSDIR/$MAPSFILE|grep chk|awk '{print $2" "}'|tr -d '\n')) > $OUTPUT - # We check if everything is okay sha512sum -c $FILEMAPSDIR/$MAPSFILE if [ $? -ne 0 ] @@ -140,11 +125,8 @@ _ak_sm_file_joiner(){ _ak_log_error "Error while checking sums" exit 1 fi - mv $OUTPUT $CURDIR - rm -rf "$TMPWD" - rm $CURDIR/tmp_holder else _ak_log_error "No hash given" @@ -152,7 +134,7 @@ _ak_sm_file_joiner(){ fi } -_ak_sm_file_splitter(){ +function _ak_sm_file_splitter(){ # # The concept is simple # @@ -170,10 +152,8 @@ _ak_sm_file_splitter(){ # # 6. We are done! # - # Uncomment next line if you want to debug # set -xe - if [ ! -f "$1" ] then echo "ERROR File not found" @@ -181,44 +161,32 @@ _ak_sm_file_splitter(){ else FILE="$1" 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/lib/_ak_zblock b/lib/_ak_zblock index 6edf33c..667bf80 100755 --- a/lib/_ak_zblock +++ b/lib/_ak_zblock @@ -29,7 +29,7 @@ then mkdir $AK_WORKDIR/ipfs fi -_ak_data_expand(){ +function _ak_data_expand(){ if [ ! -z $1 ] && [ ! -z $2 ] && [ -n "$1" ] && [ -n "$2" ] then TEMP="$(_ak_make_temp_directory)" @@ -127,7 +127,7 @@ _ak_data_expand(){ # # Returns a JSON array representing the chain retrieved. # Logs messages to $LOGSFILE. -_ak_zblock_show(){ +function _ak_zblock_show(){ verify=1 if [ ! -z $1 ] && [ -n "$1" ] then @@ -149,9 +149,7 @@ _ak_zblock_show(){ timestamp='' # Announce to logs which ZBLOCK is being read at the moment _ak_log_info "Examining $zblock" - _ak_ipfs_cid_v0_check "$zblock" - # We check if any $zblock at all... # TODO: Eliminate outputing to file since we store all cat/get'ed # ipfs hashes on local fs. @@ -174,7 +172,6 @@ _ak_zblock_show(){ echo -n '{' # echo -n '"id":"'$counter'",' echo -n '"zblock":"'$zblock'",' - # Be sure that there are the expected values # We need 'block' and 'block_signature' inside a 'zblock' # Exit if any is missing @@ -186,7 +183,6 @@ _ak_zblock_show(){ fi _ak_ipfs_cid_v0_check "$block" _ak_log_debug "ZBLOCK $zblock has block $block" - block_signature="$(cat $AK_IPFS_ARTIFACTS/$zblock | jq -M -r .block_signature)" if [ "$block_signature" == "null" ] then @@ -195,12 +191,10 @@ _ak_zblock_show(){ fi _ak_ipfs_cid_v0_check "$block_signature" _ak_log_debug "ZBLOCK $zblock contains a BLOCK_SIGNATURE $block_signature" - # Same as above applies to BLOCK and DATA subparts of each ZBLOCK # BLOCKS echo -n '"block":"'$block'",' echo -n '"block_signature":"'$block_signature'",' - _ak_ipfs_cat $block | jq -c -M > /dev/null 2>&1 cat $AK_IPFS_ARTIFACTS/$block | jq -M > /dev/null 2>&1 if [ $? -ne 0 ] @@ -208,7 +202,6 @@ _ak_zblock_show(){ _ak_log_error "BLOCK $block READ failed" exit 1 fi - grep -e 'timestamp' -e 'gpg' -e 'data' -e 'action' -e 'detach' -e 'previous' $AK_IPFS_ARTIFACTS/$block > /dev/null 2>&1 if [ $? -ne 0 ] then @@ -216,30 +209,22 @@ _ak_zblock_show(){ exit 1 fi _ak_log_debug "BLOCK $block is a block" - action="$(cat $AK_IPFS_ARTIFACTS/$block | jq -M -r .action)" module="$(echo $action | sed -e 's/\// /g' | awk '{ print $1 }')" _ak_log_debug "DATA is $module module." - command="$(echo $action | sed -e 's/\// /g' | awk '{ print $2 }')" _ak_log_debug "COMMAND is $command" - timestamp="$(cat $AK_IPFS_ARTIFACTS/$block | jq -M -r .timestamp)" if [ "$timestamp" != "null" ] then echo -n '"timestamp":"'$timestamp'",' fi - detach="$(cat $AK_IPFS_ARTIFACTS/$block | jq -M -r .detach)" echo -n '"detach":"'$detach'",' - echo -n '"module":"'$module'",' - echo -n '"action":"'$command'",' - gpg="$(cat $AK_IPFS_ARTIFACTS/$block | jq -M -r .gpg)" echo -n '"gpg":"'$gpg'",' - if [ $verify -eq 1 ] then _ak_ipfs_get $gpg > /dev/null 2>&1 @@ -262,7 +247,6 @@ _ak_zblock_show(){ fi ln -s $AK_IPFS_ARTIFACTS/$block_signature $TEMP/$block.asc _ak_log_info "BLOCK_SIGNATURE $block_signature downloaded" - _ak_ipfs_get $block > /dev/null 2>&1 if [ $? -ne 0 ] then @@ -270,7 +254,6 @@ _ak_zblock_show(){ exit 1 fi _ak_log_info "BLOCK $block downloaded" - _ak_gpg_verify_signature $TEMP/$block.asc $AK_IPFS_ARTIFACTS/$block > /dev/null 2>&1 if [ $? -ne 0 ] then @@ -279,7 +262,6 @@ _ak_zblock_show(){ fi _ak_log_info "$gpg signature of $block is verified." fi - data="$(cat $AK_IPFS_ARTIFACTS/$block | jq -M -r .data)" _ak_ipfs_cid_v0_check "$data" _ak_data_expand $data $gpg @@ -288,13 +270,11 @@ _ak_zblock_show(){ _ak_log_error "Failed on data signature verification [data: $data, gpg: $gpg, zblock: $zblock]" exit 1 fi - # DATA # Only print to stdout # _ak_ipfs_cat $data # touch $AK_DATADIR/$data # ^ unreasonable? - # 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. @@ -305,7 +285,6 @@ _ak_zblock_show(){ echo -n '"previous":"'$seed'"},{"genesis":"genesis"}]' _ak_log_info "Reached pseudo-genesis, counted $counter zblocks." exit 2 - # Otherwise, we inform of the sequence else #echo "$zblock after $previous" @@ -313,7 +292,6 @@ _ak_zblock_show(){ 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" ] @@ -474,7 +452,7 @@ _ak_zblock_show(){ # # } -_ak_zblock_gen_html(){ +function _ak_zblock_gen_html(){ time_started=$(date -u +%s.%N) ss=$(echo $time_started | cut -d '.' -f 1) nss=$(echo $time_started | cut -d '.' -f 2) @@ -485,7 +463,6 @@ _ak_zblock_gen_html(){ _ak_help exit 1 fi - if [ -n "$1" ] then TEST="$(echo -n "$1" | grep -v '^Qm[A-Za-z0-9]\{44\}$')" @@ -495,13 +472,10 @@ _ak_zblock_gen_html(){ exit 1 fi fi - arg="$(_ak_make_temp_file)" _ak_zblock_show "$1" | jq > $arg - _ak_generate_html_header > zblock-$1.html _ak_generate_html_zblock $arg >> zblock-$1.html - time_ended=$(date -u +%s.%N) se=$(echo $time_ended | cut -d '.' -f 1) nse=$(echo $time_ended | cut -d '.' -f 2) @@ -515,17 +489,15 @@ _ak_zblock_gen_html(){ fi printf '' >> zblock-$1.html printf '' >> zblock-$1.html - rm $arg } -_ak_zblock_cache(){ +function _ak_zblock_cache(){ if [ ! -d "$AK_CACHEDIR/fzblocks" ] then mkdir $AK_CACHEDIR/fzblocks fi FZBLOCKSDIR="$AK_CACHEDIR/fzblocks" - if [ ! -z "$1" ] && [ -n "$1" ] then if [ -f "$AK_ZBLOCKDIR/$1" ] && [ "$( (du -b $AK_ZBLOCKDIR/$1 || du -A $AK_ZBLOCKDIR/$1)2>/dev/null | awk '{ print $1 }')" != "0" ] @@ -557,10 +529,9 @@ _ak_zblock_cache(){ _ak_log_error "No arguments..." exit 1 fi - } -_ak_zblock_repack(){ +function _ak_zblock_repack(){ if [ -z $1 ] || [ ! -n "$1" ] then _ak_log_error "No zblock hash provided" @@ -585,9 +556,7 @@ _ak_zblock_repack(){ exit 1 fi zblock_to_repack_at="$2" - MESSAGE="$zblock_to_repack" - ACTION="$(_ak_zblock_show $zblock_to_repack | jq -r '.module,.action' | tr $'\n' '/' | sed -e 's/\/$//g')" if [ ! -n "$ACTION" ] then @@ -600,36 +569,28 @@ _ak_zblock_repack(){ exit 1 fi data="$(_ak_zblock_show $zblock_to_repack | jq -r '.data')" - if [ ! -f $AK_IPFS_ARTIFACTS/$data ] then _ak_log_error "$data file doesn't exist" exit 1 fi _ak_log_info "We are repacking $ACTION with content $MESSAGE at $zblock_to_repack_at" - - MESSAGE_HASH="$data" - # We create a detached and armor signature of it MESSAGE_SIGN_FILE="$data.asc" _ak_gpg_sign_detached $MESSAGE_SIGN_FILE $AK_IPFS_ARTIFACTS/$data _ak_log_debug "Signature made for $data" - # We add the signature to IPFS MESSAGE_SIGNATURE=$(_ak_ipfs_add $MESSAGE_SIGN_FILE) _ak_log_debug "Hash made for $data: $MESSAGE_SIGNATURE" - # We will be using our public key also to put it in the block later KEY="self.pub" _ak_gpg_key_self_export $KEY GPG_PUB_KEY=$(_ak_ipfs_add $KEY) _ak_log_debug "Key: $GPG_PUB_KEY" - # Acquire last block of information, to chain this one with previous posted PREVIOUS="$zblock_to_repack_at" _ak_log_debug "Previous: $PREVIOUS" - # We create a block of json like this: printf '{"timestamp":"%s","action":"%s","data":"%s","detach":"%s","gpg":"%s","previous":"%s"}' $(date -u +%s) $ACTION $MESSAGE_HASH $MESSAGE_SIGNATURE $GPG_PUB_KEY $PREVIOUS > block BLOCK="block" @@ -637,15 +598,12 @@ _ak_zblock_repack(){ # We have a block now, so we sign it _ak_gpg_sign_detached $BLOCK_SIG $BLOCK _ak_log_debug "Signature made for block" - # We now add the signature to IPFS BLOCK_SIGNATURE=$(_ak_ipfs_add $BLOCK_SIG) _ak_log_debug "Block signature hash: $BLOCK_SIGNATURE" - # We also add the block! BLOCK=$(_ak_ipfs_add $BLOCK) _ak_log_debug "Block hash: $BLOCK" - # So we now do the think almost again printf '{"block":"%s","block_signature":"%s"}' $BLOCK $BLOCK_SIGNATURE > zblock ZBL="zblock" @@ -653,7 +611,6 @@ _ak_zblock_repack(){ ZBLOCK=$(_ak_ipfs_add $ZBL) echo $ZBLOCK _ak_log_debug "Zblock hash: $ZBLOCK" - # cat $PWD/zblock | jq -M # Optional or extending with # python send_as_ak_tx $ZBLOCK @@ -702,7 +659,7 @@ _ak_zblock_repack(){ fi } -_ak_zblock_pack(){ +function _ak_zblock_pack(){ if [ ! -z $2 ] then MESSAGE="$2" @@ -721,39 +678,30 @@ _ak_zblock_pack(){ fi done < tempisalreadythere rm tempisalreadythere - _ak_log_info "We are doing $ACTION with content $MESSAGE" # We add it to IPFS MESSAGE_HASH=$(_ak_ipfs_add $MESSAGE) - # We create a detached and armor signature of it MESSAGE_SIGN_FILE=$MESSAGE".asc" _ak_gpg_sign_detached $MESSAGE_SIGN_FILE $MESSAGE - # We add the signature to IPFS 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" _ak_gpg_key_self_export $KEY GPG_PUB_KEY=$(_ak_ipfs_add $KEY) - # Acquire last block of information, to chain this one with previous posted PREVIOUS=$(_ak_ipfs_files_stat /zlatest | head -n 1) - # We create a block of json like this: printf '{"timestamp":"%s","action":"%s","data":"%s","detach":"%s","gpg":"%s","previous":"%s"}' $(date -u +%s) $ACTION $MESSAGE_HASH $MESSAGE_SIGNATURE $GPG_PUB_KEY $PREVIOUS > block BLOCK="block" BLOCK_SIG=$BLOCK".asc" # We have a block now, so we sign it _ak_gpg_sign_detached $BLOCK_SIG $BLOCK - # We now add the signature to IPFS BLOCK_SIGNATURE=$(_ak_ipfs_add $BLOCK_SIG) - # We also add the block! BLOCK=$(_ak_ipfs_add $BLOCK) - # So we now do the think almost again printf '{"block":"%s","block_signature":"%s"}' $BLOCK $BLOCK_SIGNATURE > zblock ZBL="zblock" @@ -764,7 +712,6 @@ _ak_zblock_pack(){ _ak_log_error "File does not exist. Aborting..." exit 1 fi - # cat $PWD/zblock | jq -M # Optional or extending with # python send_as_ak_tx $ZBLOCK @@ -815,10 +762,9 @@ _ak_zblock_pack(){ _ak_log_error "Not enough arguments" exit 1 fi - } -_ak_zblock_announce(){ +function _ak_zblock_announce(){ if [ ! -z "$1" ] && [ -n "$1" ] then curl \ -- cgit v1.2.3