You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

167 lines
7.9 KiB

#!/bin/bash
########################################################################
# Author: Fred (support@qo-op.com)
# Version: 0.2
# 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##*/}"
# Retrieve Gchange profil data
# Sends "ipfstryme" messages to liked linking_me NODES
# If NODE is from "A_boostrap_nodes.txt" then auto-linking
########################################################################
# INITIALISATION & CONTROL
########################################################################
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
########################################################################
# CREATNG IPFS LOCAL REPOSITORY for Node G1 Identity : G1SSB
mkdir -p ~/.zen/ipfs/.$IPFSNODEID/G1SSB
########################################################################
# CREATING MY tryme.addr
~/.zen/astrXbian/zen/tools/add_externIP_to_ipfstryme.sh
cat ~/.zen/ipfs/.${IPFSNODEID}/tryme.addr
########################################################################
# ADD GCHANGE+ informations
########################################################################
GCHANGE="https://data.gchange.fr"
# CREATE _g1.gchange_title
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')
[[ $title ]] && echo "$title" > ~/.zen/ipfs/.$IPFSNODEID/G1SSB/_g1.gchange_title
# CREATE _g1.astroport_title with city
rm -f ~/.zen/ipfs/.$IPFSNODEID/G1SSB/_g1.astroport_title
title="Station $USER@$(hostname)"
city=$(cat /tmp/A_${G1PUB}.cache | jq -r '._source.city')
[[ "$city" != "null" ]] && title="$title in $city"
echo "$title" > ~/.zen/ipfs/.$IPFSNODEID/G1SSB/_g1.astroport_title
# 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"
# CREATE _nodename
[[ -f /home/$YOU/.zen/ipfs/.$IPFSNODEID/G1SSB/_nodename ]] && nodename=$(cat /home/$YOU/.zen/ipfs/.$IPFSNODEID/G1SSB/_nodename)
if [[ $nodename == "" ]]; then
nodename=$(hostname)
extension=$(echo $nodename | cut -d '.' -f 2)
if [[ $extension == $nodename ]]; then
nodename=$nodename.home
fi
echo "$nodename" > ~/.zen/ipfs/.$IPFSNODEID/G1SSB/_nodename
fi
########################################################################
# DUNITER G1 Wallet balance
export LC_ALL=C.UTF-8 #attipix
export LANG=C.UTF-8 #attipix
# _g1.pubkey
[[ ! ~/.zen/ipfs/.${IPFSNODEID}/G1SSB/_g1.pubkey ]] && echo "$G1PUB" > ~/.zen/ipfs/.${IPFSNODEID}/G1SSB/_g1.pubkey
# TO REMOVE #######################################################################
# IPFS Adresses
[[ -f ~/.zen/ipfs/.${IPFSNODEID}/Addresses ]] && rm ~/.zen/ipfs/.${IPFSNODEID}/Addresses
# IPFS AgentVersion
[[ -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
###
#### FRIENDS && BOOTSTRAP ipfstryme MESSAGE sending procedure
########################################################################
# GET LIST of issuer(s) who likes me & A_boostrap_nodes.txt
IamBOOTSTRAP=$(cat ~/.zen/astrXbian/A_boostrap_nodes.txt | grep "$G1PUB") # AM I A BOOTSTRAP ?
################## AUTO PINNING
~/.zen/astrXbian/zen/tools/autoPINfriends.sh
################## AUTO PINNING
################## CHECKING WHO GAVE ME STARS
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 "#");
do
##### BOOTSTRAP AUTO LIKE BACK (NOT liking Myself)
if [[ "$IamBOOTSTRAP" == "$G1PUB" ]]; then
echo "I AM A BOOTSTRAP AUTO LIKING $liking_me FRIEND"
if [[ ! -f ~/.zen/ipfs/.${IPFSNODEID}/FRIENDS/$liking_me/tryme.addr && "$liking_me" != "$G1PUB" ]]; then
echo "SENDING 1 STAR AUTO LIKE to $liking_me"
/home/$YOU/.zen/astrXbian/zen/jaklis/jaklis.py -k ~/.zen/secret.dunikey unstars -p $liking_me
sleep $((1 + RANDOM % 2)) # SLOW DOWN
/home/$YOU/.zen/astrXbian/zen/jaklis/jaklis.py -k ~/.zen/secret.dunikey stars -p $liking_me -n 1
sleep $((1 + RANDOM % 2)) # SLOW DOWN
fi
fi
##### CHECKING IF WE LIKE EACH OTHER (AVOID LIKING MYSELF)
# publish star friends map
[[ -d ~/.zen/ipfs/.${IPFSNODEID}/FRIENDS/$liking_me/ ]] && ~/.zen/astrXbian/zen/jaklis/jaklis.py -k ~/.zen/secret.dunikey stars -p $liking_me > ~/.zen/ipfs/.${IPFSNODEID}/FRIENDS/$liking_me/Gstars.json
friend_of_mine=$(cat ~/.zen/ipfs/.${IPFSNODEID}/FRIENDS/$liking_me/Gstars.json | jq -r '.yours');
if [[ "$friend_of_mine" != "null" && "$liking_me" != "$G1PUB" ]]
then
# ADD $liking_me TO MY ipfs FRIENDS list
mkdir -p ~/.zen/ipfs/.${IPFSNODEID}/FRIENDS/$liking_me
# SEND jaklis message if tryme.addr is different from last one
if [[ $(diff ~/.zen/ipfs/.${IPFSNODEID}/tryme.addr ~/.zen/ipfs/.${IPFSNODEID}/FRIENDS/$liking_me/tryme.addr 2>&1) ]]
then
echo "I AM $G1PUB"
echo "Sending IPFSTRYME message to $liking_me"
if [[ -f ~/.zen/ipfs/.${IPFSNODEID}/tryme.addr ]]; then
~/.zen/astrXbian/zen/jaklis/jaklis.py -k ~/.zen/secret.dunikey send -d $liking_me -t "ipfstryme" -f ~/.zen/ipfs/.${IPFSNODEID}/tryme.addr
echo $(cat ~/.zen/ipfs/.${IPFSNODEID}/FRIENDS/$liking_me/Gstars.json | jq -r '.yours.level') > ~/.zen/ipfs/.${IPFSNODEID}/FRIENDS/$liking_me/stars.level
else
echo 'MISSING ~/.zen/ipfs/.${IPFSNODEID}/tryme.addr'
fi
else
echo "tryme.addr MESSAGE ALREADY SEND TO $liking_me"
fi
# MEMORIZE actual tryme.addr
cp -f ~/.zen/ipfs/.${IPFSNODEID}/tryme.addr ~/.zen/ipfs/.${IPFSNODEID}/FRIENDS/$liking_me/
fi
sleep $((1 + RANDOM % 2)) # SLOW DOWN
# TODO: REMOVE NOT ANYMORE FRIENDS ~/.zen/ipfs/.${IPFSNODEID}/FRIENDS/$liking_me/
# Memorize $friend_of_mine loop and remove extra directories
done
## 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
# REFRESH IPNS SELF PUBLISH
########################################################################
~/.zen/astrXbian/zen/ipns_self_publish.sh
########################################################################
exit 0