forked from axiom-team/astroport
118 lines
5.1 KiB
Bash
Executable File
118 lines
5.1 KiB
Bash
Executable File
#!/bin/bash
|
|
########################################################################
|
|
# Author: Fred (support@qo-op.com)
|
|
# Version: 2020.11.30
|
|
# 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##*/}"
|
|
|
|
########################################################################
|
|
# ENVIRONEMENT DETECTION + IPFS ~/.zen/ipfs/.$IPFSNODEID/G1SSB/_info
|
|
########################################################################
|
|
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
|
|
########################################################################
|
|
|
|
# GET NODE disk performance. TODO, publish and use as IPFS repartition
|
|
echo "DISK SIZE AVAILABLE & PERFORMANCE TESTING"
|
|
[[ -f ~/.ipfs/test.disk ]] && rm -f ~/.ipfs/test.disk
|
|
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 $diskperf
|
|
|
|
# IPFS LOCAL REPOSITORY for Node Identity
|
|
mkdir -p ~/.zen/ipfs/.$IPFSNODEID/G1SSB
|
|
|
|
# find IPFSTRYME public address
|
|
echo "" > ~/.zen/ipfs/.${IPFSNODEID}/tryme.addr
|
|
for tryme in $(ipfs id | jq -r .Addresses[]);
|
|
do
|
|
isLAN=$(echo $tryme | cut -f3 -d '/' | grep -E "(^127\.)|(^192\.168\.)|(^fd42\:)|(^10\.)|(^172\.1[6-9]\.)|(^172\.2[0-9]\.)|(^172\.3[0-1]\.)|(^::1$)|(^[fF][cCdD])/")
|
|
[[ ! $isLAN ]] && echo "$tryme" >> ~/.zen/ipfs/.${IPFSNODEID}/tryme.addr
|
|
done
|
|
cat ~/.zen/ipfs/.${IPFSNODEID}/tryme.addr
|
|
|
|
|
|
################################
|
|
# ADD Cesium+ informations
|
|
GCHANGE="https://data.gchange.fr"
|
|
|
|
# PREPARE title
|
|
# Made from Gchange+ profile tittle and city OR user@hostname
|
|
title=$(curl -s ${GCHANGE}/user/profile/${G1PUB} | jq -r '._source.title')
|
|
[[ -f ~/.zen/ipfs/.$IPFSNODEID/G1SSB/_uidna ]] && uidna=$(cat ~/.zen/ipfs/.$IPFSNODEID/G1SSB/_uidna)
|
|
|
|
# Put in .$IPFSNODEID INDEX: _g1.uidna & _g1.cesium_name (used by Minetest flavour and others)
|
|
[[ $uidna ]] && echo "$uidna" > ~/.zen/ipfs/.$IPFSNODEID/G1SSB/_g1.uidna
|
|
[[ $title ]] && echo "$title" > ~/.zen/ipfs/.$IPFSNODEID/G1SSB/_g1.gchange_name
|
|
|
|
[[ $uidna ]] && [[ "$title" == "null" ]] && title="Station $uidna"
|
|
[[ "$title" == "null" ]] && title="Station $USER@$(cat /etc/hostname)"
|
|
|
|
city=$(curl -s ${GCHANGE}/user/profile/${G1PUB} | jq -r '._source.city')
|
|
[[ "$city" != "null" ]] && title="$title in $city"
|
|
|
|
|
|
# ADD "cesium_geoPoint.lat" AND "cesium_geoPoint.lon" messages in SSB feed
|
|
# This way any SSB account is connected to its Cesium+ Geolocalisation.
|
|
geopointlat=$(curl -s ${GCHANGE}/user/profile/${G1PUB} | jq '._source.geoPoint.lat')
|
|
geopointlon=$(curl -s ${GCHANGE}/user/profile/${G1PUB} | jq '._source.geoPoint.lon')
|
|
|
|
# REFRESH Cesium+ Avatar image
|
|
curl -s ${GCHANGE}/user/profile/${G1PUB} | jq -r '._source.avatar._content' | base64 -d > "/tmp/_gchange.avatar.png"
|
|
|
|
# Get nodename
|
|
[[ -f /home/$YOU/.zen/ipfs/.$IPFSNODEID/G1SSB/_nodename ]] && nodename=$(cat /home/$YOU/.zen/ipfs/.$IPFSNODEID/G1SSB/_nodename)
|
|
if [[ $nodename == "" ]]; then
|
|
nodename=$(cat /etc/hostname)
|
|
extension=$(echo $nodename | cut -d '.' -f 2)
|
|
if [[ $extension == $nodename ]]; then
|
|
nodename=$nodename.home
|
|
fi
|
|
echo "$nodename" > /home/$YOU/.zen/ipfs/.$IPFSNODEID/G1SSB/_nodename
|
|
fi
|
|
########################################################################
|
|
# DUNITER G1 Wallet balance
|
|
export LC_ALL=C.UTF-8 #attipix
|
|
export LANG=C.UTF-8 #attipix
|
|
|
|
# COPY NODE G1SSB ID to IPFS
|
|
echo "$G1PUB" > ~/.zen/ipfs/.$IPFSNODEID/G1SSB/_g1.pubkey
|
|
|
|
# IPFS Node PUBLISH Adresses so Pub can become bootstrap for ${g1author}
|
|
ipfs id | jq -r .Addresses[] > ~/.zen/ipfs/.${IPFSNODEID}/Addresses
|
|
|
|
# IPFS Node PUBLISH AgentVersion & repo.stat
|
|
ipfs id | jq -r .AgentVersion > ~/.zen/ipfs/.${IPFSNODEID}/AgentVersion
|
|
ipfs repo stat > ~/.zen/ipfs/.${IPFSNODEID}/repo.stat
|
|
|
|
echo "$diskperf" > ~/.zen/ipfs/.${IPFSNODEID}/disk.perf
|
|
echo $(df ~/.ipfs/ | tail -n 1 | awk '{print $4}') > ~/.zen/ipfs/.${IPFSNODEID}/disk.bytes
|
|
|
|
|
|
IWALLETS=$(ipfs add -rHq ~/.zen/ipfs | tail -n 1)
|
|
NODEIPNS=$(ipfs name publish --allow-offline --quieter /ipfs/$IWALLETS)
|
|
|
|
###
|
|
# GET ALL MY GCHANGE FRIENDS AND SEND THEM my IPFS Address
|
|
|
|
cd ~/.zen/astroport/zen/jaklis
|
|
# GET LIST of issuer(s) who likes me
|
|
for liking_me in $(./jaklis.py like | jq -r '.likes[].issuer');
|
|
do
|
|
# CHECk if I am liking him either
|
|
friend_of_mine=$(./jaklis.py like -p $liking_me | jq -r '.yours');
|
|
echo "Sending IPFSTRYME message to $friend"
|
|
[[ $friend_of_mine != null ]] && ./jaklis.py send -d $liking_me -t "ipfstryme" -f ~/.zen/ipfs/.${IPFSNODEID}/tryme.addr
|
|
done
|
|
cd -
|
|
# TODO: This message should be regularly deleted by receiver and sent again to refresh changing IP
|
|
|
|
exit 0
|