#!/bin/bash ######################################################################## # Author: Fred (support@qo-op.com) # Version: 2020.03.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##*/}" ######################################################################## # \\/// # qo-op ############# '$MY_PATH/$ME' ######################################################################## # ex: ./'$ME' ######################################################################## # This script is controling IPFS swarm # Sync friends peers ~/.zen/ipfs/ into ~/.zen/ipfs_swarm/.IPFSNODEID's/ directories # add not friend_of_mine IPs to fail2ban ######################################################################## # TODO remove because now it is in~/.bashrc export YOU=$(ps auxf --sort=+utime | grep -w ipfs | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d " " -f 1) export IPFSNODEID=$(ipfs id -f='\n') ######################################################################## mkdir -p ~/.zen/ipfs_swarm echo ' ___ _ _ __ __ _ _ _ _ _ _ __ | |_)|_(_ (_\ //\ |_)|\/| |_)|_|_|_)|_(_ |_| _|_| | __) __)\/\//--\| \| | | \|_| | \|___)| | ' echo "I am $IPFSNODEID" echo "REFRESHING /home/$YOU/.zen/ipfs_swarm/ from my SWARM peers" rm -Rf /home/$YOU/.zen/ipfs_swarm/.12D3KooW* rm -Rf /home/$YOU/.zen/ipfs_swarm/.Qm* rm -Rf /home/$YOU/.zen/ipfs_swarm/* count=1 for peer in $(ipfs swarm peers); do ipfsnodeid=$(echo "$peer" | awk -F '/' '{print $7}') ip=$(echo "$peer" | awk -F '/' '{print $3}') nowdate=$(date) timestamp=$(date -u +%s%N | cut -b1-13) echo "$nowdate - $id - $ip" foundIp=$(cat ~/.zen/A_allow_ip.txt | grep "$ip" | wc -l) if [ "$foundIp" -eq 0 ] ; then echo "${ip} of peer ${id} is not in the authorized ip list." echo "${peer} will be removed from the swarm" ipfs swarm disconnect $peer ipfs bootstrap rm $peer [[ $USER == "pi" || $USER == "xbian" ]] && echo "BAN $ip" \ && sudo fail2ban-client add recidive \ && sudo fail2ban-client set recidive banip $ip else # REFRESH ~/.zen/ipfs_swarm/ $MY_PATH/tools/timeout.sh -t 30 ipfs get --output=/home/$YOU/.zen/ipfs_swarm/ /ipns/$ipfsnodeid fi done echo "PUBLISHING MY OWN /home/$YOU/.zen/ipfs/ to SWARM" [[ ! -d /home/$YOU/.zen/ipfs ]] && echo "ERROR : /home/$YOU/.zen/ipfs/ NOT FOUND" && exit 1 IWALLETS=$(ipfs add -rHq /home/$YOU/.zen/ipfs | tail -n 1) NODEIPNS=$(ipfs name publish --quieter /ipfs/$IWALLETS) # Put my own data in /home/$YOU/.zen/ipfs_swarm/ ipfs get --output=/home/$YOU/.zen/ipfs_swarm/ /ipns/$IPFSNODEID exit 0