forked from axiom-team/astroport
84 lines
3.6 KiB
Bash
Executable File
84 lines
3.6 KiB
Bash
Executable File
#!/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'
|
|
# SYNC IPFS SWARM PEERS SHARED DATA .Qm****
|
|
########################################################################'
|
|
export YOU=$(ps auxf --sort=+utime | grep -w ipfs | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d " " -f 1);
|
|
[[ $YOU == "" ]] && echo "Please run ipfs daemon" && exit 1
|
|
########################################################################
|
|
# 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)
|
|
########################################################################
|
|
|
|
mkdir -p ~/.zen/ipfs_swarm
|
|
echo '
|
|
___ _ _ __ __ _ _ _ _ _ _ __
|
|
| |_)|_(_ (_\ //\ |_)|\/| |_)|_|_|_)|_(_ |_|
|
|
_|_| | __) __)\/\//--\| \| | | \|_| | \|___)| |
|
|
|
|
'
|
|
echo "I am $IPFSNODEID"
|
|
|
|
## CHANNELS SWARM INDEX COPY PROCEDURE
|
|
## SIGNAL ~/.zen/g1sms_wallets TODO
|
|
|
|
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)
|
|
ipfs get --output=/home/$YOU/.zen/ipfs_swarm/ /ipns/$IPFSNODEID
|
|
|
|
echo "REFRESHING /home/$YOU/.zen/ipfs_swarm/ from my SWARM peers"
|
|
count=1
|
|
# Search for All peers Nodes. ## TODO: To be changed when Swarm is too big or not expanding
|
|
#for id in $(ls -d ~/.zen/ipfs_swarm/.Qm* | cut -d '.' -f 3); # Alternative search...
|
|
for peer in $(ipfs swarm peers);
|
|
do
|
|
id=$(echo "$peer" | grep 'ip4' | awk -F '/' '{print $7}')
|
|
# FULL REFRESH (allow deletion, for DEV period)
|
|
# TODO: COMMENT TO LOWER DISK USAGE
|
|
[[ "$id" == "" ]] && echo "WARNING! ID empty for $peer " && continue
|
|
echo "Refreshing /home/$YOU/.zen/ipfs_swarm/.$id ($count)"
|
|
rm -Rf /home/$YOU/.zen/ipfs_swarm/.$id
|
|
$MY_PATH/tools/timeout.sh -t 30 ipfs get --output=/home/$YOU/.zen/ipfs_swarm/ /ipns/$id
|
|
|
|
|
|
#### IPFS SWARM - BLOB SHAPING CONTROL -
|
|
### CHECK Astroport Station Database Coherence?
|
|
if [[ ! -d /home/$YOU/.zen/ipfs_swarm/.$id ]]; then
|
|
echo "WARNING! $peer is NOT an Astroport Station !!"
|
|
ipfs swarm disconnect $peer
|
|
ipfs bootstrap rm $peer
|
|
fi
|
|
|
|
### Is "ipfs_swarm/.$id/G1SSB/_ssb.whoami" my SSB friend??
|
|
ssbID=$(cat /home/$YOU/.zen/ipfs_swarm/.$id/G1SSB/_ssb.whoami)
|
|
isMyFriend=$(grep -Rwl "$ssbID" /tmp/ssb-friends.txt)
|
|
[[ ! $isMyFriend ]] && echo "WARNING! $count IS NOT my SSB Friend !!! Check $ssbID" # TODO Send sbotc message?
|
|
# TODO: PROD ACTIVATE # && ipfs swarm disconnect $peer && ipfs bootstrap rm $peer
|
|
## TODO: Use fail2ban if same node continue entering our swarm...
|
|
|
|
count=$((count+1))
|
|
|
|
done
|
|
|
|
# TODO: TASK treatment.
|