diff options
author | kaotisk <kaotisk@arching-kaos.org> | 2024-05-27 03:44:33 +0300 |
---|---|---|
committer | kaotisk <kaotisk@arching-kaos.org> | 2024-05-27 03:44:33 +0300 |
commit | 7a52180ec7a2f8b23f29b9a3094c5d015314acc0 (patch) | |
tree | 759b6abb9da26d319ac5e67ac3ab24aa1831cd5d /lib | |
parent | 00573eff1569a984000dfafe8f9ccf9bcad971dd (diff) | |
download | arching-kaos-tools-7a52180ec7a2f8b23f29b9a3094c5d015314acc0.tar.gz arching-kaos-tools-7a52180ec7a2f8b23f29b9a3094c5d015314acc0.tar.bz2 arching-kaos-tools-7a52180ec7a2f8b23f29b9a3094c5d015314acc0.zip |
More checks to avoid spawning unendless procedures
Diffstat (limited to 'lib')
-rwxr-xr-x | lib/_ak_ipfs | 101 |
1 files changed, 89 insertions, 12 deletions
diff --git a/lib/_ak_ipfs b/lib/_ak_ipfs index 1c1e430..3286399 100755 --- a/lib/_ak_ipfs +++ b/lib/_ak_ipfs @@ -44,8 +44,8 @@ _ak_ipfs_scanner(){ url="http://$ip:8610/v0/node_info" fi node_info="`curl \ - -A 'akd/0.1.0; https://github.com/arching-kaos' \ --connect-timeout 3 \ + -A 'akd/0.1.0; https://github.com/arching-kaos' \ "$url" 2>/dev/null`" if [ $? -eq 0 ] then @@ -64,6 +64,11 @@ _ak_ipfs_scanner(){ } _ak_ipfs_add(){ + if [ -z $1 ] || [ ! -n "$1" ] + then + logit "error" "no argument given" + exit 1 + fi # Receives a file # Returns a hash _ak_ipfs add -Qr "$1" @@ -75,6 +80,11 @@ _ak_ipfs_add(){ } _ak_ipfs_block_stat(){ + if [ -z $1 ] || [ ! -n "$1" ] + then + logit "error" "no argument given" + exit 1 + fi _ak_ipfs block stat "$1" if [ $? -ne 0 ] then @@ -84,6 +94,11 @@ _ak_ipfs_block_stat(){ } _ak_ipfs_cat(){ + if [ -z $1 ] || [ ! -n "$1" ] + then + logit "error" "no argument given" + exit 1 + fi _ak_ipfs --timeout=10s cat $1 if [ "$?" -ne "0" ] then @@ -94,6 +109,16 @@ _ak_ipfs_cat(){ } _ak_ipfs_files_cp(){ + if [ -z $1 ] || [ ! -n "$1" ] + then + logit "ERROR" "No argument given" + exit 1 + fi + if [ -z $2 ] || [ ! -n "$2" ] + then + logit "ERROR" "No argument given" + exit 1 + fi _ak_ipfs files cp "$1" "$2" if [ $? -ne 0 ] then @@ -112,6 +137,11 @@ _ak_ipfs_files_ls(){ } _ak_ipfs_files_mkdir(){ + if [ -z $1 ] || [ ! -n "$1" ] + then + logit "ERROR" "No argument given" + exit 1 + fi _ak_ipfs files mkdir "$1" if [ $? -ne 0 ] then @@ -121,6 +151,16 @@ _ak_ipfs_files_mkdir(){ } _ak_ipfs_files_mv(){ + if [ -z $1 ] || [ ! -n "$1" ] + then + logit "ERROR" "No argument given" + exit 1 + fi + if [ -z $2 ] || [ ! -n "$2" ] + then + logit "ERROR" "No argument given" + exit 1 + fi _ak_ipfs files mv "$1" "$2" if [ $? -ne 0 ] then @@ -130,6 +170,11 @@ _ak_ipfs_files_mv(){ } _ak_ipfs_files_rm(){ + if [ -z $1 ] || [ ! -n "$1" ] + then + logit "ERROR" "No argument given" + exit 1 + fi _ak_ipfs files rm "$1" if [ $? -ne 0 ] then @@ -139,6 +184,11 @@ _ak_ipfs_files_rm(){ } _ak_ipfs_files_stat(){ + if [ -z $1 ] || [ ! -n "$1" ] + then + logit "ERROR" "No argument given" + exit 1 + fi _ak_ipfs files stat "$1" if [ $? -ne 0 ] then @@ -148,6 +198,11 @@ _ak_ipfs_files_stat(){ } _ak_ipfs_get(){ + if [ -z $1 ] || [ ! -n "$1" ] + then + logit "ERROR" "No argument given" + exit 1 + fi _ak_ipfs --timeout=10s get "$1" > /dev/null 2>&1 if [ $? -ne 0 ] then @@ -157,6 +212,11 @@ _ak_ipfs_get(){ } _ak_ipfs_key_gen(){ + if [ -z $1 ] || [ ! -n "$1" ] + then + logit "ERROR" "No argument given" + exit 1 + fi _ak_ipfs key gen "$1" if [ $? -ne 0 ] then @@ -184,6 +244,16 @@ _ak_ipfs_key_list_full(){ } _ak_ipfs_name_publish(){ + if [ -z $1 ] || [ ! -n "$1" ] + then + logit "ERROR" "No argument given" + exit 1 + fi + if [ -z $2 ] || [ ! -n "$2" ] + then + logit "ERROR" "No argument given" + exit 1 + fi _ak_ipfs name publish "$1" "$2" if [ $? -ne 0 ] then @@ -194,6 +264,11 @@ _ak_ipfs_name_publish(){ } _ak_ipfs_name_resolve(){ + if [ -z $1 ] || [ ! -n "$1" ] + then + logit "ERROR" "No argument given" + exit 1 + fi _ak_ipfs name resolve "$1" if [ $? -ne 0 ] then @@ -292,7 +367,9 @@ _ak_ipfs_init(){ _ak_ipfs_download(){ logit "INFO" "Attempting to install IPFS..." - IPFS_VERSION="$(curl -s https://dist.ipfs.tech/kubo/versions | tail -1)" + IPFS_VERSION="$(curl \ + --connect-timeout 3 \ + -s https://dist.ipfs.tech/kubo/versions | tail -1)" IPFS_TARGET_FILE="kubo_"$IPFS_VERSION"_linux-amd64.tar.gz" logit "INFO" "Downloading ipfs $IPFS_VERSION" @@ -306,19 +383,19 @@ _ak_ipfs_download(){ } _ak_ipfs_cid_v0_check () { - if [ -z $1 ] || [ "$1" != "" ] + if [ -z $1 ] || [ ! -n "$1" ] then - echo $1 | grep -e 'Qm.\{44\}' > /dev/null - if [ "$?" -ne 0 ] - then - logit "ERROR" "$1 is not an IPFS CIDv0 string" - exit 1 - fi - logit "INFO" "$1 provided is an IPFS CIDv0 string" - else - logit "ERROR" "No argument was provided" + logit "ERROR" "No argument given" + exit 1 + fi + echo $1 | grep -e 'Qm.\{44\}' > /dev/null + if [ "$?" -ne 0 ] + then + logit "ERROR" "$1 is not an IPFS CIDv0 string" exit 1 fi + logit "INFO" "$1 provided is an IPFS CIDv0 string" + fi } _ak_ipfs_swarm_install() { |