diff options
Diffstat (limited to 'lib/_ak_ipfs')
-rwxr-xr-x | lib/_ak_ipfs | 176 |
1 files changed, 123 insertions, 53 deletions
diff --git a/lib/_ak_ipfs b/lib/_ak_ipfs index 94f5913..07595ae 100755 --- a/lib/_ak_ipfs +++ b/lib/_ak_ipfs @@ -1,5 +1,25 @@ -#!/bin/bash -source $AK_LIBDIR/_ak_log +#!/usr/bin/env bash +### +### arching-kaos-tools +### Tools to interact and build an Arching Kaos Infochain +### Copyright (C) 2021 - 2025 kaotisk +### +### This program is free software: you can redistribute it and/or modify +### it under the terms of the GNU General Public License as published by +### the Free Software Foundation, either version 3 of the License, or +### (at your option) any later version. +### +### This program is distributed in the hope that it will be useful, +### but WITHOUT ANY WARRANTY; without even the implied warranty of +### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +### GNU General Public License for more details. +### +### You should have received a copy of the GNU General Public License +### along with this program. If not, see <http://www.gnu.org/licenses/>. +### +source $AK_LIBDIR/_ak_lib_load +_ak_lib_load _ak_log + AK_IPFS_REPO="$AK_WORKDIR/ipfsrepo" AK_IPFS_ARTIFACTS="$AK_WORKDIR/ipfs_artifacts" if [ ! -d $AK_IPFS_ARTIFACTS ] @@ -7,21 +27,30 @@ then mkdir -p $AK_IPFS_ARTIFACTS fi -_ak_ipfs(){ - export IPFS_PATH=$AK_IPFS_REPO; ipfs $* +function _ak_ipfs(){ + export IPFS_PATH=$AK_IPFS_REPO; kubo $* + if [ $? -ne 0 ] + then + _ak_log_error "Some error occured when running: kubo $*" + #exit 1 + fi +} + +function _ak_ipfs_runner(){ + export IPFS_PATH=$AK_IPFS_REPO; kubo $* if [ $? -ne 0 ] then - _ak_log_error "Some error occured when running: ipfs $*" + _ak_log_error "Some error occured when running: kubo $*" #exit 1 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" @@ -30,7 +59,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 @@ -38,7 +67,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 ] @@ -86,10 +115,10 @@ _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" + _ak_log_error "_ak_ipfs_add: no argument given" exit 1 fi # Receives a file @@ -102,10 +131,10 @@ _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" + _ak_log_error "_ak_ipfs_block_stat: no argument given" exit 1 fi _ak_ipfs block stat "$1" @@ -116,15 +145,15 @@ _ak_ipfs_block_stat(){ fi } -_ak_ipfs_files_cp(){ +function _ak_ipfs_files_cp(){ if [ -z $1 ] || [ ! -n "$1" ] then - _ak_log_error "No argument given" + _ak_log_error "Source: No argument given" exit 1 fi if [ -z $2 ] || [ ! -n "$2" ] then - _ak_log_error "No argument given" + _ak_log_error "Destination: No argument given" exit 1 fi _ak_ipfs files cp "$1" "$2" @@ -135,7 +164,7 @@ _ak_ipfs_files_cp(){ fi } -_ak_ipfs_files_ls(){ +function _ak_ipfs_files_ls(){ _ak_ipfs files ls "$1" if [ $? -ne 0 ] then @@ -144,7 +173,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" @@ -158,7 +187,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" @@ -177,7 +206,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" @@ -191,7 +220,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" @@ -205,7 +234,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" @@ -226,10 +255,10 @@ _ak_ipfs_get(){ fi } -_ak_ipfs_cat(){ +function _ak_ipfs_cat(){ if [ -z $1 ] || [ ! -n "$1" ] then - _ak_log_error "no argument given" + _ak_log_error "_ak_ipfs_cat: no argument given" exit 1 fi if [ ! -f $AK_IPFS_ARTIFACTS/$1 ] @@ -244,8 +273,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" @@ -259,7 +287,7 @@ _ak_ipfs_key_gen(){ fi } -_ak_ipfs_key_list(){ +function _ak_ipfs_key_list(){ _ak_ipfs key list if [ $? -ne 0 ] then @@ -268,7 +296,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 @@ -277,7 +305,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" @@ -296,7 +324,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" @@ -306,7 +334,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" @@ -320,7 +348,7 @@ _ak_ipfs_name_resolve(){ fi } -_ak_ipfs_swarm_peers(){ +function _ak_ipfs_swarm_peers(){ _ak_ipfs swarm peers if [ $? -ne 0 ] then @@ -329,7 +357,7 @@ _ak_ipfs_swarm_peers(){ fi } -_ak_ipfs_starter(){ +function _ak_ipfs_starter(){ _ak_ipfs_daemon if [ $? -ne 0 ] then @@ -345,7 +373,7 @@ _ak_ipfs_starter(){ fi } -_ak_ipns_resolve(){ +function _ak_ipns_resolve(){ if [ ! -z $1 ] then rsld=$(_ak_ipfs_name_resolve $1) @@ -362,7 +390,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 @@ -379,7 +407,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 @@ -396,7 +424,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 @@ -406,7 +434,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 @@ -416,14 +444,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 @@ -431,36 +459,76 @@ _ak_ipfs_init(){ fi } -_ak_ipfs_download(){ - _ak_log_info "Attempting to install IPFS..." +function _ak_ipfs_download(){ + _ak_log_info "Figuring latest compatible version of kubo (IPFS)..." IPFS_VERSION="$(curl \ --connect-timeout 3 \ -s https://dist.ipfs.tech/kubo/versions | tail -1)" - if [ "$(uname --machine)" == "x86_64" ] + if [ "$(uname -m)" == "amd64" ] then ARCH="amd64" - elif [ "$(uname --machine)" == "armv7l" ] + elif [ "$(uname -m)" == "x86_64" ] + then + ARCH="amd64" + elif [ "$(uname -m)" == "armv7l" ] then ARCH="arm" - elif [ "$(uname --machine)" == "aarch64" ] + elif [ "$(uname -m)" == "aarch64" ] then ARCH="arm64" else - echo "ERROR UNKNOWN ARCHITECTURE $(uname --machine)" + echo "ERROR UNKNOWN ARCHITECTURE $(uname -m)" exit 1 fi - IPFS_TARGET_FILE="kubo_"$IPFS_VERSION"_linux-$ARCH.tar.gz" - _ak_log_info "Downloading ipfs $IPFS_VERSION" + IPFS_TARGET_FILE="kubo_${IPFS_VERSION}_$(uname|tr "[:upper:]" "[:lower:]")-${ARCH}.tar.gz" + _ak_log_info "Downloading kubo $IPFS_VERSION" if [ ! -f $AK_ARCHIVESDIR/$IPFS_TARGET_FILE ] then - wget -O $AK_ARCHIVESDIR/$IPFS_TARGET_FILE https://dist.ipfs.tech/kubo/$IPFS_VERSION/$IPFS_TARGET_FILE ; + curl -s -o $AK_ARCHIVESDIR/$IPFS_TARGET_FILE https://dist.ipfs.tech/kubo/$IPFS_VERSION/$IPFS_TARGET_FILE else _ak_log_info "Already have the latest version" exit 0 fi } -_ak_ipfs_cid_v0_check(){ +function _ak_ipfs_install(){ + _ak_log_info "Making temp files" + pwd > pwd + mktemp -d > tempassin + ak_curdir=$(cat pwd) + TEMPASSIN=$(cat tempassin) + cd $TEMPASSIN + tar xf $AK_ARCHIVESDIR/$IPFS_TARGET_FILE + cp kubo/ipfs $AK_BINDIR/kubo + cd $ak_curdir + rm -rf $TEMPASSIN + _ak_log_info "ipfs installed on $AK_BINDIR" +} + +function _ak_ipfs_check_and_install(){ + which kubo > /dev/null 2>&1 + if [ $? -ne 0 ] + then + _ak_ipfs_download + _ak_ipfs_install + _ak_ipfs init + _ak_ipfs_swarm_install + else + _ak_log_info "Found IPFS! Skipping downloading..." + _ak_ipfs_swarm_install + fi + if [ ! -d $AK_IPFS_REPO ] + then + _ak_ipfs init + _ak_ipfs_swarm_install + fi + if [ ! -f $AK_ZGENESIS ] + then + _ak_ipfs add -Q $AK_GENESIS > $AK_ZGENESIS + fi +} + +function _ak_ipfs_cid_v0_check(){ if [ -z $1 ] || [ ! -n "$1" ] then _ak_log_error "_ak_ipfs_cid_v0_check: No argument given" @@ -480,12 +548,12 @@ _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 _ak_log_info "Downloading swarm key" - wget -O $AK_IPFS_REPO/swarm.key https://arching-kaos.net/files/swarm.key + curl -s -o $AK_IPFS_REPO/swarm.key https://arching-kaos.net/files/swarm.key elif [ -f $AK_IPFS_REPO/swarm.key ] && [ "$(sha512sum $AK_IPFS_REPO/swarm.key | awk '{ print $1 }')" == "$SWARMSHA512SUM" ] then _ak_log_info "Congrats! You are already in our swarm" @@ -495,6 +563,8 @@ _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 } + +_ak_log_debug "_ak_ipfs loaded $(caller)" |