astroport/zen/ssb_IPFS_swarm.sh

59 lines
2.7 KiB
Bash
Raw Normal View History

2020-04-27 23:26:51 +02:00
#!/bin/bash
########################################################################
# Author: Fred (support@qo-op.com)
2020-04-27 23:32:49 +02:00
# Version: 2020.04.27
2020-04-27 23:26:51 +02:00
# 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##*/}"
echo '
########################################################################
# \\///
# qo-op
############# '$MY_PATH/$ME'
########################################################################
# ex: ./'$ME'
2020-04-28 01:55:48 +02:00
# GET SSB FRIENDS AND FIND THEIR IPFS ID .Qm****
2020-04-27 23:26:51 +02:00
########################################################################'
########################################################################
# 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)
########################################################################
echo '
#####
#### #### ##### # # # ##### ###### ####
# # # # # # # # # #
#### #### ##### ##### # # # ##### ####
# # # # # # ##### # #
# # # # # # # # # # # #
#### #### ##### ####### # # # ####
'
# GET /tmp/ssb-friends.json to choose SWARM peers
self=$(sbotc whoami | jq -r .id)
sbotc query.read '{"query":[{"$filter":{"value":{"author": "'"$self"'", "content":{"type":"contact"}}}}]}' | jq -r '.value?.content?.contact' > /tmp/ssb-friends.json || rm -f /tmp/ssb-friends.json
2020-04-28 02:12:48 +02:00
# ONLY SSB FRIENDS ARE swarm connected
2020-04-27 23:26:51 +02:00
for SSBFRIEND in $(cat /tmp/ssb-friends.json); do
2020-04-28 00:40:55 +02:00
INSWARM=$(grep -Rwl "$SSBFRIEND" ~/.zen/ipfs_swarm/.Qm*/G1SSB/_ssb.whoami | tail -n 1 | cut -f 6 -d '/')
2020-04-28 02:12:48 +02:00
[[ $INSWARM ]] && echo $INSWARM && TRYME=$(cat ~/.zen/ipfs_swarm/$INSWARM/tryme.addr) && ipfs swarm connect $TRYME
# Modify ipfs swarm peers from ssb friends graph
2020-04-27 23:26:51 +02:00
done
2020-04-28 02:12:48 +02:00
# All memorized IPFS Nodes are swarm connected (again?)
2020-04-28 02:14:54 +02:00
for IPFSNODEADDR in $(cat ~/.zen/ipfs_swarm/.Qm*/tryme.addr); do
ipfs swarm connect $IPFSNODEADDR
2020-04-28 02:12:48 +02:00
# Renew ipfs_swarm knows ...
done
# WHICH IS THE BEST ? TODO choose