aboutsummaryrefslogtreecommitdiff
path: root/lib/_ak_ipfs
diff options
context:
space:
mode:
authorkaotisk <kaotisk@arching-kaos.org>2024-07-05 00:32:55 +0300
committerkaotisk <kaotisk@arching-kaos.org>2024-07-05 00:32:55 +0300
commit681358adcfc8d1471ca53c3af246bf80a885ef98 (patch)
tree1b339d01f5ed5bee99c5c1be4403a6d23b7c05c4 /lib/_ak_ipfs
parentc0dbfc8dc7cf7af278de1d233d87ffbe481ba704 (diff)
downloadarching-kaos-tools-681358adcfc8d1471ca53c3af246bf80a885ef98.tar.gz
arching-kaos-tools-681358adcfc8d1471ca53c3af246bf80a885ef98.tar.bz2
arching-kaos-tools-681358adcfc8d1471ca53c3af246bf80a885ef98.zip
Refactoring
- Edited log messages and types - IPFS `cat` is now calling `get` which in turn searches for already gotten file, otherwise fetches it. - ak-data-expand is now a function of _ak_zblock lib (_ak_data_expand) - Removed ak-sm-hash-to-path as it lives in _ak_fs lib now - Removed _ak_title_description and _ak_help from ak in favor of _ak_usage - Tweaks around native FS over IPFS strategy Note that we are preparing the ground for migration to AKFS as well
Diffstat (limited to 'lib/_ak_ipfs')
-rwxr-xr-xlib/_ak_ipfs64
1 files changed, 43 insertions, 21 deletions
diff --git a/lib/_ak_ipfs b/lib/_ak_ipfs
index 5c47f91..2a8fc77 100755
--- a/lib/_ak_ipfs
+++ b/lib/_ak_ipfs
@@ -1,6 +1,11 @@
#!/bin/bash
source $AK_LIBDIR/_ak_log
AK_IPFS_REPO="$AK_WORKDIR/ipfsrepo"
+AK_IPFS_ARTIFACTS="$AK_WORKDIR/ipfs_artifacts"
+if [ ! -d $AK_IPFS_ARTIFACTS ]
+then
+ mkdir -p $AK_IPFS_ARTIFACTS
+fi
_ak_ipfs(){
export IPFS_PATH=$AK_IPFS_REPO; ipfs $*
@@ -105,20 +110,6 @@ _ak_ipfs_block_stat(){
fi
}
-_ak_ipfs_cat(){
- if [ -z $1 ] || [ ! -n "$1" ]
- then
- _ak_log_error "no argument given"
- exit 1
- fi
- _ak_ipfs --timeout=10s cat $1
- if [ $? -ne 0 ]
- then
- _ak_log_error "Failed to cat $1"
- exit 1
- fi
-}
-
_ak_ipfs_files_cp(){
if [ -z $1 ] || [ ! -n "$1" ]
then
@@ -214,14 +205,40 @@ _ak_ipfs_get(){
_ak_log_error "No argument given"
exit 1
fi
- _ak_ipfs --timeout=10s get "$1" > /dev/null 2>&1
+ if [ ! -f $AK_IPFS_ARTIFACTS/$1 ]
+ then
+ wam="$(pwd)"
+ cd $AK_IPFS_ARTIFACTS
+ _ak_ipfs --timeout=10s get "$1" > /dev/null 2>&1
+ if [ $? -ne 0 ]
+ then
+ _ak_log_error "Failed to get $1"
+ exit 1
+ fi
+ cd $wam
+ ln -s $AK_IPFS_ARTIFACTS/$1 $1
+ fi
+}
+
+_ak_ipfs_cat(){
+ if [ -z $1 ] || [ ! -n "$1" ]
+ then
+ _ak_log_error "no argument given"
+ exit 1
+ fi
+ if [ ! -f $AK_IPFS_ARTIFACTS/$1 ]
+ then
+ _ak_ipfs_get $1
+ fi
+ cat $AK_IPFS_ARTIFACTS/$1
if [ $? -ne 0 ]
then
- _ak_log_error "Failed to get $1"
+ _ak_log_error "Failed to cat $1"
exit 1
fi
}
+
_ak_ipfs_key_gen(){
if [ -z $1 ] || [ ! -n "$1" ]
then
@@ -426,22 +443,27 @@ _ak_ipfs_download(){
fi
}
-_ak_ipfs_cid_v0_check () {
+_ak_ipfs_cid_v0_check(){
if [ -z $1 ] || [ ! -n "$1" ]
then
- _ak_log_error "No argument given"
+ _ak_log_error "_ak_ipfs_cid_v0_check: No argument given"
+ exit 1
+ fi
+ if [ $(echo -n $1 | wc -c) -ne 46 ]
+ then
+ _ak_log_error "_ak_ipfs_cid_v0_check: $1 IPFS CIDv0 length mismatch"
exit 1
fi
echo $1 | grep -e 'Qm.\{44\}' > /dev/null
if [ $? -ne 0 ]
then
- _ak_log_error "$1 is not an IPFS CIDv0 string"
+ _ak_log_error "_ak_ipfs_cid_v0_check: $1 is not an IPFS CIDv0 string"
exit 1
fi
- _ak_log_info "$1 provided is an IPFS CIDv0 string"
+ _ak_log_debug "_ak_ipfs_cid_v0_check: $1 provided is an IPFS CIDv0 string"
}
-_ak_ipfs_swarm_install() {
+_ak_ipfs_swarm_install(){
SWARMSHA512SUM="7001e37412758c43d372a969e977ca11511e034c8c1e233a58dc3ce1c6f3c1aa7d2da8cba9944a5eabaa8885742bfe6cc6794224c146b7129da8f633b53b9cfc"
if [ ! -f $AK_IPFS_REPO/swarm.key ]
then