From 30a2bc6cc950bcd460e5a3651ab869a732a0f50b Mon Sep 17 00:00:00 2001 From: kaotisk Date: Sun, 30 Jun 2024 07:01:15 +0300 Subject: Refactoring --- api/tests/announce_zblock.sh | 6 +++--- api/tests/announce_zchain_link.sh | 6 +++--- api/tests/default_route.sh | 2 +- api/tests/gathered_zblocks.sh | 4 ++-- api/tests/gathered_zchain_zlatest_pairs.sh | 2 +- bin/ak-profile | 2 +- bin/ak-sm-filejoiner | 8 ++++---- bin/ak-sm-filesplitter | 6 +++--- init.sh | 12 ++++++------ lib/_ak_fs | 2 +- lib/_ak_ipfs | 2 +- lib/_ak_network | 2 +- lib/_ak_zblock | 16 ++++++++-------- lib/_ak_zchain | 4 ++-- 14 files changed, 37 insertions(+), 37 deletions(-) diff --git a/api/tests/announce_zblock.sh b/api/tests/announce_zblock.sh index ce3b1aa..15caec8 100755 --- a/api/tests/announce_zblock.sh +++ b/api/tests/announce_zblock.sh @@ -4,7 +4,7 @@ printf '[%s]\n' "$PROGRAM" printf "TEST\t/v0/announce/zblock\n" printf "\t01:\tendpoint with valid data" curl http://127.0.0.1:8610/v0/announce/zblock --header 'Content-Type: application/json' --data-raw '{"zblock":"'$(ak-get-zlatest)'"}' 2>/dev/null | jq -M -c > /dev/null -if [ "$?" == "0" ] +if [ $? -eq 0 ] then printf "\t\t\033[0;32mPASSED\033[0;0m" else @@ -14,7 +14,7 @@ printf "\n" printf "\t02:\tendpoint with invalid data" curl http://127.0.0.1:8610/v0/announce/zblock --header 'Content-Type: application/json' --data-raw '{"zblock":"'$(ak-get-zlatest)'sdfas"}' 2>/dev/null | jq -M -c > /dev/null -if [ "$?" == "0" ] +if [ $? -eq 0 ] then printf "\t\t\033[0;32mPASSED\033[0;0m" else @@ -24,7 +24,7 @@ printf "\n" printf "\t03:\tendpoint no data" curl http://127.0.0.1:8610/v0/announce/zblock --header 'Content-Type: application/json' --data-raw '{"zblock":""}' 2>/dev/null | jq -M -c > /dev/null -if [ "$?" == "0" ] +if [ $? -eq 0 ] then printf "\t\t\t\033[0;32mPASSED\033[0;0m" else diff --git a/api/tests/announce_zchain_link.sh b/api/tests/announce_zchain_link.sh index 9c9d381..c92a367 100755 --- a/api/tests/announce_zchain_link.sh +++ b/api/tests/announce_zchain_link.sh @@ -5,7 +5,7 @@ printf "TEST\t/v0/announce/zchain\n" # curl http://127.0.0.1:8610/v0/announce/zchain printf "\t01:\tendpoint with valid data" curl -POST http://localhost:8610/v0/announce/zchain --header 'Content-Type: application/json' --data-raw '{"zchain":"k51qzi5uqu5dgapvk7bhxmchuqya9immqdpbz0f1r91ckpdqzub63afn3d5apr"}' 2>/dev/null | jq -M -c > /dev/null -if [ "$?" == "0" ] +if [ $? -eq 0 ] then printf "\t\t\033[0;32mPASSED\033[0;0m" else @@ -15,7 +15,7 @@ printf "\n" printf "\t02:\tendpoint with invalid data" curl -POST http://localhost:8610/v0/announce/zchain --header 'Content-Type: application/json' --data-raw '{"zchain":"k51qzi5uqu5dgapvk7bhxmchuqya9immqdpbz0f1r91ckpdqzub63afn3d5aar"}' 2>/dev/null | jq -M -c > /dev/null -if [ "$?" == "0" ] +if [ $? -eq 0 ] then printf "\t\t\033[0;32mPASSED\033[0;0m" else @@ -25,7 +25,7 @@ printf "\n" printf "\t03:\tendpoint no data" curl -POST http://localhost:8610/v0/announce/zchain --header 'Content-Type: application/json' --data-raw '{"zchain":""}' 2>/dev/null | jq -M -c > /dev/null -if [ "$?" == "0" ] +if [ $? -eq 0 ] then printf "\t\t\t\033[0;32mPASSED\033[0;0m" else diff --git a/api/tests/default_route.sh b/api/tests/default_route.sh index 1505b68..950ce32 100755 --- a/api/tests/default_route.sh +++ b/api/tests/default_route.sh @@ -2,7 +2,7 @@ PROGRAM="$(basename $0)" printf '[%s]\n' "$PROGRAM" curl http://127.0.0.1:8610 2>/dev/null | jq > /dev/null -if [ "$?" == "0" ] +if [ $? -eq 0 ] then printf "\t\t\033[0;32mPASSED\033[0;0m" else diff --git a/api/tests/gathered_zblocks.sh b/api/tests/gathered_zblocks.sh index 35920e0..3e38ccc 100755 --- a/api/tests/gathered_zblocks.sh +++ b/api/tests/gathered_zblocks.sh @@ -6,7 +6,7 @@ printf '[%s]\n' "$PROGRAM" printf "TEST\t/see\n" printf "\t01:\tOutput is valid JSON format..." curl http://127.0.0.1:8610/v0/see 2>/dev/null | jq > /dev/null -if [ "$?" == "0" ] +if [ $? -eq 0 ] then printf "\t\t\033[0;32mPASSED\033[0;0m" else @@ -16,7 +16,7 @@ printf "\n" printf "\t02:\tFound blocks inside response..." curl http://127.0.0.1:8610/v0/see 2>/dev/null | grep block > /dev/null -if [ "$?" == "0" ] +if [ $? -eq 0 ] then printf "\t\t\033[0;32mPASSED\033[0;0m" else diff --git a/api/tests/gathered_zchain_zlatest_pairs.sh b/api/tests/gathered_zchain_zlatest_pairs.sh index d6c1274..361cc33 100755 --- a/api/tests/gathered_zchain_zlatest_pairs.sh +++ b/api/tests/gathered_zchain_zlatest_pairs.sh @@ -4,7 +4,7 @@ printf '[%s]\n' "$PROGRAM" printf "TEST\t/seens\n" printf "\t01:\tendpoint returns JSON..." curl http://127.0.0.1:8610/v0/seens 2>/dev/null | jq > /dev/null -if [ "$?" == "0" ] +if [ $? -eq 0 ] then printf '\t\t\033[0;32mPASSED\033[0;0m\n' else diff --git a/bin/ak-profile b/bin/ak-profile index c686f28..f4051eb 100755 --- a/bin/ak-profile +++ b/bin/ak-profile @@ -200,7 +200,7 @@ EOF fi _ak_zblock_pack "profile/add" $(pwd)/data - if [ "$?" -ne 0 ] + if [ $? -ne 0 ] then echo "error??" exit 1 diff --git a/bin/ak-sm-filejoiner b/bin/ak-sm-filejoiner index 9264a9a..f4165f9 100755 --- a/bin/ak-sm-filejoiner +++ b/bin/ak-sm-filejoiner @@ -21,7 +21,7 @@ TMPWD="/tmp/rjs" if [ ! -d "$TMPWD" ] then mkdir -p "$TMPWD" - if [ "$?" != 0 ] + if [ $? -ne 0 ] then echo "Can't create $TMPWD dir" exit 1 @@ -33,7 +33,7 @@ MAPSDIR="$AK_WORKDIR/fmp" CHKDIR="$AK_WORKDIR/ftr" cd $CHKDIR -if [ "$?" != 0 ] +if [ $? -ne 0 ] then echo "Can't get dir" exit 1 @@ -51,7 +51,7 @@ then bash script - if [ "$?" != 0 ] + if [ $? -ne 0 ] then echo "Error executing copy script" exit 1 @@ -73,7 +73,7 @@ then # We check if everything is okay sha512sum -c $MAPSDIR/$MAPSFILE - if [ "$?" != "0" ]; then + if [ $? -ne 0 ]; then _ak_log_error "Error while checking sums" exit 1 fi diff --git a/bin/ak-sm-filesplitter b/bin/ak-sm-filesplitter index 7365b19..4cbb4e4 100755 --- a/bin/ak-sm-filesplitter +++ b/bin/ak-sm-filesplitter @@ -49,7 +49,7 @@ source $AK_LIBDIR/_ak_log if [ ! -d "$TECHDIR" ] then mkdir -p "$TECHDIR" - if [ "$?" == 0 ] + if [ $? -eq 0 ] then _ak_log_info "Folder $TECHDIR created!" else @@ -65,7 +65,7 @@ fi if [ ! -d "$FILEMAPSDIR" ] then mkdir -p "$FILEMAPSDIR" - if [ "$?" == 0 ] + if [ $? -eq 0 ] then _ak_log_info "Folder $FILEMAPSDIR created!" else @@ -81,7 +81,7 @@ fi if [ ! -d "$CHKDIR" ] then mkdir -p "$CHKDIR" - if [ "$?" == 0 ] + if [ $? -eq 0 ] then _ak_log_info "Folder $CHKDIR created!" else diff --git a/init.sh b/init.sh index 43f2a40..36c2d4f 100755 --- a/init.sh +++ b/init.sh @@ -8,7 +8,7 @@ source lib/_ak_ipfs # existing one if any. ak_gpg_check_or_create(){ gpg2 --homedir $AK_GPGHOME --list-keys | grep kaos@kaos.kaos -B 1 - if [ "$?" -ne "0" ] + if [ $? -ne 0 ] then gpg2 --homedir $AK_GPGHOME --batch --passphrase '' --quick-gen-key kaos@kaos.kaos rsa3072 sign 0 AK_FINGERPRINT="$(gpg2 --homedir $AK_GPGHOME --list-keys | grep kaos@kaos.kaos -B 1 | head -n 1 | awk '{print $1}')" @@ -19,9 +19,9 @@ ak_gpg_check_or_create(){ ipfs_zarchive_check_or_mkdir(){ printf "Checking for /zarchive in IPFS FS..." _ak_ipfs files ls /zarchive > /dev/null 2>&1 - if [ $? != 0 ]; then + if [ $? -ne 0 ]; then _ak_ipfs files mkdir /zarchive > /dev/null 2>&1 - if [ $? != 0 ]; then + if [ $? -ne 0 ]; then printf "\tError!\n" exit 1 else @@ -35,9 +35,9 @@ ipfs_zarchive_check_or_mkdir(){ ipfs_zlatest_check_or_create(){ printf "Looking for /zlatest..." _ak_ipfs files stat /zlatest > /dev/null 2>&1 - if [ $? != 0 ]; then + if [ $? -ne 0 ]; then _ak_ipfs files cp /ipfs/$(cat $AK_ZGENESIS) /zlatest - if [ $? != 0 ]; then + if [ $? -ne 0 ]; then printf "\tProblem copying %s to /zlatest!\n" "$AK_ZGENESIS" exit 1 else @@ -56,7 +56,7 @@ if [ -f $AK_ZGENESIS ] ; then printf "%s" "$(_ak_ipfs add -q $AK_GENESIS)" > $AK if [ ! -f $AK_ZCHAIN ] then _ak_ipfs key list | grep zchain - if [ "$?" -ne 0 ] + if [ $? -ne 0 ] then printf "%s" "$(_ak_ipfs key gen zchain)" > $AK_ZCHAIN else diff --git a/lib/_ak_fs b/lib/_ak_fs index da09f93..ac466b4 100755 --- a/lib/_ak_fs +++ b/lib/_ak_fs @@ -282,7 +282,7 @@ _ak_fs_find_depth(){ exit 111 # Try to download stuff # wget -s $remoteMrk/$currentNode -O $fmrk/$currentNode - # if [ "$?" -ne 0 ] + # if [ $? -ne 0 ] # then # exit 111 # fi diff --git a/lib/_ak_ipfs b/lib/_ak_ipfs index f7c2dac..3437083 100755 --- a/lib/_ak_ipfs +++ b/lib/_ak_ipfs @@ -407,7 +407,7 @@ _ak_ipfs_cid_v0_check () { exit 1 fi echo $1 | grep -e 'Qm.\{44\}' > /dev/null - if [ "$?" -ne 0 ] + if [ $? -ne 0 ] then _ak_log_error "$1 is not an IPFS CIDv0 string" exit 1 diff --git a/lib/_ak_network b/lib/_ak_network index aa8105e5..1d77eef 100755 --- a/lib/_ak_network +++ b/lib/_ak_network @@ -100,7 +100,7 @@ _ak_network_scan_stellar(){ test="$(curl \ --connect-timeout 3 \ https://horizon.stellar.org/accounts/$p/data/config 2>/dev/null | grep value)" - if [ "$?" == 0 ] + if [ $? -eq 0 ] then addressValuePair="$(printf '%s %s\n' "$p" "$(echo $test | sed -e 's/^.*: "//g; s/"//g' | base64 -d)")" while IFS="" read -r x || [ -n "$x" ] diff --git a/lib/_ak_zblock b/lib/_ak_zblock index f853ef7..f379870 100755 --- a/lib/_ak_zblock +++ b/lib/_ak_zblock @@ -44,7 +44,7 @@ _ak_zblock_show(){ # We check if any $zblock at all _ak_ipfs_cat $zblock | jq -c -M > $AK_ZBLOCKDIR/$zblock - if [ "$?" -ne 0 ] + if [ $? -ne 0 ] then _ak_log_error "ZBLOCK $zblock READ failed" exit 1 @@ -90,14 +90,14 @@ _ak_zblock_show(){ echo -n '"block":"'$block'",' _ak_ipfs_cat $block | jq -c -M > $AK_BLOCKDIR/$block cat $AK_BLOCKDIR/$block | jq -M > /dev/null 2>&1 - if [ "$?" -ne 0 ] + if [ $? -ne 0 ] then _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 ] + if [ $? -ne 0 ] then _ak_log_error "BLOCK $block is NOT a valid block" exit 1 @@ -132,19 +132,19 @@ _ak_zblock_show(){ if [ $verify == 1 ] then _ak_ipfs_get $gpg > /dev/null 2>&1 - if [ "$?" -ne 0 ] + if [ $? -ne 0 ] then _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 ] + if [ $? -ne 0 ] then _ak_log_error "Could not import GPG key: $gpg ." exit 1 fi _ak_ipfs_get $block_signature > /dev/null 2>&1 - if [ "$?" -ne 0 ] + if [ $? -ne 0 ] then _ak_log_error "Error while getting $block_signature for $block" exit 1 @@ -153,7 +153,7 @@ _ak_zblock_show(){ _ak_log_info "Block signature downloaded" _ak_ipfs_get $block > /dev/null 2>&1 - if [ "$?" -ne 0 ] + if [ $? -ne 0 ] then _ak_log_error "Could not get $block block" exit 1 @@ -161,7 +161,7 @@ _ak_zblock_show(){ _ak_log_info "Downloaded block $block." _ak_gpg_verify_signature $block.asc $block > /dev/null 2>&1 - if [ "$?" -ne 0 ] + if [ $? -ne 0 ] then _ak_log_error "Could not verify $block with GPG key $gpg." exit 1 diff --git a/lib/_ak_zchain b/lib/_ak_zchain index d6925bf..d15048a 100755 --- a/lib/_ak_zchain +++ b/lib/_ak_zchain @@ -29,7 +29,7 @@ _ak_zchain_reset(){ if [ $? != 0 ]; then exit 1; fi ak-config --publish - if [ "$?" -ne 0 ] + if [ $? -ne 0 ] then _ak_log_error "Could not publish new configuration" exit 1 @@ -68,7 +68,7 @@ _ak_zchain_rebase(){ if [ $? != 0 ]; then exit 1; fi ak-config --publish - if [ "$?" -ne 0 ] + if [ $? -ne 0 ] then _ak_log_error "Could not publish new configuration" exit 1 -- cgit v1.2.3