astrXbian/zen/gchange_INIT.sh

139 lines
6.2 KiB
Bash
Executable File
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/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
[[ -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 "DISK PERFORMANCE TESTING : $diskperf"
# IPFS LOCAL REPOSITORY for Node Identity
mkdir -p ~/.zen/ipfs/.$IPFSNODEID/G1SSB
# create IPFSTRYME public address file
~/.zen/astrXbian/zen/tools/add_externIP_to_ipfstryme.sh
cat ~/.zen/ipfs/.${IPFSNODEID}/tryme.addr
################################
# ADD GCHANGE+ 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
## PUBLISH ~/.zen/ipfs on self key IPNS
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
########################################################################
# GET LIST of issuer(s) who likes me
for liking_me in $(~/.zen/astrXbian/zen/jaklis/jaklis.py like | jq -r '.likes[].issuer');
do
# CHECk if I am liking him either
friend_of_mine=$(~/.zen/astrXbian/zen/jaklis/jaklis.py like -p $liking_me | jq -r '.yours');
echo "Sending IPFSTRYME message to $liking_me"
[[ $friend_of_mine != null ]] && ~/.zen/astrXbian/zen/jaklis/jaklis.py send -d $liking_me -t "ipfstryme" -f ~/.zen/ipfs/.${IPFSNODEID}/tryme.addr
sleep 3 # SLOW DOWN
done
echo 'SEND ipfstryme to A_boostrap_nodes.txt listed PUBs' # Add your bootstrap Pub here
for g1node in $(cat ~/.zen/astrXbian/A_boostrap_nodes.txt | grep -Ev "#") # remove comments
do
if [[ $g1node != "" ]]; then
echo "LIKING my BOOTSTRAP node : $g1node"
# ~/.zen/astrXbian/zen/jaklis/jaklis.py -n "https://g1.data.le-sou.org" send -d $g1node -t "ipfstryme" -f ~/.zen/ipfs/.${IPFSNODEID}/tryme.addr
~/.zen/astrXbian/zen/jaklis/jaklis.py send -d $g1node -t "ipfstryme" -f ~/.zen/ipfs/.${IPFSNODEID}/tryme.addr
/home/$YOU/.zen/astrXbian/zen/jaklis/jaklis.py unlike -p $g1node
/home/$YOU/.zen/astrXbian/zen/jaklis/jaklis.py like -p $g1node -s 3
isG1PUBoot=$(cat ~/.zen/astrXbian/A_boostrap_nodes.txt | grep "$G1PUB") # search my G1PUB ?
if [[ $isG1PUBoot == "$G1PUB" ]]; then
for liking_me in $(/home/$YOU/.zen/astrXbian/zen/jaklis/jaklis.py like | jq -r '.likes[].issuer')
do
echo "SENDING 3 STARS to $liking_me"
/home/$YOU/.zen/astrXbian/zen/jaklis/jaklis.py unlike -p $liking_me
/home/$YOU/.zen/astrXbian/zen/jaklis/jaklis.py like -p $liking_me -s 3
done
#$(cat ~/.zen/ipfs_swarm/xbian/_*) # ACTIVATE AUTO FULL RESTORE
fi
fi
done
# RESTORE Vstream astroport.py source
if [[ -f ~/.zen/astroport.py ]]; then
cp -f ~/.zen/astroport.py ~/.kodi/addons/plugin.video.vstream/resources/sites/
fi
exit 0