2020-03-21 05:02:16 +01:00
#!/bin/bash
########################################################################
# Author: Fred (support@qo-op.com)
# Version: 2020.03.21
# 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 ##*/ } "
echo '
########################################################################
# \\///
# qo-op
2020-03-22 05:41:24 +01:00
############# '$MY_PATH/$ME'
2020-03-21 05:02:16 +01:00
########################################################################
# ex: ./'$ME'
2020-04-19 11:30:03 +02:00
# Initialize G1SSB + SSB About + IPFS Node publish
2020-03-21 05:02:16 +01:00
########################################################################
o__ __o __o o__ __o o__ __o o__ __o
/v v\ __| > /v v\ /v v\ <| v\
/> <\ | /> <\ /> <\ / \ <\
o/ <o> _\o ____ _\o ____ \o / o/
<| _\_ _o__ | \_ \_ _o__ \_ \_ _o__ | __ _<|
\\ | < > \ \ | \
\ / | \ / \ / <o> /
o o o o o o o | o
<\_ _ __/> __| >_ <\_ _ __/> <\_ _ __/> / \ __/>
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
# [ASTROPORT](https://astroport.com)
########################################################################
'
2020-03-29 15:44:01 +02:00
2020-03-23 19:07:37 +01:00
########################################################################
2020-03-24 01:20:10 +01:00
# ENVIRONEMENT DETECTION + IPFS ~/.zen/ipfs/.$ipfsnodeid/G1SSB/_info
2020-03-23 19:07:37 +01:00
########################################################################
2020-03-24 01:20:10 +01:00
ipfsnodeid = $( ipfs id -f= '<id>\n' )
2020-03-24 20:53:44 +01:00
[ [ $ipfsnodeid = = "" ] ] && echo "ERROR missing IPFS Node id !! IPFS is not installed !?" && exit 1
2020-03-23 19:07:37 +01:00
########################################################################
2020-03-22 04:45:20 +01:00
ssbpub = $( sbotc whoami 2>/dev/null | jq -r .id)
2020-04-28 14:27:25 +02:00
[ [ $ssbpub = = "" ] ] && echo "ERROR sbotc NOT running !! Please check it..." && exit 1
2020-03-24 01:20:10 +01:00
########################################################################
[ [ ! -f ~/.ssb/secret.dunikey ] ] && $MY_PATH /tools/secret2dunikey.sh
g1pub = $( cat ~/.ssb/secret.dunikey | grep 'pub:' | cut -d ' ' -f 2)
2020-04-15 04:37:01 +02:00
[ [ $g1pub = = "" ] ] && echo "ERROR g1pub empty !! Please check it..." && exit 1
2020-03-24 01:20:10 +01:00
########################################################################
2020-03-22 04:45:20 +01:00
2020-05-09 02:09:19 +02:00
# GET NODE disk performance. TODO, publish and use as IPFS repartition
2020-05-14 00:47:30 +02:00
echo "DISK SIZE AVAILABLE & PERFORMANCE TESTING"
2020-05-11 04:20:30 +02:00
[ [ -f ~/.zen/test.disk ] ] && rm -f ~/.zen/test.disk
2020-05-12 18:55:17 +02:00
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)
2020-05-12 22:26:45 +02:00
# echo $diskperf
2020-05-14 00:47:30 +02:00
sizeAvail = $( df -h ~/ | tail -n 1 | awk '{print $4}' )
2020-05-09 02:09:19 +02:00
2020-03-24 20:53:44 +01:00
# IPFS LOCAL REPOSITORY for Node Identity G1 + SSB
2020-03-24 01:20:10 +01:00
mkdir -p ~/.zen/ipfs/.$ipfsnodeid /G1SSB
2020-04-28 03:50:48 +02:00
2020-05-14 00:47:30 +02:00
# SSB PUBLISH ipfs informations
2020-05-06 19:41:50 +02:00
sbotc publish '{"type":"ipfsnodeid","text":"' " $( ipfs id -f= '<id>\n' ) " '"}'
2020-04-28 02:38:20 +02:00
sbotc publish '{"type":"ipfstryme","text":"' " $( ipfs id | jq -r .Addresses[ ] | tail -n 1) " '"}'
2020-03-22 04:45:20 +01:00
2020-04-28 04:30:29 +02:00
################################
2020-04-28 03:50:48 +02:00
# ADD Cesium+ informations
CESIUM = "https://g1.data.le-sou.org"
2020-04-28 04:30:29 +02:00
2020-05-14 00:47:30 +02:00
# PREPARE title
2020-05-09 13:00:09 +02:00
[ [ -f ~/.zen/ipfs/.$ipfsnodeid /G1SSB/_uidna ] ] && uidna = $( cat ~/.zen/ipfs/.$ipfsnodeid /G1SSB/_uidna)
2020-05-11 04:20:30 +02:00
[ [ ! $uidna ] ] && title = $( curl -s ${ CESIUM } /user/profile/${ g1pub } | jq -r '._source.title' ) || title = " Station $uidna "
2020-04-28 04:30:29 +02:00
[ [ $title = = null ] ] && title = " Station $USER @ $( cat /etc/hostname) "
2020-05-11 04:20:30 +02:00
city = $( curl -s ${ CESIUM } /user/profile/${ g1pub } | jq -r '._source.city' )
2020-04-28 04:30:29 +02:00
[ [ $city != null ] ] && title = " $title in $city "
2020-05-14 00:47:30 +02:00
# REFRESH cesium_geoPoint in SSB feed
2020-04-28 03:50:48 +02:00
geopointlat = $( curl -s ${ CESIUM } /user/profile/${ g1pub } | jq '._source.geoPoint.lat' )
[ [ $geopointlat != null ] ] && sbotc publish '{"type":"cesium_geoPoint.lat","text":"' " $geopointlat " '"}'
geopointlon = $( curl -s ${ CESIUM } /user/profile/${ g1pub } | jq '._source.geoPoint.lon' )
[ [ $geopointlon != null ] ] && sbotc publish '{"type":"cesium_geoPoint.lon","text":"' " $geopointlon " '"}'
2020-05-14 00:47:30 +02:00
# REFRESH Cesium+ Avatar image
2020-05-11 04:30:10 +02:00
curl -s ${ CESIUM } /user/profile/${ g1pub } | jq -r '._source.avatar._content' | base64 -d > "/tmp/_g1.avatar.png"
2020-04-28 03:50:48 +02:00
2020-03-21 05:02:16 +01:00
## PUBLISH ABOUT MESSAGE
##############################################
2020-04-28 03:50:48 +02:00
# IF AVATAR not png take IMAGE of G1 wallet QRCode
2020-04-28 04:30:29 +02:00
qrencode -s 5 -o ~/.zen/ipfs/.$ipfsnodeid /G1SSB/_g1.qrcode.png " $g1pub "
2020-05-12 18:46:41 +02:00
imagefile = ~/.zen/ipfs/.$ipfsnodeid /G1SSB/_g1.qrcode.png
qrname = ${ imagefile ##*/ }
qrid = " $( sbotc blobs.add < $imagefile ) "
qrtype = " $( file -b --mime-type $imagefile ) "
qrsize = " $( wc -c < $imagefile ) "
2020-04-28 04:30:29 +02:00
2020-05-11 04:30:10 +02:00
if [ [ ! $( file "/tmp/_g1.avatar.png" | grep 'PNG' ) ] ] ; then
2020-05-10 03:51:50 +02:00
echo "NO Cesium AVATAR - Using G1Pub QRCode"
2020-05-11 04:30:10 +02:00
rm -f /tmp/_g1.avatar.png
2020-04-28 03:50:48 +02:00
else
2020-05-10 03:51:50 +02:00
echo "AVATAR FOUND"
2020-05-11 04:30:10 +02:00
imagefile = /tmp/_g1.avatar.png
2020-05-14 00:47:30 +02:00
# PUBLISH AVATAR TO IPFS
2020-05-11 04:30:10 +02:00
cp /tmp/_g1.avatar.png ~/.zen/ipfs/.$ipfsnodeid /G1SSB/
2020-04-28 03:50:48 +02:00
fi
2020-05-10 03:51:50 +02:00
2020-03-24 01:20:10 +01:00
# Prepare QRCode File for SSB
2020-05-10 03:51:50 +02:00
name = ${ imagefile ##*/ }
id = " $( sbotc blobs.add < $imagefile ) "
type = " $( file -b --mime-type $imagefile ) "
size = " $( wc -c < $imagefile ) "
2020-03-24 01:20:10 +01:00
2020-03-24 20:53:44 +01:00
echo "
2020-03-24 01:20:10 +01:00
2020-03-24 20:53:44 +01:00
/\ | _ _ _| _
/--\| _) ( _) | _|| _ : PUBLISH to SSB feed...
2020-03-21 05:02:16 +01:00
2020-03-24 20:53:44 +01:00
$ssbpub
2020-05-11 04:33:25 +02:00
$title
$imagefile
$id : $type : $size bits
2020-03-21 05:02:16 +01:00
2020-03-24 20:53:44 +01:00
"
2020-05-14 00:47:30 +02:00
nodename = $( cat /etc/hostname)
extension = $( echo $nodename | cut -d '.' -f 2)
if [ [ $extension = = $nodename ] ] ; then
2020-05-14 02:59:13 +02:00
nodename = $nodename .home
2020-05-14 00:47:30 +02:00
fi
2020-03-22 04:45:20 +01:00
2020-05-14 00:47:30 +02:00
########################################################################
# DUNITER G1 Wallet balance
2020-05-10 03:28:36 +02:00
export LC_ALL = C.UTF-8 #attipix
export LANG = C.UTF-8 #attipix
2020-04-28 14:27:25 +02:00
DUNITERNODE = $( $MY_PATH /tools/duniter_getnode.sh)
2020-05-10 04:02:03 +02:00
[ [ $DUNITERNODE ] ] && g1balance = $( silkaj -p $DUNITERNODE balance $g1pub 2>& 1) || g1balance = $( silkaj balance $g1pub 2>& 1)
2020-05-14 02:59:13 +02:00
silkajQuantitativeAmountPattern = 'Total\sQuantitative\s+=\s+(.*)\s+Ğ1'
if [ [ $g1balance = ~ $silkajQuantitativeAmountPattern ] ]
then
myJune = " ${ BASH_REMATCH [1] } "
else
myJune = "0 June"
fi
2020-05-11 05:22:57 +02:00
2020-05-14 03:02:46 +02:00
# OLD ssb-server publish
# sbot publish --type about --about $ssbpub --description "[Astroport Node](https://astroport.com) [$ipfsnodeid](http://localhost:8080/ipns/$ipfsnodeid) - Wallet $g1pub - $diskperf" --name "$title" --image "$id"
# NEW sbotc publish to oasis
2020-05-14 03:06:54 +02:00
sbotc publish " {\"type\":\"about\",\"about\":\" $ssbpub \",\"description\":\"![QRCode]( $qrid )\\n[Astroport #Swarm0 DEV Station](https://astroport.com)\\n - [Gchange](http:// $nodename /gchange/#/app/wot/ $g1pub ) \\n - [Cesium - $myJune -](https:// $nodename /cesium/#/app/wot/ $g1pub /) \\n IPFS NODE ID : [ $ipfsnodeid ](http://localhost:8080/ipns/ $ipfsnodeid ) \\n DISK: $sizeAvail = $diskperf \\n - [LOVE Land entrance](http:// $nodename /) \\n\",\"name\":\" $title \",\"image\":\" $id \"} "
2020-05-14 03:02:46 +02:00
2020-05-10 06:30:06 +02:00
# SSB PUBLISH G1 wallet silkaj balance
2020-05-11 05:22:57 +02:00
json_escape ( ) {
printf '%s' " $1 " | python -c 'import json,sys; print(json.dumps(sys.stdin.read()))'
}
INLINE = $( json_escape " $g1balance " )
2020-05-14 02:59:13 +02:00
# TODO FIND WHY THIS ***** COMA , IS EVERYWHERE NOT PUBLSHING silkaj
2020-05-14 00:47:30 +02:00
# [[ $INLINE ]] && sbotc publish '{"type":"post","text":'$INLINE'}'
2020-04-28 14:27:25 +02:00
2020-05-11 05:22:57 +02:00
#INLINE="${g1balance@Q}"
#[[ $INLINE ]] && sbotc publish '{"type":"post","text":"'$INLINE'"}'
2020-03-22 04:45:20 +01:00
echo "
2020-03-24 20:53:44 +01:00
_ _
/ \| _) _ _ _| _
2020-04-28 04:00:17 +02:00
\_ X| \ ( _( _) ( _| ( /_ ! AVATAR
2020-03-22 04:45:20 +01:00
2020-04-28 14:27:25 +02:00
$g1balance
2020-03-24 01:20:10 +01:00
2020-03-24 20:53:44 +01:00
~/.zen/ipfs/.$ipfsnodeid /G1SSB/_g1.qrcode.png
2020-03-24 03:10:28 +01:00
2020-03-24 20:53:44 +01:00
-- sbotc publish --
"
2020-04-28 14:27:25 +02:00
# IF no AVATAR, publish message with QRCode
2020-05-11 04:30:10 +02:00
if [ [ ! $( file "/tmp/_g1.avatar.png" | grep 'PNG' ) ] ] ; then
2020-05-14 02:59:13 +02:00
sleep 1
2020-05-14 00:47:30 +02:00
# sbotc publish '{"type":"post","text":"![QRCode]('"$qrid"')\n Scan QRCode with [Cesium](https://cesium.app).\n Thank you\n ONE :heart:","mentions":[{"link":"'"$id"'","name":"'"$name"'","size":'"$size"',"type":"'"$type"'"}]}'
2020-05-10 03:51:50 +02:00
else
2020-05-11 04:38:36 +02:00
# Publish only if new avatar
if [ [ $( diff /tmp/_g1.avatar.png ~/.zen/ipfs/.$ipfsnodeid /G1SSB/_g1.avatar.png) ] ] ; then
sbotc publish '{"type":"post","text":"![Cesium Avatar](' " $id " ')\n from my Wallet [Cesium](https://demo.cesium.app/#/app/wot/' " $g1pub " ') ' " $g1pub " '","mentions":[{"link":"' " $id " '","name":"' " $name " '","size":' " $size " ',"type":"' " $type " '"}]}'
fi
2020-05-10 03:51:50 +02:00
fi
2020-03-22 04:45:20 +01:00
2020-03-24 20:53:44 +01:00
echo "
2020-03-22 04:45:20 +01:00
2020-03-24 20:53:44 +01:00
___ _ _ __
| | _) | _( _ _. _| _|
2020-03-26 03:20:04 +01:00
_| _| | __) ( _| ( _| ( _|
~/.zen/ipfs
2020-03-22 04:45:20 +01:00
2020-05-11 04:20:30 +02:00
ipfs ls /ipns/$ipfsnodeid
2020-03-24 20:53:44 +01:00
"
# COPY NODE G1SSB ID to IPFS
echo " $ssbpub " > ~/.zen/ipfs/.$ipfsnodeid /G1SSB/_ssb.whoami
echo " $g1pub " > ~/.zen/ipfs/.$ipfsnodeid /G1SSB/_g1.pubkey
2020-04-27 22:57:41 +02:00
# 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
ipfs id | jq -r .Addresses[ ] | tail -n 1 > ~/.zen/ipfs/.${ ipfsnodeid } /tryme.addr
2020-03-24 20:53:44 +01:00
IWALLETS = $( ipfs add -rHq ~/.zen/ipfs | tail -n 1)
NODEIPNS = $( ipfs name publish --allow-offline --quieter /ipfs/$IWALLETS )
echo "
2020-05-11 04:20:30 +02:00
ipfs ls /ipns/$ipfsnodeid /.$ipfsnodeid /
2020-03-24 01:20:10 +01:00
_ _ _ _ _
( _) _ ____ _( _) | _ __ _| | _( _) ___ _ __
| | _ \ \ / / | __/ _| | __| | / _ \| _ \
| | | | \ V /| | || ( _| | | _| | ( _) | | | |
| _| _| | _| \_ / | _| \_ _\_ _| _| \_ _| _| \_ __/| _| | _|
2020-03-22 04:45:20 +01:00
2020-04-18 03:52:08 +02:00
# This INVITE is to be sent an to 'Astroport Station' willing to Join our IPFS Swarm.
2020-03-24 20:53:44 +01:00
# see 'ssb_SURVEY_contact.sh' for commands executed...
2020-03-29 16:15:39 +02:00
2020-03-22 04:45:20 +01:00
"
2020-05-11 02:22:36 +02:00
echo "INVITATION LINK (only works in LAN or WAN depending on your Node)"
2020-05-11 02:28:23 +02:00
sbotc invite.create 1 2>/dev/null
2020-05-11 02:26:53 +02:00
2020-05-11 02:22:36 +02:00
#read ssb_invit_link
#sbotc invite.accept $ssb_invit_link
2020-03-29 16:15:39 +02:00
exit 0