You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

107 lines
5.7 KiB

#!/bin/bash
########################################################################
# Author: Fred (support@qo-op.com)
# Version: 2020.12.03
# 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##*/}"
YOU=$(ps auxf --sort=+utime | grep -w ipfs | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d " " -f 1) && [[ ! $YOU ]] && echo "ipfs NOT RUNNING. EXIT" && exit 1
G1PUB=$(cat ~/.zen/secret.dunikey | grep 'pub:' | cut -d ' ' -f 2) && [[ ! $G1PUB ]] && echo "ERREUR G1PUB. EXIT" && exit 1
IPFSNODEID=$(ipfs id -f='<id>\n') && [[ "$IPFSNODEID" == "" ]] && echo 'ERROR missing IPFS Node id !! IPFS is not installed !?' && exit 1
# CLEAN "A_my_swarm.txt" and "A_swarm_map.txt"
rm -f ~/.zen/A_my_swarm.txt && touch ~/.zen/A_my_swarm.txt
rm -f ~/.zen/A_swarm_map.txt && touch ~/.zen/A_swarm_map.txt
########################################################################
# ENVIRONEMENT DETECTION + IPFS ~/.zen/ipfs/.$IPFSNODEID/G1SSB/_info
########################################################################
isIPFSRunning=$(ps auxf --sort=+utime | grep -w ipfs | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d ' ' -f 1)
[[ ! $isIPFSRunning ]] && echo "ERROR! ipfs daemon is not running. EXIT" && exit 1
########################################################################
# Force Strict #swarm0 !!?
# ipfs bootstrap rm --all
liking_me_count=0
friend_of_mine_count=0
echo $(date)
########################################################################
# Let's look for Friends and "IPFS swarm connect" with them
########################################################################
# 1. Get Gchange "liking_me" people list
for liking_me in $(~/.zen/astrXbian/zen/jaklis/jaklis.py -k ~/.zen/secret.dunikey -n "https://data.gchange.fr" stars | jq -r '.likes[].issuer');
do
[[ "$liking_me" == "" || "$liking_me" == "$G1PUB" ]] && continue
# DE TOUS CEUX QUI M'AIMENT JE VAIS LIRE LES MESSAGES pour collecter leurs ipfstryme vers ~/.zen/A_swarm_map.txt
# SI JE SUIS LEUR AMI EN RETOUR, je conserve leur ID dans ~/.zen/A_my_swarm.txt
# Check if my like is reverse
liking_me_count=$((liking_me_count+1))
echo ">>>>>> CHECKING liking_me n° $liking_me_count : READING 'ipfstryme' message from $liking_me"
for peerline in $(~/.zen/astrXbian/zen/jaklis/jaklis.py -k ~/.zen/secret.dunikey -n "https://data.gchange.fr" read -n300 -j | jq -r --arg friendKEY "$liking_me" '.[] | select(.pubkey == $friendKEY)' | jq 'select(.title == "ipfstryme")' | jq -r '.content');
do
echo "======================================================"
# GET $ipfsnodeid FROM $peerline
echo "PEERLINE: $peerline"
ipfsnodeid=${peerline##*/} # http://mywiki.wooledge.org/BashFAQ/100
[[ "$ipfsnodeid" == "" ]] && continue
[[ $(cat ~/.zen/A_my_swarm.txt | grep $ipfsnodeid ) ]] && continue # ALREADY in my SWARM
# GET $whoisg1 FROM $peerline
whoisg1=$(~/.zen/astrXbian/zen/tools/ipfs_to_g1.py $ipfsnodeid)
# KEEPING LAST ipfstryme MESSAGES only
nbmessage=0
for messageid in $(~/.zen/astrXbian/zen/jaklis/jaklis.py -k ~/.zen/secret.dunikey -n "https://data.gchange.fr" read -n300 -j | jq -r --arg friendKEY "$whoisg1" '.[] | select(.pubkey == $friendKEY)' | jq 'select(.title == "ipfstryme")' | jq -r '.id')
do
nbmessage=$((nbmessage+1))
[ $nbmessage -gt 1 ] && echo "Delete $nbmessage OLD 'ipfstryme' messages from $whoisg1" && ~/.zen/astrXbian/zen/jaklis/jaklis.py -k ~/.zen/secret.dunikey -n "https://data.gchange.fr" delete -i $messageid
sleep 0.5
done
[[ $nbmessage == 0 ]] && echo "NO ipfstryme MESSAGE from $whoisg1" && echo "$ipfsnodeid" >> ~/.zen/A_dead_swarm.txt && continue
# SEND MESSAGE ~/.zen/astrXbian/zen/jaklis/jaklis.py -k ~/.zen/secret.dunikey -n "https://data.gchange.fr" send -d $whoisg1 -t 'Astroport' -m 'Aucun message de ta part https://copylaradio.com'"
# REFRESH A_swarm_map.txt
echo $peerline >> ~/.zen/A_swarm_map.txt
cat ~/.zen/A_swarm_map.txt | sort | uniq > /tmp/A_swarm_map.txt
cp -f /tmp/A_swarm_map.txt ~/.zen/A_swarm_map.txt
# FRIEND ADDRESS DISCOVERY
echo "Am I friend with my FRIEND friend $whoisg1 ?"
friend_of_mine=$(~/.zen/astrXbian/zen/jaklis/jaklis.py -k ~/.zen/secret.dunikey -n "https://data.gchange.fr" stars -p $whoisg1 | jq -r '.yours.pseudo'); # must contains my XZUID
if [[ "$friend_of_mine" != "null" ]]; then
if [[ ! $(grep "$ipfsnodeid" ~/.zen/A_my_swarm.txt) ]]
then
echo "OK FRIEND"
# COUNT UNIQ FRIENDS
friend_of_mine_count=$((friend_of_mine_count+1))
echo "$peerline" >> ~/.zen/A_my_swarm.txt
ipfs bootstrap add "$peerline"
else
echo "ALREADY RECORDED FRIEND"
fi
else
echo "NOT FULL FRIEND $ipfsnodeid / $whoisg1"
[[ "$liking_me" != "" ]] && rm -Rf ~/.zen/ipfs/.${IPFSNODEID}/FRIENDS/$liking_me
# SEND ME A MESSAGE TO DECIDE WHAT TO DO ?
# SEND MESSAGE ~/.zen/astrXbian/zen/jaklis/jaklis.py -k ~/.zen/secret.dunikey -n "https://data.gchange.fr" send -d $whoisg1 -t 'Astroport' -m 'Rejoins mon #Swarm0 https://copylaradio.com'"
fi
done;
echo "__________________________________________"
done
# UNIQ file
cat ~/.zen/A_my_swarm.txt | sort | uniq > /tmp/A_my_swarm.txt
cp -f /tmp/A_my_swarm.txt ~/.zen/A_my_swarm.txt
echo "####################################################
I have $friend_of_mine_count friends amoung $liking_me_count liking me people
__________________________________________
My actual #SWARM0"
ipfs swarm peers
echo $(date)
# ipfs SWARM shaping
~/.zen/astrXbian/zen/ipfs_SWARM_refresh.sh