65 lines
3.2 KiB
Bash
Executable File
65 lines
3.2 KiB
Bash
Executable File
#!/bin/bash
|
|
########################################################################
|
|
# Author: Fred (support@qo-op.com)
|
|
# Version: 2020.04.27
|
|
# 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##*/}"
|
|
|
|
########################################################################
|
|
# \\///
|
|
# qo-op
|
|
############# '$MY_PATH/$ME'
|
|
########################################################################
|
|
# ex: ./'$ME'
|
|
# GET SSB FRIENDS AND FIND THEIR IPFS ID TO "ipfs swarm connect" THEM
|
|
########################################################################'
|
|
|
|
########################################################################
|
|
# 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 ipfs addresses from SSB friends and add to bootstrap & swarm peers'
|
|
|
|
# GET /tmp/ssb-friends.txt
|
|
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.txt || rm -f /tmp/ssb-friends.txt
|
|
|
|
# GET /tmp/ssb-NOTfriends.txt
|
|
FEED_ID="$(sbotc whoami | jq .id -r)"
|
|
sbotc links "{\"source\": \"${FEED_ID}\", \"rel\": \"contact\", \"values\": true, \"reverse\": true}" | jq -c . | grep 'blocking":true' | jq -r .dest > /tmp/ssb-NOTfriends.txt
|
|
|
|
########################################################################
|
|
# 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"
|
|
TRYME=$(sbotc query.read '{"query":[{"$filter":{"value":{"author": "'"$SSBFRIEND"'", "content":{"type":"ipfstryme"}}}}]}' | jq -r .value?.content?.text | tail -n 1)
|
|
|
|
## REMOVE NOTfriends from IPFS swarm
|
|
[[ $TRYME ]] && [[ $(grep -Rwl "$SSBFRIEND" /tmp/ssb-NOTfriends.txt) ]] && echo "NOT $TRYME" && ipfs swarm disconnect $TRYME && ipfs bootstrap rm $TRYME && continue
|
|
|
|
## ADD Friend to our IPFS swarm
|
|
[[ $TRYME ]] && echo "Friend $TRYME" && ipfs swarm connect $TRYME && ipfs bootstrap add $TRYME
|
|
|
|
done
|
|
|