From 58b888574923c46c3854090c5cd5d8106e39d46a Mon Sep 17 00:00:00 2001 From: kaotisk Date: Sun, 30 Jul 2023 20:08:57 +0300 Subject: Added checks to detect success and failure of underlying commands being run --- bin/ak-ipfs-add | 9 ++++++++- bin/ak-ipfs-block-stat | 7 ++++++- bin/ak-ipfs-cat | 2 ++ bin/ak-ipfs-files-cp | 7 ++++++- bin/ak-ipfs-files-ls | 7 ++++++- bin/ak-ipfs-files-mkdir | 7 ++++++- bin/ak-ipfs-files-mv | 7 ++++++- bin/ak-ipfs-files-rm | 7 ++++++- bin/ak-ipfs-files-stat | 7 ++++++- bin/ak-ipfs-get | 6 ++++++ bin/ak-ipfs-key-gen | 6 ++++++ bin/ak-ipfs-key-list | 6 ++++++ bin/ak-ipfs-key-list-full | 6 ++++++ bin/ak-ipfs-name-publish | 6 ++++++ bin/ak-ipfs-name-resolve | 6 ++++++ bin/ak-ipfs-starter | 6 ++++++ bin/ak-ipfs-swarm-peers | 6 ++++++ 17 files changed, 100 insertions(+), 8 deletions(-) diff --git a/bin/ak-ipfs-add b/bin/ak-ipfs-add index c3f75f1..63862b7 100755 --- a/bin/ak-ipfs-add +++ b/bin/ak-ipfs-add @@ -1,3 +1,10 @@ #!/bin/bash +PROGRAM="$(basename $0)" +# Receives a file +# Returns a hash ipfs add -Qr "$1" - +if [ "$?" != "0" ] +then + ak-logthis "<$PROGRAM>" "[ERROR]" "Failed to add $1" + exit 1 +fi diff --git a/bin/ak-ipfs-block-stat b/bin/ak-ipfs-block-stat index 6668275..144523d 100755 --- a/bin/ak-ipfs-block-stat +++ b/bin/ak-ipfs-block-stat @@ -1,3 +1,8 @@ #!/bin/bash +PROGRAM="$(basename $0)" ipfs block stat "$1" - +if [ "$?" != "0" ] +then + ak-logthis "<$PROGRAM>" "[ERROR]" "Failed to retrieve stat of block $1" + exit 1 +fi diff --git a/bin/ak-ipfs-cat b/bin/ak-ipfs-cat index b9bd7ec..d2415e4 100755 --- a/bin/ak-ipfs-cat +++ b/bin/ak-ipfs-cat @@ -1,7 +1,9 @@ #!/bin/bash +PROGRAM="$(basename $0)" ipfs --timeout=10s cat $1 if [ "$?" -ne "0" ] then + ak-logthis "<$PROGRAM>" "[ERROR]" "Failed to cat $1" exit 1 fi diff --git a/bin/ak-ipfs-files-cp b/bin/ak-ipfs-files-cp index 3e4dfbd..6ae766e 100755 --- a/bin/ak-ipfs-files-cp +++ b/bin/ak-ipfs-files-cp @@ -1,3 +1,8 @@ #!/bin/bash +PROGRAM="$(basename $0)" ipfs files cp "$1" "$2" - +if [ "$?" != "0" ] +then + ak-logthis "<$PROGRAM>" "[ERROR]" "Failed to copy $1 to $2" + exit 1 +fi diff --git a/bin/ak-ipfs-files-ls b/bin/ak-ipfs-files-ls index 1354f83..26a3313 100755 --- a/bin/ak-ipfs-files-ls +++ b/bin/ak-ipfs-files-ls @@ -1,3 +1,8 @@ #!/bin/bash +PROGRAM="$(basename $0)" ipfs files ls "$1" - +if [ "$?" != "0" ] +then + ak-logthis "<$PROGRAM>" "[ERROR]" "Failed to list $1" + exit 1 +fi diff --git a/bin/ak-ipfs-files-mkdir b/bin/ak-ipfs-files-mkdir index ab36f81..6406b33 100755 --- a/bin/ak-ipfs-files-mkdir +++ b/bin/ak-ipfs-files-mkdir @@ -1,3 +1,8 @@ #!/bin/bash +PROGRAM="$(basename $0)" ipfs files mkdir "$1" - +if [ "$?" != "0" ] +then + ak-logthis "<$PROGRAM>" "[ERROR]" "Failed to mkdir $1" + exit 1 +fi diff --git a/bin/ak-ipfs-files-mv b/bin/ak-ipfs-files-mv index 918674a..8b64dba 100755 --- a/bin/ak-ipfs-files-mv +++ b/bin/ak-ipfs-files-mv @@ -1,3 +1,8 @@ #!/bin/bash +PROGRAM="$(basename $0)" ipfs files mv "$1" "$2" - +if [ "$?" != "0" ] +then + ak-logthis "<$PROGRAM>" "[ERROR]" "Failed to move $1 to $2" + exit 1 +fi diff --git a/bin/ak-ipfs-files-rm b/bin/ak-ipfs-files-rm index 6ac570d..490103e 100755 --- a/bin/ak-ipfs-files-rm +++ b/bin/ak-ipfs-files-rm @@ -1,3 +1,8 @@ #!/bin/bash +PROGRAM="$(basename $0)" ipfs files rm "$1" - +if [ "$?" != "0" ] +then + ak-logthis "<$PROGRAM>" "[ERROR]" "Failed to remove $1" + exit 1 +fi diff --git a/bin/ak-ipfs-files-stat b/bin/ak-ipfs-files-stat index a378ed8..5e3e537 100755 --- a/bin/ak-ipfs-files-stat +++ b/bin/ak-ipfs-files-stat @@ -1,3 +1,8 @@ #!/bin/bash +PROGRAM="$(basename $0)" ipfs files stat "$1" - +if [ "$?" != "0" ] +then + ak-logthis "<$PROGRAM>" "[ERROR]" "Failed to get file's stats $1" + exit 1 +fi diff --git a/bin/ak-ipfs-get b/bin/ak-ipfs-get index ad959ed..ef8ba94 100755 --- a/bin/ak-ipfs-get +++ b/bin/ak-ipfs-get @@ -1,2 +1,8 @@ #!/bin/bash +PROGRAM="$(basename $0)" ipfs --timeout=10s get "$1" +if [ "$?" != "0" ] +then + ak-logthis "<$PROGRAM>" "[ERROR]" "Failed to get $1" + exit 1 +fi diff --git a/bin/ak-ipfs-key-gen b/bin/ak-ipfs-key-gen index 29a30f9..e30ce8d 100755 --- a/bin/ak-ipfs-key-gen +++ b/bin/ak-ipfs-key-gen @@ -1,2 +1,8 @@ #!/bin/bash +PROGRAM="$(basename $0)" ipfs key gen "$1" +if [ "$?" != "0" ] +then + ak-logthis "<$PROGRAM>" "[ERROR]" "Failed to generate key $1" + exit 1 +fi diff --git a/bin/ak-ipfs-key-list b/bin/ak-ipfs-key-list index 7ebdb15..1106b40 100755 --- a/bin/ak-ipfs-key-list +++ b/bin/ak-ipfs-key-list @@ -1,2 +1,8 @@ #!/bin/bash +PROGRAM="$(basename $0)" ipfs key list +if [ "$?" != "0" ] +then + ak-logthis "<$PROGRAM>" "[ERROR]" "Failed to get key list" + exit 1 +fi diff --git a/bin/ak-ipfs-key-list-full b/bin/ak-ipfs-key-list-full index f777225..1c19c00 100755 --- a/bin/ak-ipfs-key-list-full +++ b/bin/ak-ipfs-key-list-full @@ -1,2 +1,8 @@ #!/bin/bash +PROGRAM="$(basename $0)" ipfs key list -l +if [ "$?" != "0" ] +then + ak-logthis "<$PROGRAM>" "[ERROR]" "Failed to get key list" + exit 1 +fi diff --git a/bin/ak-ipfs-name-publish b/bin/ak-ipfs-name-publish index d1e10cf..d1a938c 100755 --- a/bin/ak-ipfs-name-publish +++ b/bin/ak-ipfs-name-publish @@ -1,3 +1,9 @@ #!/bin/bash +PROGRAM="$(basename $0)" ipfs name publish "$1" "$2" +if [ "$?" != "0" ] +then + ak-logthis "<$PROGRAM>" "[ERROR]" "Failed to get $1" + exit 1 +fi diff --git a/bin/ak-ipfs-name-resolve b/bin/ak-ipfs-name-resolve index 1f7ea93..6368e19 100755 --- a/bin/ak-ipfs-name-resolve +++ b/bin/ak-ipfs-name-resolve @@ -1,3 +1,9 @@ #!/bin/bash +PROGRAM="$(basename $0)" ipfs name resolve "$1" +if [ "$?" != "0" ] +then + ak-logthis "<$PROGRAM>" "[ERROR]" "Failed to resolve $1" + exit 1 +fi diff --git a/bin/ak-ipfs-starter b/bin/ak-ipfs-starter index 5cab1c3..35b9168 100755 --- a/bin/ak-ipfs-starter +++ b/bin/ak-ipfs-starter @@ -1,2 +1,8 @@ #!/bin/bash +PROGRAM="$(basename $0)" screen -dmS ipfs-daemon ipfs daemon +if [ "$?" != "0" ] +then + ak-logthis "<$PROGRAM>" "[ERROR]" "Failed to start IPFS daemon" + exit 1 +fi diff --git a/bin/ak-ipfs-swarm-peers b/bin/ak-ipfs-swarm-peers index d906ec3..b1890be 100755 --- a/bin/ak-ipfs-swarm-peers +++ b/bin/ak-ipfs-swarm-peers @@ -1,2 +1,8 @@ #!/bin/bash +PROGRAM="$(basename $0)" ipfs swarm peers +if [ "$?" != "0" ] +then + ak-logthis "<$PROGRAM>" "[ERROR]" "Failed to get list of peers" + exit 1 +fi -- cgit v1.2.3