astrXbian/zen/ipns_TAG_refresh.sh

97 lines
4.2 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. 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.04.28
# 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##*/}"
########################################################################
# \\///
# qo-op
############# '$MY_PATH/$ME'
########################################################################
# ex: ./'$ME'
# SYNC IPFS SWARM PEERS SHARED DATA .12D3KooW****
########################################################################'
########################################################################
# ENVIRONEMENT DETECTION + IPFS ~/.zen/ipfs/.$IPFSNODEID/G1SSB/_info
########################################################################
IPFSNODEID=$(ipfs id -f='<id>\n')
[[ $IPFSNODEID == "" ]] && echo "ERROR missing IPFS Node id !! IPFS is not installed !?" && exit 1
########################################################################
[[ ! -f ~/.zen/secret.dunikey ]] && exit 1
G1PUB=$(cat ~/.zen/secret.dunikey | grep 'pub:' | cut -d ' ' -f 2)
########################################################################
## CODE EXECUTION SECURITY EXAMPLE
## EACH NODE CAN CHECK IF ANOTHER HAS SAME IPFS CODE HASH
MyCODE=$(ipfs add -rq --ignore="__pycache__" ~/.zen/astrXbian/ | tail -n 1)
[[ ! -f ~/.zen/ipfs/.${IPFSNODEID}/.mycode ]] && echo $MyCODE > ~/.zen/ipfs/.${IPFSNODEID}/.mycode
[[ "$(cat ~/.zen/ipfs/.${IPFSNODEID}/.mycode)" != "$MyCODE" ]] && echo $MyCODE > ~/.zen/ipfs/.${IPFSNODEID}/.mycode
echo "
_ _ _ _
/ \ / \ / \ / \
( I | P | N | S )
\_/ \_/ \_/ \_/
ZENTAG KEY REFRESH
MyCODE = $MyCODE
"
echo "I am /ipns/$IPFSNODEID controling and refreshing my KEY ZenTag"
count=0
[[ ! -d ~/.zen/KEY/ ]] && exit 1
for id in $(ls ~/.zen/KEY/); # Alternative search
do
count=$((count+1))
IPNSLINK=$(ipfs key list -l | grep ${id} | cut -d ' ' -f 1)
FILE_NAME=$(cat ~/.zen/KEY/${id}/${G1PUB}/.ipfs.filename)
TITLE=$(cat ~/.zen/KEY/${id}/${G1PUB}/.title)
### IPNS LINK CAN EVOLVE (REFRESH EVERY 12 H TO MAINTAIN ALIVE IN THE SWARM)
echo "<meta http-equiv=\"Refresh\" content=\"10;URL=https://aries.copylaradio.com/ipns/$IPNSLINK/${G1PUB}/\">
<h1><a href='https://astroport.com'>ASTROPORT</a>/KODI</h1>
Pour consulter cette vidéo, rejoignez notre video-club et devenons amis...<br><br>
Installez <a href='https://copylaradio.com'>astrXbian</a><br>
<br><a href=\"https://www.gchange.fr/#/app/user/${G1PUB}/\"><img width=40 src=\"https://aries.copylaradio.com/ipns/${IPFSNODEID}/.${IPFSNODEID}/G1SSB/_g1.gchange_avatar.png\"></a>" > ~/.zen/KEY/${id}/index.html
### CHANGE FILE ACCESS
# echo "<meta http-equiv=\"Refresh\" content=\"0;URL=http://localhost:8181/ipfs/$IPFSREPFILEID/$URLENCODE_FILE_NAME\">" > ~/.zen/KEY/${INDEXPREFIX}${REFERENCE}/${G1PUB}/index.html
## DEBUG, decode natools to discover ipns link
[[ -f ~/.zen/KEY/${id}/${G1PUB}/.ipfs.filelink.natools.encrypt ]] && $MY_PATH/tools/natools.py decrypt -f pubsec -k "$HOME/.zen/secret.dunikey" -i "$HOME/.zen/KEY/${id}/${G1PUB}/.ipfs.filelink.natools.encrypt" -o "/tmp/filelink.txt" && cat /tmp/filelink.txt && rm /tmp/filelink.txt
## Write KEY id
[[ ! -f ~/.zen/KEY/${id}/${G1PUB}/.id ]] && echo ${id} > ~/.zen/KEY/${id}/${G1PUB}/.id
I=$(ipfs add -qrH ~/.zen/KEY/${id}/ | tail -n 1)
OLDCHAIN=$(cat ~/.zen/KEY/.chain)
if [[ "$OLDCHAIN" != "$I" ]] # MODIFY CHAIN only if something was changed
then
echo "$(date -u +%s%N | cut -b1-13)" > ~/.zen/KEY/.timestamp
echo $I > ~/.zen/KEY/.chain
fi
# KEY ZenTag IPNS name publish
J=$(ipfs name publish -k ${id} --quieter /ipfs/${I})
echo "$count) $id REFRESHED https://aries.copylaradio.com/ipns/$J"
done
# echo "Ajouter une ML en relatif DU :
# DU(t+1)=(DU+c²)/r
# S(t+1)=(S+DU)/r
# M(t+1)=N (et oui, si vous regardez les formules, on na pas besoin de M :slight_smile: On a donc pas besoin de stocker M !)
# r=(1+DU)*N/N(t+1) (diviser par r, cest multiplier par [N(t+1)/N]/(1+DU), qui prend en compte la variation de N)
# https://forum.monnaie-libre.fr/t/etude-commencer-a-la-moyenne/15231/34?u=qoop
# "