2020-12-12 01:26:39 +01:00
#!/bin/bash
########################################################################
# Author: Fred (support@qo-op.com)
2021-01-31 14:19:15 +01:00
# Version: 0.2
2020-12-12 01:26:39 +01:00
# 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-01-12 18:35:22 +01:00
# Retrieve Gchange profil data
# Sends "ipfstryme" messages to liked linking_me NODES
# If NODE is from "A_boostrap_nodes.txt" then auto-linking
2020-12-12 01:26:39 +01:00
########################################################################
2021-01-31 14:19:15 +01:00
# INITIALISATION & CONTROL
2020-12-12 01:26:39 +01:00
########################################################################
YOU = $( ps auxf --sort= +utime | grep -w ipfs | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d " " -f 1) ;
IPFSNODEID = $( ipfs id -f= '<id>\n' )
[ [ $IPFSNODEID = = "" ] ] && echo "ERROR missing IPFS Node id !! EXIT" && exit 1
########################################################################
[ [ ! -f ~/.zen/secret.dunikey ] ] && echo "Missing ~/.zen/secret.dunikey. EXIT" && exit 1
G1PUB = $( cat ~/.zen/secret.dunikey | grep 'pub:' | cut -d ' ' -f 2)
[ [ $G1PUB = = "" ] ] && echo "ERROR G1PUB empty !! EXIT" && exit 1
2021-04-02 23:26:47 +02:00
[ [ -f ~/.zen/ipfs/.$IPFSNODEID /_xbian.zuid ] ] && AXID = $( cat ~/.zen/ipfs/.$IPFSNODEID /_xbian.zuid)
2020-12-12 01:26:39 +01:00
2021-01-31 14:19:15 +01:00
########################################################################
# CREATNG IPFS LOCAL REPOSITORY for Node G1 Identity : G1SSB
2020-12-12 01:26:39 +01:00
mkdir -p ~/.zen/ipfs/.$IPFSNODEID /G1SSB
2021-01-31 14:19:15 +01:00
########################################################################
# CREATING MY tryme.addr
2020-12-24 16:29:36 +01:00
~/.zen/astrXbian/zen/tools/add_externIP_to_ipfstryme.sh
2020-12-12 01:26:39 +01:00
cat ~/.zen/ipfs/.${ IPFSNODEID } /tryme.addr
2021-01-31 14:19:15 +01:00
########################################################################
2020-12-12 01:26:39 +01:00
# ADD GCHANGE+ informations
2021-01-31 14:19:15 +01:00
########################################################################
2020-12-12 01:26:39 +01:00
GCHANGE = "https://data.gchange.fr"
2021-01-31 14:19:15 +01:00
# CREATE _g1.gchange_title
2021-03-18 00:18:48 +01:00
curl -s ${ GCHANGE } /user/profile/${ G1PUB } > /tmp/A_${ G1PUB } .cache
# rm -f ~/.zen/ipfs/.$IPFSNODEID/G1SSB/_g1.gchange_title
title = $( cat /tmp/A_${ G1PUB } .cache | jq -r '._source.title' )
2021-01-31 14:19:15 +01:00
[ [ $title ] ] && echo " $title " > ~/.zen/ipfs/.$IPFSNODEID /G1SSB/_g1.gchange_title
2020-12-12 01:26:39 +01:00
2021-02-13 00:40:45 +01:00
# CREATE _g1.astroport_title with city
2021-01-31 14:19:15 +01:00
rm -f ~/.zen/ipfs/.$IPFSNODEID /G1SSB/_g1.astroport_title
2021-04-02 23:26:47 +02:00
title = " Station $USER @ $AXID "
2021-03-18 00:18:48 +01:00
city = $( cat /tmp/A_${ G1PUB } .cache | jq -r '._source.city' )
2020-12-12 01:26:39 +01:00
[ [ " $city " != "null" ] ] && title = " $title in $city "
2021-01-31 14:19:15 +01:00
echo " $title " > ~/.zen/ipfs/.$IPFSNODEID /G1SSB/_g1.astroport_title
2020-12-12 01:26:39 +01:00
2021-03-18 00:18:48 +01:00
# GET _g1.gchange_avatar.png
cat /tmp/A_${ G1PUB } .cache | jq -r '._source.avatar._content' | base64 -d > " /home/ $YOU /.zen/ipfs/. $IPFSNODEID /G1SSB/_g1.gchange_avatar.png "
2020-12-12 01:26:39 +01:00
2021-01-31 14:19:15 +01:00
# CREATE _nodename
2020-12-12 01:26:39 +01:00
[ [ -f /home/$YOU /.zen/ipfs/.$IPFSNODEID /G1SSB/_nodename ] ] && nodename = $( cat /home/$YOU /.zen/ipfs/.$IPFSNODEID /G1SSB/_nodename)
if [ [ $nodename = = "" ] ] ; then
2021-01-31 14:19:15 +01:00
nodename = $( hostname)
2020-12-12 01:26:39 +01:00
extension = $( echo $nodename | cut -d '.' -f 2)
if [ [ $extension = = $nodename ] ] ; then
nodename = $nodename .home
fi
2021-01-31 14:19:15 +01:00
echo " $nodename " > ~/.zen/ipfs/.$IPFSNODEID /G1SSB/_nodename
2020-12-12 01:26:39 +01:00
fi
########################################################################
# DUNITER G1 Wallet balance
export LC_ALL = C.UTF-8 #attipix
export LANG = C.UTF-8 #attipix
2021-01-31 14:19:15 +01:00
# _g1.pubkey
2021-03-17 16:41:56 +01:00
[ [ ! ~/.zen/ipfs/.${ IPFSNODEID } /G1SSB/_g1.pubkey ] ] && echo " $G1PUB " > ~/.zen/ipfs/.${ IPFSNODEID } /G1SSB/_g1.pubkey
2021-03-18 00:18:48 +01:00
# TO REMOVE #######################################################################
2021-01-31 14:19:15 +01:00
# IPFS Adresses
2021-03-18 00:18:48 +01:00
[ [ -f ~/.zen/ipfs/.${ IPFSNODEID } /Addresses ] ] && rm ~/.zen/ipfs/.${ IPFSNODEID } /Addresses
2021-01-31 14:19:15 +01:00
# IPFS AgentVersion
2021-03-18 00:18:48 +01:00
[ [ -f ~/.zen/ipfs/.${ IPFSNODEID } /AgentVersion ] ] && rm ~/.zen/ipfs/.${ IPFSNODEID } /AgentVersion
########################################################################
# NODE DISK PERFORMANCE, manual remove ~/.ipfs/test.disk to run again
if [ [ ! -f ~/.ipfs/test.disk ] ] ; then
diskperf = $( dd if = /dev/zero of = ~/.ipfs/test.disk bs = 10M count = 1 oflag = dsync 2>& 1 | tail -n 1 | sed s/\, \ /\ -/g | cut -d '-' -f 4)
echo " DISK PERFORMANCE TESTING : $diskperf "
# NODE disk.perf
echo " $diskperf " > ~/.zen/ipfs/.${ IPFSNODEID } /disk.perf
# NODE disk.bytes
echo $( df ~/.ipfs/ | tail -n 1 | awk '{print $4}' ) > ~/.zen/ipfs/.${ IPFSNODEID } /disk.bytes
# IPFS repo.stat
ipfs repo stat > ~/.zen/ipfs/.${ IPFSNODEID } /repo.stat
# GEOLOC SHOULD BE SECURELY EXCHANGED
# CREATE "_g1.gchange_geoPoint.lat" AND "_g1.gchange_geoPoint.lon"
# rm -f ~/.zen/ipfs/.$IPFSNODEID/G1SSB/_g1.gchange_geoPoint.lat
# echo $(curl -s ${GCHANGE}/user/profile/${G1PUB} | jq '._source.geoPoint.lat') > ~/.zen/ipfs/.$IPFSNODEID/G1SSB/_g1.gchange_geoPoint.lat
# rm -f ~/.zen/ipfs/.$IPFSNODEID/G1SSB/_g1.gchange_geoPoint.lon
# echo $(curl -s ${GCHANGE}/user/profile/${G1PUB} | jq '._source.geoPoint.lon') > ~/.zen/ipfs/.$IPFSNODEID/G1SSB/_g1.gchange_geoPoint.lon
fi
2020-12-12 01:26:39 +01:00
###
2021-01-31 13:51:24 +01:00
#### FRIENDS && BOOTSTRAP ipfstryme MESSAGE sending procedure
2020-12-25 19:27:26 +01:00
########################################################################
2021-01-31 14:19:15 +01:00
# GET LIST of issuer(s) who likes me & A_boostrap_nodes.txt
2021-02-21 21:35:23 +01:00
IamBOOTSTRAP = $( cat ~/.zen/astrXbian/A_boostrap_nodes.txt | grep " $G1PUB " ) # AM I A BOOTSTRAP ?
2021-04-04 20:33:41 +02:00
################## AUTO PINNING for BOOTSTRAP
[ [ $IamBOOTSTRAP ] ] && ~/.zen/astrXbian/zen/tools/autoPINfriends.sh
2021-02-21 21:35:23 +01:00
################## AUTO PINNING
2021-03-17 16:54:15 +01:00
################## CHECKING WHO GAVE ME STARS
2021-03-10 07:07:06 +01:00
for liking_me in $( ~/.zen/astrXbian/zen/jaklis/jaklis.py -k ~/.zen/secret.dunikey stars | jq -r '.likes[].issuer' && cat ~/.zen/astrXbian/A_boostrap_nodes.txt | grep -Ev "#" ) ;
2020-12-12 01:26:39 +01:00
do
2021-03-17 16:54:15 +01:00
##### BOOTSTRAP AUTO LIKE BACK (NOT liking Myself)
2021-02-20 01:47:40 +01:00
if [ [ " $IamBOOTSTRAP " = = " $G1PUB " ] ] ; then
2021-02-22 02:17:21 +01:00
echo " I AM A BOOTSTRAP AUTO LIKING $liking_me FRIEND "
2021-03-05 19:50:21 +01:00
if [ [ ! -f ~/.zen/ipfs/.${ IPFSNODEID } /FRIENDS/$liking_me /tryme.addr && " $liking_me " != " $G1PUB " ] ] ; then
2021-02-20 01:47:40 +01:00
echo " SENDING 1 STAR AUTO LIKE to $liking_me "
2021-03-10 07:07:06 +01:00
/home/$YOU /.zen/astrXbian/zen/jaklis/jaklis.py -k ~/.zen/secret.dunikey unstars -p $liking_me
2021-02-20 01:47:40 +01:00
sleep $(( 1 + RANDOM % 2 )) # SLOW DOWN
2021-03-10 07:07:06 +01:00
/home/$YOU /.zen/astrXbian/zen/jaklis/jaklis.py -k ~/.zen/secret.dunikey stars -p $liking_me -n 1
2021-02-20 01:47:40 +01:00
sleep $(( 1 + RANDOM % 2 )) # SLOW DOWN
fi
2020-12-25 19:27:26 +01:00
fi
2021-01-31 13:51:24 +01:00
2021-03-19 02:37:03 +01:00
2021-03-19 20:22:24 +01:00
##### CHECKING IF WE LIKE EACH OTHER (AVOID LIKING MYSELF)
~/.zen/astrXbian/zen/jaklis/jaklis.py -k ~/.zen/secret.dunikey stars -p $liking_me > /tmp/Gstars.json
[ [ ! -f /tmp/Gstars.json ] ] && rm -Rf ~/.zen/ipfs/.${ IPFSNODEID } /FRIENDS/$liking_me && echo " $liking_me is a DEAD FRIEND !!! " && continue
friend_of_mine = $( cat /tmp/Gstars.json | jq -r '.yours' ) ;
2021-01-31 15:04:35 +01:00
if [ [ " $friend_of_mine " != "null" && " $liking_me " != " $G1PUB " ] ]
2021-01-31 13:51:24 +01:00
then
# ADD $liking_me TO MY ipfs FRIENDS list
2021-03-19 20:22:24 +01:00
echo " $liking_me is my FRIEND "
2021-01-31 13:51:24 +01:00
mkdir -p ~/.zen/ipfs/.${ IPFSNODEID } /FRIENDS/$liking_me
2021-03-19 20:22:24 +01:00
# REFRESH & PUBLISH stars friends map
stars = " $( cat /tmp/Gstars.json | jq -r '.yours.level' ) "
[ [ " $stars " = = "null" ] ] && rm -Rf ~/.zen/ipfs/.${ IPFSNODEID } /FRIENDS/$liking_me && echo " $friend_of_mine NO STAR !! Removing $liking_me " && continue ## REMOVE NO GOOD FRIENDS (no star)
cp /tmp/Gstars.json ~/.zen/ipfs/.${ IPFSNODEID } /FRIENDS/$liking_me /
echo " $stars " > ~/.zen/ipfs/.${ IPFSNODEID } /FRIENDS/$liking_me /stars.level && echo " ***** $stars STARS ***** "
2021-01-31 13:51:24 +01:00
# SEND jaklis message if tryme.addr is different from last one
2021-01-31 15:11:57 +01:00
if [ [ $( diff ~/.zen/ipfs/.${ IPFSNODEID } /tryme.addr ~/.zen/ipfs/.${ IPFSNODEID } /FRIENDS/$liking_me /tryme.addr 2>& 1) ] ]
2021-01-31 13:51:24 +01:00
then
echo " I AM $G1PUB "
echo " Sending IPFSTRYME message to $liking_me "
2021-03-12 00:40:49 +01:00
if [ [ -f ~/.zen/ipfs/.${ IPFSNODEID } /tryme.addr ] ] ; then
2021-03-19 20:22:24 +01:00
~/.zen/astrXbian/zen/jaklis/jaklis.py -k ~/.zen/secret.dunikey send -d $liking_me -t "ipfstryme" -f ~/.zen/ipfs/.${ IPFSNODEID } /tryme.addr
2021-03-12 00:40:49 +01:00
else
echo 'MISSING ~/.zen/ipfs/.${IPFSNODEID}/tryme.addr'
fi
2021-01-31 13:51:24 +01:00
else
2021-03-19 20:22:24 +01:00
echo " tryme.addr MESSAGE ALREADY SENT TO $liking_me "
2021-01-31 13:51:24 +01:00
fi
# MEMORIZE actual tryme.addr
cp -f ~/.zen/ipfs/.${ IPFSNODEID } /tryme.addr ~/.zen/ipfs/.${ IPFSNODEID } /FRIENDS/$liking_me /
2021-03-19 02:34:00 +01:00
2021-02-21 21:23:26 +01:00
fi
2021-02-15 11:09:43 +01:00
sleep $(( 1 + RANDOM % 2 )) # SLOW DOWN
2021-03-05 19:54:18 +01:00
# TODO: REMOVE NOT ANYMORE FRIENDS ~/.zen/ipfs/.${IPFSNODEID}/FRIENDS/$liking_me/
# Memorize $friend_of_mine loop and remove extra directories
2020-12-24 16:43:37 +01:00
done
2020-12-25 17:27:17 +01:00
2021-02-24 22:32:26 +01:00
## ADD tiddlywiki #TODO REMOVE #PUT in ISOConfig for next install
[ [ ! -f ~/.zen/ipfs/.${ IPFSNODEID } /index.html ] ] && mkdir -p ~/.zen/ipfs/.${ IPFSNODEID } && cp ~/.zen/astrXbian/.install/templates/tiddlywiki/index.html ~/.zen/ipfs/.${ IPFSNODEID } /index.html
2021-02-15 11:09:43 +01:00
# REFRESH IPNS SELF PUBLISH
########################################################################
~/.zen/astrXbian/zen/ipns_self_publish.sh
########################################################################
2021-01-31 14:19:15 +01:00
2020-12-12 01:26:39 +01:00
exit 0