astroport/zen/ssb_IPFS_swarm.sh

82 lines
3.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##*/}"
2020-04-28 02:38:20 +02:00
2020-04-27 23:26:51 +02:00
########################################################################
# \\///
# qo-op
############# '$MY_PATH/$ME'
########################################################################
# ex: ./'$ME'
2020-04-28 02:38:20 +02:00
# GET SSB FRIENDS AND FIND THEIR IPFS ID TO "ipfs swarm connect" THEM
2020-04-27 23:26:51 +02:00
########################################################################'
2020-05-11 00:29:11 +02:00
## TODO: REMOVE DUPLICATES
## TODO: MODE : COOL, STRAIGHT, ARMORED
2020-05-11 00:57:26 +02:00
########################################################################
## CONNECT GLOBAL "ipfs.io" ## DANGEROUS only for short time...
########################################################################
# ADD ipfs.io public bootstrap into your swarm peers
# RUN: cat ~/.zen/astroport/ipfs.swarm.ipfs.io | ipfs swarm connect
# SOON ipfs swarm peers will GROW!!! YOU ARE VSIBLE !!!
# RUN: sudo systemctl restart ipfs # GOES BACK TO SWARM0
########################################################################
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 '
2020-05-05 01:22:30 +02:00
__ __ ____
__/ // /_______ ______ __________ ___ / __ \
/_ _ __/ ___/ | /| / / __ `/ ___/ __ `__ \/ / / /
/_ _ __(__ )| |/ |/ / /_/ / / / / / / / / /_/ /
/_//_/ /____/ |__/|__/\__,_/_/ /_/ /_/ /_/\____/
EXTEND IPFS SWARM and SHAPE IT FROM (ssb_INIT.sh) FRIENDS
Search "ipfstryme" message type in SSB feed
'
2020-04-27 23:26:51 +02:00
self=$(sbotc whoami | jq -r .id)
2020-05-05 01:22:30 +02:00
# GET /tmp/ssb-friends.txt
2020-05-22 23:55:27 +02:00
sbotc query.read '{"query":[{"$filter":{"value":{"author": "'"$self"'", "content":{"type":"contact"}}}}]}' | jq -r '.value?.content?.contact' > /tmp/ssb-friends.txt
2020-04-27 23:26:51 +02:00
2020-04-29 19:55:45 +02:00
# GET /tmp/ssb-NOTfriends.txt
2020-05-05 01:22:30 +02:00
sbotc links "{\"source\": \"${self}\", \"rel\": \"contact\", \"values\": true, \"reverse\": true}" | jq -c . | grep 'blocking":true' | jq -r .dest > /tmp/ssb-NOTfriends.txt
# Force Strict #swarm0 !!
# ipfs bootstrap rm --all
2020-04-28 02:38:20 +02:00
2020-04-29 19:55:45 +02:00
########################################################################
# Let's look if our SSB Friends ARE "IPFS swarm connected"
########################################################################
for SSBFRIEND in $(cat /tmp/ssb-friends.txt); do
### GET SSB "ipfstryme" message type !!! Astroport Node should have publish it during "ssb_INIT.sh"
2020-04-28 02:44:20 +02:00
TRYME=$(sbotc query.read '{"query":[{"$filter":{"value":{"author": "'"$SSBFRIEND"'", "content":{"type":"ipfstryme"}}}}]}' | jq -r .value?.content?.text | tail -n 1)
2020-04-29 19:55:45 +02:00
## REMOVE NOTfriends from IPFS swarm
2020-04-29 20:37:53 +02:00
[[ $TRYME ]] && [[ $(grep -Rwl "$SSBFRIEND" /tmp/ssb-NOTfriends.txt) ]] && echo "NOT $TRYME" && ipfs swarm disconnect $TRYME && ipfs bootstrap rm $TRYME && continue
2020-04-29 19:55:45 +02:00
## ADD Friend to our IPFS swarm
2020-04-29 20:37:53 +02:00
[[ $TRYME ]] && echo "Friend $TRYME" && ipfs swarm connect $TRYME && ipfs bootstrap add $TRYME
2020-04-29 19:55:45 +02:00
2020-04-27 23:26:51 +02:00
done
2020-04-28 02:12:48 +02:00
2020-05-04 16:30:43 +02:00
ipfs swarm peers