#!/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' # SURVEY received #astroport-swarmkey ipfs_swarm.key.crypt for IPFS ######################################################################## ___DESACTIVATED___ TODO testing. __ __ _ _ (_ (_ |_) _ ._ _ _|_o| __)__)|_) _>|_||\/(/_\/ | ||(/__> / 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 } ' [[ -f ~/.ipfs/ipfs_swarm.key ]] && echo "SWARM KEY ~/.ipfs/ipfs_swarm.key OK !!!" && exit 0 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='\n') # 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 - 24*3600*1000 - 1)) # timestamp from 24h ago echo ' _ _ -|-|- _. __|_.__ ._ _ .__|___/ |\/|| \ -|-|-(_|_> |_|(_)|_)(_)| |_ \_| ||_/ | sbotc messagesByType "post" > $last_ts ' messages=$(sbotc messagesByType '{"type":"post","gt":'$last_ts'}') #messages=$(sbotc messagesByType '{"type":"post"}') #DEBUG while read -r msg do author=$(printf %s "$msg" | jq -r .value.author) attached_file=$(printf %s "$msg" | jq -r .value.content.mentions[].name 2>/dev/null) if [[ $attached_file == "ipfs_swarm.key.crypt" ]]; then echo ' __ _ _ (_\ //\ |_)|\/| |/|_\_/ _._ .__|_ __)\/\//--\| \| | |\|_ | de(_|\/|_)|_ / | to ~/.ipfs/ipfs_swarm.key ' mylink=$(printf %s "$msg" | jq -r .value.content.mentions[].link) mytmp=$(mktemp -d "${TMPDIR:-/tmp}/astroport.swarmkey.XXXXXXXXX") echo "http://localhost:8989/blobs/get/$mylink" continue curl -s "http://localhost:8989/blobs/get/$mylink" > $mytmp/ipfs_swarm.key.crypt $MY_PATH/tools/natools.py decrypt -f pubsec -k ~/.ssb/secret.dunikey -i $mytmp/ipfs_swarm.key.crypt -o ~/.ipfs/ipfs_swarm.key && \ echo "IPFS SWARM KEY ~/.ipfs/ipfs_swarm.key received from SSB $author ... OK !" echo ' ___ _ _ __ | |_)|_(_ _| _. _ ._ _ _ ._ _|_| | __) (_|(_|(/_| | |(_)| | ... restart ... ' # TODO!!! Add user in sudo without password like "pi" = Run astroport under pi user IDEA. sudo systemctl restart ipfs fi done < <(printf '%s\n' "$messages")