2021-06-21 09:57:46 +02:00
|
|
|
#!/bin/bash
|
|
|
|
########################################################################
|
|
|
|
# Author: Fred (support@qo-op.com)
|
|
|
|
# Version: 2021.03.21
|
|
|
|
# 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##*/}"
|
2021-08-05 23:57:29 +02:00
|
|
|
countMErunning=$(ps auxf --sort=+utime | grep -w $ME | grep -v -E 'color=auto|grep' | wc -l)
|
|
|
|
[[ $countMErunning -gt 2 ]] && echo "$ME already running $countMErunning time" && exit 0
|
2021-09-23 03:21:48 +02:00
|
|
|
start=`date +%s`
|
2021-06-21 09:57:46 +02:00
|
|
|
|
|
|
|
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
|
2021-12-03 23:59:57 +01:00
|
|
|
IPFSNODEID=$(cat ~/.ipfs/config | jq -r .Identity.PeerID)
|
2021-07-10 14:04:16 +02:00
|
|
|
[[ ! $IPFSNODEID ]] && echo 'ERROR missing IPFS Node id !! IPFS is not installed !?' && exit 1
|
2021-06-21 09:57:46 +02:00
|
|
|
########################################################################
|
|
|
|
########################################################################
|
|
|
|
# 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
|
|
|
|
########################################################################
|
|
|
|
########################################################################
|
|
|
|
## SYNC WITH FRIENDS
|
2021-08-05 23:57:29 +02:00
|
|
|
# _____ ____ ___ _____ _ _ ____
|
|
|
|
# | ___| _ \|_ _| ____| \ | | _ \
|
2021-06-21 09:57:46 +02:00
|
|
|
# | |_ | |_) || || _| | \| | | | |
|
|
|
|
# | _| | _ < | || |___| |\ | |_| |
|
2021-08-05 23:57:29 +02:00
|
|
|
# |_| |_| \_\___|_____|_| \_|____/
|
|
|
|
#
|
|
|
|
#
|
2021-08-17 02:29:15 +02:00
|
|
|
for g1id in $(ls ~/.zen/ipfs/.$IPFSNODEID/FRIENDS | shuf);
|
2021-06-21 09:57:46 +02:00
|
|
|
do
|
2021-08-06 03:50:09 +02:00
|
|
|
[[ "$g1id" == "index.html" ]] && continue
|
2021-09-13 18:10:35 +02:00
|
|
|
[ -d ~/.zen/ipfs/.$IPFSNODEID/FRIENDS/$g1id ] && ipfsnodeid=$(~/.zen/astrXbian/zen/tools/g1_to_ipfs.py $g1id) || continue
|
2021-07-10 13:22:49 +02:00
|
|
|
|
2021-09-13 18:10:35 +02:00
|
|
|
echo "=============================================="
|
|
|
|
echo "$ipfsnodeid"
|
|
|
|
echo "=============================================="
|
2021-08-06 03:50:09 +02:00
|
|
|
# Try to ping my friend OR continue
|
2021-09-13 18:10:35 +02:00
|
|
|
#ipfs --timeout=10s ping -n 3 /p2p/$ipfsnodeid || continue
|
2021-06-21 09:57:46 +02:00
|
|
|
|
2021-09-13 18:10:35 +02:00
|
|
|
#echo "REFRESHING Friend /ipns/$ipfsnodeid INTO ~/.zen/ipfs_swarm/"
|
|
|
|
#ipfs --timeout=90s get --output=/home/$YOU/.zen/ipfs_swarm/ /ipns/$ipfsnodeid
|
|
|
|
#[[ -f /home/$YOU/.zen/ipfs_swarm/.$ipfsnodeid/_xbian.zuid ]] && cat /home/$YOU/.zen/ipfs_swarm/.$ipfsnodeid/_xbian.zuid || echo "NO ZUID"
|
2021-09-02 14:37:02 +02:00
|
|
|
|
2021-09-13 18:10:35 +02:00
|
|
|
echo "This is the list of your friend $g1id friends liking you"
|
|
|
|
ls -d ~/.zen/ipfs_swarm/.$ipfsnodeid/FRIENDS/*/ 2>/dev/null | rev | cut -d '/' -f 2 | rev
|
|
|
|
echo "LIKING YOU?"
|
|
|
|
ls -d ~/.zen/ipfs_swarm/.$ipfsnodeid/FRIENDS/$G1PUB/ 2>/dev/null | rev | cut -d '/' -f 2 | rev
|
2021-08-06 03:50:09 +02:00
|
|
|
done
|
2021-06-21 09:57:46 +02:00
|
|
|
|
2021-09-23 03:21:48 +02:00
|
|
|
echo "#### EXCECUTION TIME"
|
|
|
|
end=`date +%s`
|
|
|
|
echo Execution time was `expr $end - $start` seconds.
|
|
|
|
echo "########################################################################"
|
2021-06-21 09:57:46 +02:00
|
|
|
exit 0
|
2021-09-02 14:37:02 +02:00
|
|
|
|