2020-03-25 14:26:40 +01:00
#!/bin/bash
########################################################################
# Author: Fred (support@qo-op.com)
# Version: 2020.03.24
# 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
############# '$MY_PATH/$ME'
########################################################################
# ex: ./'$ME'
2020-03-27 04:04:10 +01:00
# SURVEY received #astroport-swarmkey ipfs_swarm.key.crypt for IPFS
2020-03-29 05:57:04 +02:00
########################################################################
2020-03-27 04:15:32 +01:00
__ __ _ _
2020-03-29 05:57:04 +02:00
( _ ( _ | _) _ ._ _ _| _o|
__) __) | _) _>| _|| \/ ( /_\/ | || ( /__>
/
2020-03-27 04:15:32 +01:00
2020-03-27 04:04:10 +01:00
USED ONLY ONCE... Next swarm.key change will accurs in ~/.zen/ipfs-swarm
{
"key" : "%ydN2fyzKTKzVZiZJSxiTXbb17GVvu0ZOf7LPY6u3Bc8=.sha256" ,
"value" : {
"previous" : "%SM2J1D8RcWzd2/P6I3ATyN4VXHuQEP3sXy7YCtK0djE=.sha256" ,
"sequence" : 18,
"author" : "@t/giTDc0EtzdPQGC7iAAzgzVOkFo++XZRvzOOlqgX1c=.ed25519" ,
"timestamp" : 1585194822251,
"hash" : "sha256" ,
"content" : {
"type" : "post" ,
"text" : " #astroport-swarmkey = [ipfs_swarm.key.crypt](&L9nCidDjJ4c4Jz1LNTtx8Xp0SJW9HPCD9IVsbbAhS/I=.sha256) TO.SSB_ ${ author } TO.G1_ ${ g1author } +++ FROM.SSB_ ${ self_name } FROM.G1_ ${ g1self } FROM.IPFS_ ${ ipfsnodeid } " ,
"mentions" : [
{
"link" : "&L9nCidDjJ4c4Jz1LNTtx8Xp0SJW9HPCD9IVsbbAhS/I=.sha256" ,
"name" : "ipfs_swarm.key.crypt" ,
"size" : 144,
"type" : "application/octet-stream"
}
]
} ,
"signature" : "DHMTIS17yF450CqFssuP2iwYMMdOd3PzCDTkLYdjprTtvjWZYUEG9vHaXBrGuaFZRhV2gGZ3WSknM7YLevilAQ==.sig.ed25519"
} ,
"timestamp" : 1585194822367
}
2020-03-25 14:26:40 +01:00
'
2020-03-29 05:57:04 +02:00
2020-03-27 04:15:32 +01:00
[ [ -f ~/.ipfs/ipfs_swarm.key ] ] && echo "SWARM KEY ~/.ipfs/ipfs_swarm.key OK !!!" && exit 0
2020-03-25 14:26:40 +01:00
self = $( sbotc whoami | jq -r .id) || exit 1
g1self = $( echo $self | cut -d '@' -f 2 | cut -d '.' -f 1 | base64 -d | base58)
self_name = $( sbotc query.read '{"query":[{"$filter":{"value":{"author": "' " $self " '", "content":{"type":"about", "about": "' " $self " '"}}}}]}' | jq -r .value?.content?.name | grep -v null | tail -n 1)
ipfsnodeid = $( ipfs id -f= '<id>\n' )
2020-03-27 04:15:32 +01:00
2020-03-27 04:04:10 +01:00
# SEARCH "#astroport-swarmkey" CMD in message text
# Not working without patchwork (TODO: find bug. installation ok!? activate? ssb-server ssb-backlinks node_modules. HELP !! )
# messages=$(sbotc backlinks.read '{"query":[{"$filter":{"dest":"#astroport-swarmkey","value":{"content":{"type":"post"}}}}]}')
# The backlinks.read command does not publish a message, it queries the database for messages. It comes from the ssb-backlinks plugin. This plugin does not come with ssb-server by default (but it does come with Patchwork) so if you are using plain ssb-server and want to use ssb-backlinks you have to install it additionally. But to publish a message you would use the publish method (or private.publish to publish a private message, and that requires the ssb-private plugin, which is included in Patchwork but must be installed separately for ssb-server).
# SCRIPT RUN BY cron_MINUTE.sh check last hour messages
current_ts = $( date -u +%s%N | cut -b1-13)
last_ts = $(( current_ts - 3600000 )) # timestamp from 1h ago
#messages=$(sbotc messagesByType '{"type":"post","gt":'$last_ts'}')
echo '
_ _
-| -| - _. __| _.__ ._ _ .__| ___/ | \/ || \
-| -| -( _| _> | _| ( _) | _) ( _) | | _ \_ | || _/
|
sbotc messagesByType "post"
'
messages = $( sbotc messagesByType '{"type":"post"}' )
2020-03-25 14:26:40 +01:00
while read -r msg
do
2020-03-29 05:57:04 +02:00
2020-03-27 04:15:32 +01:00
author = $( printf %s " $msg " | jq -r .value.author)
attached_file = $( printf %s " $msg " | jq -r .value.content.mentions[ ] .name 2>/dev/null)
2020-03-27 04:04:10 +01:00
if [ [ $attached_file = = "ipfs_swarm.key.crypt" ] ] ; then
2020-03-29 05:57:04 +02:00
2020-03-27 04:04:10 +01:00
echo '
__ _ _
( _\ //\ | _) | \/ | | /| _\_ / _._ .__| _
__) \/ \/ /--\| \| | | \| _ | de( _| \/ | _) | _
/ |
to ~/.ipfs/ipfs_swarm.key
'
2020-03-29 05:57:04 +02:00
2020-03-27 04:48:16 +01:00
mylink = $( printf %s " $msg " | jq -r .value.content.mentions[ ] .link)
mytmp = $( mktemp -d " ${ TMPDIR :- /tmp } /astroport.swarmkey.XXXXXXXXX " )
2020-03-29 05:57:04 +02:00
echo " http://localhost:8989/blobs/get/ $mylink "
continue
2020-03-27 04:48:16 +01:00
curl -s " http://localhost:8989/blobs/get/ $mylink " > $mytmp /ipfs_swarm.key.crypt
$MY_PATH /tools/natools.py decrypt --pubsec -k ~/.ssb/secret.dunikey -i $mytmp /ipfs_swarm.key.crypt -o ~/.ipfs/ipfs_swarm.key && \
2020-03-27 04:15:32 +01:00
echo " IPFS SWARM KEY ~/.ipfs/ipfs_swarm.key received from SSB $author ... OK ! "
2020-03-29 05:57:04 +02:00
2020-03-27 04:04:10 +01:00
echo '
___ _ _ __
| | _) | _( _ _| _. _ ._ _ _ ._
_| _| | __) ( _| ( _| ( /_| | | ( _) | | ... restart ...
'
2020-03-29 05:57:04 +02:00
2020-03-27 04:04:10 +01:00
# TODO!!! Add user in sudo without password like "pi" = Run astroport under pi user IDEA.
sudo systemctl restart ipfs
2020-03-25 14:26:40 +01:00
2020-03-29 05:57:04 +02:00
2020-03-27 04:04:10 +01:00
fi
2020-03-25 14:26:40 +01:00
2020-03-29 05:57:04 +02:00
2020-03-25 14:26:40 +01:00
done < <( printf '%s\n' " $messages " )
2020-03-29 05:57:04 +02:00