From f2f3492e675331941c50ac8a1fea9bc4b516c0a1 Mon Sep 17 00:00:00 2001 From: qo-op Date: Mon, 30 Nov 2020 18:42:36 +0100 Subject: [PATCH] INIT with gchange --- zen/gchange_INIT.sh | 112 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 zen/gchange_INIT.sh diff --git a/zen/gchange_INIT.sh b/zen/gchange_INIT.sh new file mode 100644 index 0000000..bb6274b --- /dev/null +++ b/zen/gchange_INIT.sh @@ -0,0 +1,112 @@ +#!/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='\n') +[[ $IPFSNODEID == "" ]] && echo "ERROR missing IPFS Node id !! IPFS is not installed !?" && exit 1 +######################################################################## +[[ ! -f ~/.zen/secret.dunikey ]] && $MY_PATH/tools/secret2dunikey.sh +G1PUB=$(cat ~/.zen/secret.dunikey | grep 'pub:' | cut -d ' ' -f 2) +[[ $G1PUB == "" ]] && echo "ERROR G1PUB empty !! Please check it..." && exit 1 +######################################################################## + + +# GET NODE disk performance. TODO, publish and use as IPFS repartition +echo "DISK SIZE AVAILABLE & PERFORMANCE TESTING" +[[ -f ~/.zen/test.disk ]] && rm -f ~/.zen/test.disk +diskperf=$(dd if=/dev/zero of=~/.zen/test.disk bs=10M count=1 oflag=dsync 2>&1 | tail -n 1 | sed s/\,\ /\ -/g | cut -d '-' -f 4) +# echo $diskperf +sizeAvail=$(df -h ~/.ipfs/ | tail -n 1 | awk '{print $4}') + +# IPFS LOCAL REPOSITORY for Node Identity G1 + SSB +mkdir -p ~/.zen/ipfs/.$IPFSNODEID/G1SSB + +# PUBLISH default "eth" NOT isLAN IP addresses for ./zen/ssb_IPFS_swarm.sh +tryme=$(ipfs id | jq -r .Addresses[] | tail -n 1 ) +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 ]] && sbotc publish '{"type":"ipfstryme","text":"'"$tryme"'"}' + +trymev4=$(ipfs id | jq -r .Addresses[] | grep $(hostname -I | cut -f 1 -d ' ')) +isLANv4=$(echo $trymev4 | 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 && ! $isLANv4 ]] && sbotc publish '{"type":"ipfstryme","text":"'"$trymev4"'"}' && tryme="$trymev4" + +trymev6=$(ipfs id | jq -r .Addresses[] | grep $(hostname -I | cut -f 2 -d ' ')) +isLANv6=$(echo $trymev6 | 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 && $isLANv4 && ! $isLANv6 ]] && sbotc publish '{"type":"ipfstryme","text":"'"$trymev6"'"}' && tryme="$trymev6" + +################################ +# 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.cesium_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') +[[ $geopointlat != null ]] && sbotc publish '{"type":"cesium_geoPoint.lat","text":"'"$geopointlat"'"}' +geopointlon=$(curl -s ${GCHANGE}/user/profile/${G1PUB} | jq '._source.geoPoint.lon') +[[ $geopointlon != null ]] && sbotc publish '{"type":"cesium_geoPoint.lon","text":"'"$geopointlon"'"}' + +# REFRESH Cesium+ Avatar image +curl -s ${GCHANGE}/user/profile/${G1PUB} | jq -r '._source.avatar._content' | base64 -d > "/tmp/_g1.avatar.png" + +# Get 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 +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 "$tryme" > ~/.zen/ipfs/.${IPFSNODEID}/tryme.addr +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) + +### +# + +exit 0