#!/bin/bash ######################################################################## # Author: Armust (support@qo-op.com) # Version: 2020.12.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##*/}" YOU=$(ps auxf --sort=+utime | grep -w ipfs | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d " " -f 1); IPFSNODEID=$(cat ~/.ipfs/config | jq -r .Identity.PeerID) myIP=$(hostname -I | awk '{print $1}' | head -n 1) IamInLAN=$(echo $myIP | grep -E "(^127\.)|(^192\.168\.)|(^fd42\:)|(^10\.)|(^172\.1[6-9]\.)|(^172\.2[0-9]\.)|(^172\.3[0-1]\.)|(^::1$)|(^[fF][cCdD])/" ) #EXTERNIP=$(curl -s http://whatismyip.akamai.com/) ######################################################################## echo "CREATING MY /home/$YOU/.zen/ipfs/.${IPFSNODEID}/tryme.addr" ######################################################################## mkdir -p ~/.zen/ipfs/.${IPFSNODEID} # echo "/ip4/$EXTERNIP/udp/4001/astro/p2p/${IPFSNODEID}" >> /home/$YOU/.zen/ipfs/.${IPFSNODEID}/tryme.addr # Doesn't have the right NATed port, so pretty useless... rm -f ~/.zen/ipfs/.${IPFSNODEID}/tryme.addr touch ~/.zen/ipfs/.${IPFSNODEID}/tryme.addr ######################################################################## ## If my address is published by my friends, sending it only. # ME=$(cat ~/.zen/ipfs/.*/FRIENDS/*/tryme.addr | grep $IPFSNODEID | sort | uniq) # [[ $ME ]] && cat ~/.zen/ipfs/.*/FRIENDS/*/tryme.addr | grep $IPFSNODEID | sort | uniq > ~/.zen/ipfs/.${IPFSNODEID}/tryme.addr && exit 0 ######################################################################## for tryme in $(ipfs id | jq -r .Addresses[]); do isLAN=$(echo $tryme | cut -f3 -d '/' | grep -E "(^127\.)|(^192\.168\.)|(^fd42\:)|(^10\.)|(^172\.1[6-9]\.)|(^172\.2[0-9]\.)|(^172\.3[0-1]\.)|(^::1$)|(^[fF][cCdD])/") [[ ! $isLAN ]] && echo "$tryme" >> ~/.zen/ipfs/.${IPFSNODEID}/tryme.addr done ## Add "liking me" in "swarm peers" station if [[ -f /tmp/liking_me ]]; then for liking_me in $(cat /tmp/liking_me | sort | uniq); do ipfsnodeid=$(~/.zen/astrXbian/zen/tools/g1_to_ipfs.py $liking_me) [[ -f /tmp/ipfs_swarm_peers ]] && ipfsaddress=$(cat /tmp/ipfs_swarm_peers | grep $ipfsnodeid | tail -n 1) if [[ $ipfsaddress ]]; then nodeip=$(echo $ipfsaddress | cut -d '/' -f 3) IsLAN=$(echo $nodeip | grep -E "(^127\.)|(^192\.168\.)|(^fd42\:)|(^10\.)|(^172\.1[6-9]\.)|(^172\.2[0-9]\.)|(^172\.3[0-1]\.)|(^::1$)|(^[fF][cCdD])/" ) [[ ! $IsLAN ]] && echo "$ipfsaddress" >> ~/.zen/ipfs/.${IPFSNODEID}/tryme.addr fi done fi # SORT UNIQ cat ~/.zen/ipfs/.${IPFSNODEID}/tryme.addr | sort | uniq > /tmp/tryme.addr cp -f /tmp/tryme.addr ~/.zen/ipfs/.${IPFSNODEID}/tryme.addr # REFRESH ~/.zen/A_my_swarm.txt cp -f ~/.zen/ipfs/.${IPFSNODEID}/tryme.addr ~/.zen/A_swarm_map.txt cat ~/.zen/ipfs/.${IPFSNODEID}/tryme.addr exit 0