astroport/zen/ipfs_SWARM_refresh.sh

63 lines
2.5 KiB
Bash
Raw Normal View History

2020-04-13 19:12:20 +02:00
#!/bin/bash
########################################################################
# Author: Fred (support@qo-op.com)
# Version: 2020.03.24
# License: AGPL-3.0 (https://choosealicense.com/licenses/agpl-3.0/)
########################################################################
MY_PATH="`dirname \"$0\"`" # relative
MY_PATH="`( cd \"$MY_PATH\" && pwd )`" # absolutized and normalized
ME="${0##*/}"
2020-04-28 00:39:00 +02:00
2020-04-13 19:12:20 +02:00
########################################################################
# \\///
# qo-op
############# '$MY_PATH/$ME'
########################################################################
# ex: ./'$ME'
# SYNC IPFS SWARM PEERS SHARED DATA .Qm****
########################################################################'
########################################################################
# ENVIRONEMENT DETECTION + IPFS ~/.zen/ipfs/.$ipfsnodeid/G1SSB/_info
########################################################################
ipfsnodeid=$(ipfs id -f='<id>\n')
[[ $ipfsnodeid == "" ]] && echo "ERROR missing IPFS Node id !! IPFS is not installed !?" && exit 1
########################################################################
[[ ! -f ~/.ssb/secret.dunikey ]] && $MY_PATH/tools/secret2dunikey.sh
g1pub=$(cat ~/.ssb/secret.dunikey | grep 'pub:' | cut -d ' ' -f 2)
########################################################################
mkdir -p "~/.zen/ipfs_swarm"
echo '
___ _ _ __ __ _ _ _ _ _ _ __
| |_)|_(_ (_\ //\ |_)|\/| |_)|_|_|_)|_(_ |_|
_|_| | __) __)\/\//--\| \| | | \|_| | \|___)| |
'
2020-04-28 00:23:54 +02:00
echo "I am $ipfsnodeid"
2020-05-04 03:19:27 +02:00
cd ~/
2020-04-28 00:12:24 +02:00
# PUBLISH NODE ipfs shared data to swarm
2020-05-04 16:30:43 +02:00
[[ ! -d ~/.zen/ipfs ]] && echo "ERROR : ~/.zen/ipfs/ NOT FOUND" && exit 1
2020-04-28 00:12:24 +02:00
IWALLETS=$(ipfs add -rHq ~/.zen/ipfs | tail -n 1)
NODEIPNS=$(ipfs name publish --quieter /ipfs/$IWALLETS)
2020-04-28 00:09:16 +02:00
## TAKE CARE OF ~/.zen/g1sms_wallets
2020-04-13 19:12:20 +02:00
# GET IPNS published wallets from ALL SWARM NODES ## TODO: IF NODES are MISSING, check ./wallets_swarm/.QmNODES...
[[ $$ipfsnodeid ]] && ipfs get --output=./.zen/ipfs_swarm/ /ipns/$ipfsnodeid
2020-04-13 19:12:20 +02:00
count=1
# Search for All peers Nodes. ## TODO: To be changed when Swarm is too big or not expendanding
2020-04-19 13:14:47 +02:00
#for id in ./ipfs_swarm/.Qm*/; # Alternative search
2020-05-04 03:19:27 +02:00
2020-04-13 19:12:20 +02:00
for id in $(ipfs swarm peers | awk -F '/' '{print $7}');
do
count=$((count+1))
id=$(echo $id | cut -d '.' -f 3 | cut -d '/' -f 1)
echo "Refreshing ~/.zen/ipfs_swarm/.$id"
2020-05-04 03:19:27 +02:00
rm -Rf ./.zen/ipfs_swarm/.$id
$MY_PATH/tools/timeout.sh -t 30 ipfs get --output=./.zen/ipfs_swarm/ /ipns/$id
2020-04-13 19:12:20 +02:00
done