astrXbian/zen/ipns_TAG_refresh.sh

213 lines
11 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 --timeout=5s 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)
########################################################################
########################################################################
# ACTIVATE TO CONTROL SWARM STATION SAME CODE VERSION
########################################################################
## myCODE is a SECURITY about code SIMILARITY
## 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
# [[ "$G1PUB" == "Ee1n3hDv9vunfd6m3LW6XeYg7bnt5aaRn9EjqnBe8GNS" ]] && ipfs name publish -k mastodon $(cat ~/.zen/ipfs/.${IPFSNODEID}/.mycode)
# echo "MyCODE = $MyCODE CODE is published
# ipfs ls /ipns/k51qzi5uqu5dk1nt1pfbtgfis4bep8pcip78w30xykhgba7y7wk0xyu8nwci5m"
########################################################################
# ACTIVATE TO CONTROL SWARM STATION SAME CODE VERSION
########################################################################
echo "
_ _ _ _
/ \ / \ / \ / \
( I | P | N | S )
\_/ \_/ \_/ \_/
ZENTAG / MEDIAKEY : IPNS REFRESH
"
echo "I am /ipns/$IPFSNODEID controling and refreshing my MEDIAKEY IPNS"
########################################################################
# REFRESH IPNS SELF PUBLISH
########################################################################
~/.zen/astrXbian/zen/ipns_self_publish.sh
########################################################################
count=0
[[ ! -d ~/.zen/ipfs/.${IPFSNODEID}/KEY/ ]] && exit 0
## TAKE CARE OF MY KEY
for id in $(ls ~/.zen/ipfs/.${IPFSNODEID}/KEY/); # Alternative search
do
count=$((count+1)) && echo "$count) "
IPNSLINK=$(ipfs key list -l | grep ${id} | cut -d ' ' -f 1)
FILE_NAME=$(cat ~/.zen/ipfs/.${IPFSNODEID}/KEY/${id}/${G1PUB}/.ipfs.filename)
TITLE=$(cat ~/.zen/ipfs/.${IPFSNODEID}/KEY/${id}/${G1PUB}/.title)
source=$(echo $id | cut -d '_' -f 1)
ANNONCE=$(cat ~/.zen/ipfs/.${IPFSNODEID}/KEY/${id}/${G1PUB}/.gchange.ad)
## CRYPTO EXAMPLE, use natools to decrypt (could also verify signature)
[[ -f ~/.zen/ipfs/.${IPFSNODEID}/KEY/${id}/${G1PUB}/.ipfs.filelink.natools.encrypt ]] && $MY_PATH/tools/natools.py decrypt -f pubsec -k "$HOME/.zen/secret.dunikey" -i "$HOME/.zen/ipfs/.${IPFSNODEID}/KEY/${id}/${G1PUB}/.ipfs.filelink.natools.encrypt" -o "/tmp/${id}_filelink.txt"
# file=$(cat /tmp/${id}_filelink.txt | rev | cut -d '/' -f 1 | rev)
IPFSTUBELINK="https://tube.copylaradio.com$(cat /tmp/${id}_filelink.txt)"
MIMETYPE="video/${IPFSTUBELINK##*.}"
[[ "$MIMETYPE" == "video/avi" ]] && MIMETYPE="video/x-msvideo"
### IPNS LINK CAN EVOLVE (REFRESH EVERY 12 H TO MAINTAIN ALIVE IN THE SWARM)
echo "<meta charset=\"UTF-8\"><meta http-equiv=\"Refresh\" content=\"10;URL=https://tube.copylaradio.com/ipns/$IPNSLINK/${G1PUB}/\">
<h1><a href='https://astroport.com'>ASTROPORT</a>/KODI</h1>
<a href=\"$IPFSTUBELINK\">LECTURE immédiate</a>! Lancement de la video dans 10 secondes ...<br>
Apprenez à programmer le BLOB et ajoutez de nouveaux services au Datacenter Virtuel LIBRE...<br>
<h2>Essayez <a href='https://copylaradio.com'>astrXbian</a> le video-club Libre entre amis</h2>
<br><br>Portefeuille du media (${id}) : <a href=\"https://www.gchange.fr/#/app/user/${G1PUB}/\">
<img width=40 src=\"https://tube.copylaradio.com/ipns/$IPNSLINK/QR.png\"></a>" > ~/.zen/ipfs/.${IPFSNODEID}/KEY/${id}/index.html
########################################################################
### ACTIVATE & EXECUTE HERE YOUR OWN SCENARIO
# ~/.zen/ipfs/.${IPFSNODEID}/KEY/${INDEXPREFIX}${REFERENCE}/${G1PUB}/index.html
########################################################################
# FRANCE COPIE PRIVEE - clear ipfs link no tracking
## Write KEY id (provide verification)
[[ ! -f ~/.zen/ipfs/.${IPFSNODEID}/KEY/${id}/${G1PUB}/.id ]] && echo ${id} > ~/.zen/ipfs/.${IPFSNODEID}/KEY/${id}/${G1PUB}/.id
## LOCALHOST ASTROPORT STATION PAGE
# echo "<meta charset=\"UTF-8\"><meta http-equiv=\"Refresh\" content=\"0;URL=http://127.0.0.1:8181$(cat /tmp/${id}_filelink.txt)\">" > ~/.zen/ipfs/.${IPFSNODEID}/KEY/${id}/${G1PUB}/index.html
# echo "<meta charset=\"UTF-8\"><meta http-equiv=\"Refresh\" content=\"0;URL=https://tube.copylaradio.com$(cat /tmp/${id}_filelink.txt)\">" > ~/.zen/ipfs/.${IPFSNODEID}/KEY/${id}/${G1PUB}/index.html
## NICE FINAL STREAMING PAGE
echo "<!DOCTYPE html>
<html>
<head>
<title>AstroCrowdBuster</title>
<meta charset=\"UTF-8\">
<link rel='stylesheet' href='crowdbunker.css' type='text/css' />
<link rel='icon' type='image/png' href='/astrocrowdbunker.png' />
</head>
<body>
<header>
<h6>
<a href='https://copylaradio.com'><span>Astroport</span> × <span>astrXbian DEMO</span></a>
</h6>
</header>
<main>
<article>
<video autoplay='autoplay' controls><source src=\"$IPFSTUBELINK\" type=\"$MIMETYPE\"></video>
<h1 class='video-title'>$TITLE</h1>
</article>
</main>
<center><br>Faites un don pour connserver la MEDIAKEY (${id}) en ligne<br>
<br><img width=40 src=\"https://tube.copylaradio.com/ipns/$IPNSLINK/QR.png\"></center>
</body>
</html>" > ~/.zen/ipfs/.${IPFSNODEID}/KEY/${id}/${G1PUB}/index.html
if [[ "$source" == "YOUTUBE" ]]
then
echo "$source"
# mutiTUBE - activate .views.counter
# echo "<meta http-equiv=\"Refresh\" content=\"0;URL=https://tube.copylaradio.com/ipns/$IPNSLINK/${G1PUB}/go\">" > ~/.zen/ipfs/.${IPFSNODEID}/KEY/${id}/${G1PUB}/index.html
# TODO go/index.php from nginx proxy acting act as gateway (= Easy Round robin DNS tube.copylaradio.com is dynamic IP swap swarm nodes from node performance...)
fi
# ln -s /$HOME/.zen/astrXbian/www /var/www/astrxbian
# Testez vos application à même la blockchain en la copiant dans ~/.zen/ipfs/.${IPFSNODEID}/KEY/${id}/${G1PUB}/go/
# Proposez de l'ajouter au dépot des applications web2.0 dans ../www/
########################################################################
# EXAMPLE TO ACTIVATE SECURITY : FORCE SIGNATURE VERIFICATION for each sensible file
########################################################################
echo "~/.zen/ipfs/.${IPFSNODEID}/KEY/${id}/${G1PUB}/.views.counter"
if [[ ! -f ~/.zen/ipfs/.${IPFSNODEID}/KEY/${id}/${G1PUB}/.views.counter.sign ]]; then
echo "0" > ~/.zen/ipfs/.${IPFSNODEID}/KEY/${id}/${G1PUB}/.views.counter
$MY_PATH/tools/natools.py sign -f pubsec -k "$HOME/.zen/secret.dunikey" -i ~/.zen/ipfs/.${IPFSNODEID}/KEY/${id}/${G1PUB}/.views.counter -o ~/.zen/ipfs/.${IPFSNODEID}/KEY/${id}/${G1PUB}/.views.counter.sign
fi
$MY_PATH/tools/natools.py verify -p "${G1PUB}" -i "$HOME/.zen/ipfs/.${IPFSNODEID}/KEY/${id}/${G1PUB}/.views.counter.sign" -o "/tmp/verified_msg" && echo "c'est bon" || echo "c'est pas bon"
# Each time a station modify .views.counter it signs, log and timestamp then publish new IPNS to swarm.
# If a "faulty" blockchain appears (Mediakey collision)...
# Message are sent to warn friends they have to manualy validate data conflict and merge back their mutual chain.
########################################################################
########################################################################
# ipfs nanochain progression
I=$(ipfs add -qrH ~/.zen/ipfs/.${IPFSNODEID}/KEY/${id}/ | tail -n 1)
OLDCHAIN=$(cat ~/.zen/ipfs/.${IPFSNODEID}/KEY/${id}/.chain)
if [[ "$OLDCHAIN" != "$I" ]] # MODIFY CHAIN only if something was changed
then
echo "$(date -u +%s%N | cut -b1-13)" > ~/.zen/ipfs/.${IPFSNODEID}/KEY/${id}/.timestamp
echo $I > ~/.zen/ipfs/.${IPFSNODEID}/KEY/${id}/.chain
fi
# KEY ZenTag IPNS name publish
J=$(ipfs name publish -k ${id} --quieter /ipfs/${I})
echo "$id REFRESHED https://tube.copylaradio.com/ipns/$J"
########################################################################
########################################################################
done
########################################################################
########################################################################
## TAKE CARE OF PIN CREATED THROUGH autoPINfriends.sh
## Then refresh MEDIAKEY IPNS/IPFS RELATION
## CORRECT ISSUE : https://git.p2p.legal/axiom-team/astrXbian/issues/25
########################################################################
for ipnslink in $(ls ~/.zen/PIN/*/IPNSLINK);
ipnsid=$(cat $ipnslink)
ipfsid=$(echo $ipnslink | cut -d '/' -f 6)
mediakey=$(cat~/.zen/PIN/${ipfsid}/MEDIAKEY)
[[ ! $(ipfs key list | grep ${mediakey}) ]] && echo "ERROR MISSING MEDIAKEY" && continue
## GET ACTUAL IPNS .chain VALUE
actual=$(ipfs cat /ipns/$ipnsid/.chain)
## PUBLISH IT
ipfs name publish -k ${mediakey} --quieter /ipfs/${actual}
echo "REFRESHED https://tube.copylaradio.com/ipns/$ipnsid TO /ipfs/$actual"
done
########################################################################
########################################################################
########################################################################
# ACTIVATION MONNAIES LIBRES EQUIBIBREES
# En relatif M/N :
# 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)
# Chaque joueur démarre à 100 LOVE au début du JEu. DU = 100 LOVE.
# Le compteur de DU de chacun converge chaque jour vers 100 LOVE (prélevant au fort pour redistribuer aux faibles)
# amortis temporellement par C² (adapté à la durée de vie moyenne des joueurs de chaque essaim !!).
# Cela ressemble à circuit résonant (RLC) amortis par la durée de vie?!
# https://forum.monnaie-libre.fr/t/etude-commencer-a-la-moyenne/15231/34?u=qoop
# https://forum.monnaie-libre.fr/t/formules-en-referentiel-du-et-m-n/10417