astrXbian/zen/ipns_TAG_refresh.sh

259 lines
14 KiB
Bash
Raw Normal View History

2020-12-12 01:26:39 +01:00
#!/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
########################################################################
2021-07-10 14:04:16 +02:00
IPFSNODEID=$(ipfs --timeout=20s id -f='<id>\n')
[[ ! $IPFSNODEID ]] && echo 'ERROR missing IPFS Node id !! IPFS is not installed !?' && exit 1
2020-12-12 01:26:39 +01:00
########################################################################
[[ ! -f ~/.zen/secret.dunikey ]] && exit 1
G1PUB=$(cat ~/.zen/secret.dunikey | grep 'pub:' | cut -d ' ' -f 2)
2020-12-12 01:26:39 +01:00
########################################################################
2021-08-06 15:08:26 +02:00
echo "## FRIENDS IPFS PINGing"
for g1pub in $(ls -t ~/.zen/ipfs/.$IPFSNODEID/FRIENDS/); do [[ $g1pub ]] && ipfs ping --timeout=3s -n 3 /ipfs/$(~/.zen/astrXbian/zen/tools/g1_to_ipfs.py $g1pub 2>/dev/null) 2>/dev/null; done
2021-06-16 00:37:09 +02:00
2021-06-15 20:23:07 +02:00
echo "
2021-08-06 15:08:26 +02:00
_ _ _ _
/ \ / \ / \ / \
2020-12-12 01:26:39 +01:00
( I | P | N | S )
2021-08-06 15:08:26 +02:00
\_/ \_/ \_/ \_/
2020-12-12 01:26:39 +01:00
2021-08-06 15:08:26 +02:00
ZENTAG / MEDIAKEY : IPNS REFRESH
2021-03-02 18:56:33 +01:00
"
2021-03-31 01:19:41 +02:00
echo "I am /ipns/$IPFSNODEID controling and refreshing my MEDIAKEY IPNS"
########################################################################
# REFRESH IPNS SELF PUBLISH
########################################################################
~/.zen/astrXbian/zen/ipns_self_publish.sh
########################################################################
2020-12-12 01:26:39 +01:00
count=0
2021-03-17 18:17:42 +01:00
[[ ! -d ~/.zen/ipfs/.${IPFSNODEID}/KEY/ ]] && exit 0
2020-12-12 01:26:39 +01:00
## TAKE CARE OF MY KEY
2021-06-17 22:38:04 +02:00
for mediakey in $(ls ~/.zen/ipfs/.${IPFSNODEID}/KEY/); # Alternative search
2020-12-12 01:26:39 +01:00
do
2021-08-06 15:08:26 +02:00
[[ "${mediakey}" == "" ]] && continue ## prevent empty mediakey
[[ ! $(echo "${mediakey}" | grep "TMDB_") ]] && continue ## REFRESH ONLY TMDB (level 1), youtube is level 0
2021-08-06 15:08:26 +02:00
IPNSLINK=$(ipfs key list -l | grep ${mediakey} | cut -d ' ' -f 1)
[[ "${IPNSLINK}" == "" ]] && continue ## prevent empty IPNSLINK
2021-03-31 01:19:41 +02:00
count=$((count+1)) && echo "$count) "
2021-08-06 15:08:26 +02:00
FILE_NAME=$(cat ~/.zen/ipfs/.${IPFSNODEID}/KEY/${mediakey}/${G1PUB}/.ipfs.filename)
TITLE=$(cat ~/.zen/ipfs/.${IPFSNODEID}/KEY/${mediakey}/${G1PUB}/.title)
2021-08-06 15:08:26 +02:00
source=$(echo $mediakey | cut -d '_' -f 1)
ANNONCE=$(cat ~/.zen/ipfs/.${IPFSNODEID}/KEY/${mediakey}/${G1PUB}/.gchange.ad)
## Use natools to decrypt "/tmp/${mediakey}_filelink.txt
[[ -f ~/.zen/ipfs/.${IPFSNODEID}/KEY/${mediakey}/${G1PUB}/.ipfs.filelink.natools.encrypt ]] && $MY_PATH/tools/natools.py decrypt -f pubsec -k "$HOME/.zen/secret.dunikey" -i "$HOME/.zen/ipfs/.${IPFSNODEID}/KEY/${mediakey}/${G1PUB}/.ipfs.filelink.natools.encrypt" -o "/tmp/${mediakey}_filelink.txt"
# file=$(cat /tmp/${mediakey}_filelink.txt | rev | cut -d '/' -f 1 | rev)
## TREAT OLD DATA from new_file_in_astroport.sh (LATER can be removed)
2021-07-11 00:02:52 +02:00
if [[ ! -f $HOME/.zen/ipfs/.${IPFSNODEID}/KEY/${mediakey}/MEDIAPUBKEY ]]; then
2021-08-06 15:08:26 +02:00
mediakeyfile=$($MY_PATH/tools/give_me_keystore_filename.py $mediakey)
2021-07-11 00:02:52 +02:00
$MY_PATH/tools/natools.py privkey -f ipfs-keystore -k $HOME/.ipfs/keystore/$mediakeyfile -F pubsec -o /tmp/${mediakey}.dunikey
# PubFromDunikey=$(cat /tmp/${mediakey}.dunikey | grep "sec" | cut -d ' ' -f2 | base58 -d | tail -c+33 | base58)
PubFromDunikey=$(cat /tmp/${mediakey}.dunikey | grep "pub" | cut -d ' ' -f2)
2021-08-06 15:08:26 +02:00
echo "$PubFromDunikey" > $HOME/.zen/ipfs/.${IPFSNODEID}/KEY/${mediakey}/MEDIAPUBKEY
fi
MEDIAPUBKEY=$(cat $HOME/.zen/ipfs/.${IPFSNODEID}/KEY/${mediakey}/MEDIAPUBKEY)
echo "MEDIA G1 WALLET = $MEDIAPUBKEY"
BALANCE=$(~/.zen/astrXbian/zen/jaklis/jaklis.py balance -p ${MEDIAPUBKEY}) && [[ $BALANCE == null || "$BALANCE" == "" ]] && BALANCE=0
2021-08-06 15:08:26 +02:00
ZENBALANCE=$(echo "100 * $BALANCE" | bc -l | cut -d '.' -f 1)
TUBELINK="https://tube.copylaradio.com$(cat /tmp/${mediakey}_filelink.txt)"
LOCALTUBELINK="http://127.0.0.1:8181$(cat /tmp/${mediakey}_filelink.txt)"
### IPNS LINK CAN EVOLVE (REFRESH EVERY 12 H TO MAINTAIN ALIVE IN THE SWARM) # TODO : Use templating
### This index.html is ipns link root, 1st welcome page for MEDIAKEY -> *** Redirect to CONTRACTS processing HERE ***
echo "<!DOCTYPE html>
<html>
<head>
2021-08-06 15:08:26 +02:00
<title>$TITLE in Astroport</title>
<meta charset=\"UTF-8\">
2021-08-11 06:12:43 +02:00
<link rel='stylesheet' href='/ipfs/QmPC5MTqt4do7emMUV4z7feYbjSGoX4kdDYVKB6jU3rEKk/crowdbunker.css' type='text/css' />
2021-08-11 06:33:37 +02:00
<link rel='icon' type='image/png' href='/ipfs/QmPn3KpF4vNSkdXdk3eiWUVfNoUiCYfiGWxG1Zh9asjhKs/astrocrowdbunker.png' />
2021-08-10 14:36:35 +02:00
<script type='text/javascript' src='/g1scan_fichiers/adapter.js'></script>
<script type='text/javascript' src='/g1scan_fichiers/vue.js'></script>
2021-08-11 06:33:37 +02:00
<script type='text/javascript' src='/ipfs/QmcmuVxnsxpupW5Es7ipgdK6KrG8SCgqFXMKeaBsHyJQct/instascan.js'></script>
</head>
<body>
<header>
2021-08-06 15:08:26 +02:00
<h6>
2021-08-11 06:28:47 +02:00
<a href='https://astroport.com'><span>ASTROPORT</span> × <span> ${mediakey}</span></a>
2021-08-06 15:08:26 +02:00
</h6>
</header>
<main>
<article><h2>$TITLE</h2>
<div class='preview-container'>
<video id='preview' autoplay='autoplay' style='transform: scaleX(-1);' class='active'></video>
</div>
2021-08-11 20:06:18 +02:00
<br>Recevez de la JUNE. Scannez le QRCODE d'un simple G1 portefeuille (<a href='https://cesium.app'>Votre portefeuille est GRATUIT</a>)<br>
2021-08-11 06:26:14 +02:00
<h1 class='video-title'><a href='https://tube.copylaradio.com/ipns/$IPNSLINK/${G1PUB}/'>Cliquez ici pour lancer la lecture streaming de cette vidéo</a></h1>
</article>
</main>
2021-08-11 20:06:18 +02:00
<center><br>Astroport Video Club & Datacenter décentralisé. P2P Libre & Légal.<br>
<br>Voici le lien Gchange de la Station qui a ajouté ce média. Un DON = Merci
<br><a target='tube' href=\"https://www.gchange.fr/#/app/user/${G1PUB}/\"><img src=\"https://g1sms.fr/g1barre/image.php?pubkey=${G1PUB}&target=1000&title=Un%20DON%20Merci%20$XZUID&node=g1.duniter.org&start_date=2021-06-21&display_pubkey=true&display_qrcode=true&progress_color=ff07a4\"></a></center>
2021-08-10 03:03:11 +02:00
<script type='text/javascript' src='/g1scan_fichiers/app.js'></script>
</body>
2021-06-17 22:38:04 +02:00
</html>" > ~/.zen/ipfs/.${IPFSNODEID}/KEY/${mediakey}/index.html
2021-03-01 01:53:42 +01:00
2021-03-18 02:24:41 +01:00
########################################################################
2021-06-16 01:06:01 +02:00
### Scenario are G1PUB subdivized. Thus each friend can establish own contract
2021-03-18 02:24:41 +01:00
# ~/.zen/ipfs/.${IPFSNODEID}/KEY/${INDEXPREFIX}${REFERENCE}/${G1PUB}/index.html
########################################################################
2021-06-16 01:06:01 +02:00
2021-08-06 15:08:26 +02:00
## Write KEY id (provide verification)
[[ ! -f ~/.zen/ipfs/.${IPFSNODEID}/KEY/${mediakey}/${G1PUB}/.id ]] && echo ${mediakey} > ~/.zen/ipfs/.${IPFSNODEID}/KEY/${mediakey}/${G1PUB}/.id
2021-06-16 01:06:01 +02:00
## THIS MAKES FRENCH COPY RIGHT LAW RESPECT
## LOCALHOST REDIRECT FOR INTERNAL KODI DEFCON 3 (swarm.key) ASTROPORT STATION MODE
2021-08-06 15:08:26 +02:00
# echo "<meta charset=\"UTF-8\"><meta http-equiv=\"Refresh\" content=\"0;URL=http://127.0.0.1:8181$(cat /tmp/${mediakey}_filelink.txt)\">" > ~/.zen/ipfs/.${IPFSNODEID}/KEY/${mediakey}/${G1PUB}/index.html
# echo "<meta charset=\"UTF-8\"><meta http-equiv=\"Refresh\" content=\"0;URL=https://tube.copylaradio.com$(cat /tmp/${mediakey}_filelink.txt)\">" > ~/.zen/ipfs/.${IPFSNODEID}/KEY/${mediakey}/${G1PUB}/index.html
2021-06-15 20:16:52 +02:00
2021-06-16 01:06:01 +02:00
## DEMO PERIOD
2021-07-01 00:47:13 +02:00
## NICE FINAL STREAMING PAGE # TODO ACTIVATE DOWNLOAD FOR AVI or MKV
2021-08-06 15:08:26 +02:00
FILETYPE="${LOCALTUBELINK##*.}"
MIMETYPE="video/$FILETYPE" && HTMLTAG="video"
[[ "$FILETYPE" == "avi" ]] && MIMETYPE="video/x-msvideo"
[[ "$FILETYPE" == "mkv" ]] && MIMETYPE="video/x-matroska"
[[ "$FILETYPE" == "mp3" ]] && MIMETYPE="audio/mpeg" && HTMLTAG="audio"
echo "<!DOCTYPE html>
2021-06-15 20:16:52 +02:00
<html>
<head>
2021-08-11 00:08:27 +02:00
<title>$TITLE in Astroport served by $G1PUB</title>
2021-08-06 15:08:26 +02:00
<meta charset=\"UTF-8\">
2021-08-11 06:33:37 +02:00
<link rel='stylesheet' href='/ipfs/QmPC5MTqt4do7emMUV4z7feYbjSGoX4kdDYVKB6jU3rEKk/crowdbunker.css' type='text/css' />
<link rel='icon' type='image/png' href='/ipfs/QmPn3KpF4vNSkdXdk3eiWUVfNoUiCYfiGWxG1Zh9asjhKs/astrocrowdbunker.png' />
2021-06-15 20:16:52 +02:00
</head>
<body>
<header>
2021-08-06 15:08:26 +02:00
<h5>
<a href=\"https://copylaradio.com\"><span>CopyLaRadio : Joignez vous aux %MAKER de Stations Astroport</span></a>
2021-08-06 15:08:26 +02:00
</h5>
<h6>
2021-08-06 15:08:26 +02:00
<a href='https://www.gchange.fr/#/app/market/lg?q=astroport'><span>astrXbian</span> × <span> en DEMO sur Gchange</span></a>
</h6>
2021-06-15 20:16:52 +02:00
</header>
<main>
<article>
2021-08-06 15:08:26 +02:00
<$HTMLTAG controls>
<source src=\"$TUBELINK\" type=\"$MIMETYPE\">
</$HTMLTAG>
<h1 class='video-title'><a href=\"$LOCALTUBELINK\">$TITLE $MIMETYPE (Conservez OFFLINE)</a></h1>
2021-08-11 07:40:59 +02:00
<h1 class='video-title'><a target='copylaradio' href='https://www.copylaradio.com/forum/traductions-4/question/expliquer-ipfs-en-francais-35''>Aidez nous à traduire, publier la documentation Astroport/IPFS</a> ?</h1>
2021-06-15 20:16:52 +02:00
</article>
</main>
<center><br>Ce media possède un G1 portefeuille avec lequel il paye son hébergement.
<br>Voici les dons reçus par (${mediakey}). Ce média vous plait? Flashez ce QRCode.<br>
2021-06-16 00:37:09 +02:00
<br>
2021-07-06 17:59:09 +02:00
<br><img src=\"https://g1sms.fr/g1barre/image.php?pubkey=${MEDIAPUBKEY}&target=1000&title=DONS%20${mediakey}&node=g1.duniter.org&start_date=2021-06-21&display_pubkey=true&display_qrcode=true&progress_color=ff07a4\">
2021-07-01 17:48:31 +02:00
<br><img width=222 src=\"https://tube.copylaradio.com/ipns/$IPNSLINK/QR.png\"><br>${MEDIAPUBKEY} = ${ZENBALANCE} ZEN
<br><br>Le Zen est un Token de la G1 (1G1 = 100ZEN)</center>
2021-06-15 20:16:52 +02:00
</body>
2021-06-17 22:38:04 +02:00
</html>" > ~/.zen/ipfs/.${IPFSNODEID}/KEY/${mediakey}/${G1PUB}/index.html
2021-08-06 15:08:26 +02:00
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/${mediakey}/${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/${mediakey}/${G1PUB}/go/
# Proposez de l'ajouter au dépot des applications web2.0 dans ../www/
2021-03-31 01:19:41 +02:00
2021-06-15 20:23:07 +02:00
########################################################################
2021-08-06 15:08:26 +02:00
# EXAMPLE TO ACTIVATE SECURITY : FORCE SIGNATURE VERIFICATION for each sensible file
2021-06-15 20:23:07 +02:00
########################################################################
2021-08-06 15:08:26 +02:00
echo "~/.zen/ipfs/.${IPFSNODEID}/KEY/${mediakey}/${G1PUB}/.views.counter"
if [[ ! -f ~/.zen/ipfs/.${IPFSNODEID}/KEY/${mediakey}/${G1PUB}/.views.counter.sign ]]; then
echo "0" > ~/.zen/ipfs/.${IPFSNODEID}/KEY/${mediakey}/${G1PUB}/.views.counter
$MY_PATH/tools/natools.py sign -f pubsec -k "$HOME/.zen/secret.dunikey" -i ~/.zen/ipfs/.${IPFSNODEID}/KEY/${mediakey}/${G1PUB}/.views.counter -o ~/.zen/ipfs/.${IPFSNODEID}/KEY/${mediakey}/${G1PUB}/.views.counter.sign
fi
2021-06-15 20:23:07 +02:00
2021-08-06 15:08:26 +02:00
$MY_PATH/tools/natools.py verify -p "${G1PUB}" -i "$HOME/.zen/ipfs/.${IPFSNODEID}/KEY/${mediakey}/${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.
2021-06-15 20:23:07 +02:00
########################################################################
2021-06-16 01:06:01 +02:00
## CHAIN & IPNS REFRESH
2021-06-15 20:23:07 +02:00
########################################################################
2021-08-06 15:08:26 +02:00
# ipfs nanochain progression
I=$(ipfs add -qrH ~/.zen/ipfs/.${IPFSNODEID}/KEY/${mediakey}/ | tail -n 1)
2021-06-21 00:41:21 +02:00
echo "CHAIN: $I"
2021-08-06 15:08:26 +02:00
OLDCHAIN=$(cat ~/.zen/ipfs/.${IPFSNODEID}/KEY/${mediakey}/.chain)
2021-06-21 00:41:21 +02:00
echo "OLDCHAIN: $OLDCHAIN"
2021-08-06 15:08:26 +02:00
if [[ "$OLDCHAIN" != "$I" ]] # MODIFY CHAIN only if something was changed
then
echo "UPDATING CHAIN"
echo "$(date -u +%s%N | cut -b1-13)" > ~/.zen/ipfs/.${IPFSNODEID}/KEY/${mediakey}/.timestamp
echo $I > ~/.zen/ipfs/.${IPFSNODEID}/KEY/${mediakey}/.chain
fi
echo "${mediakey} NAME PUBLISHING "
# KEY ZenTag IPNS name publish
2021-07-12 04:25:44 +02:00
J=$(ipfs name publish --quieter -k ${mediakey} /ipfs/${I})
2020-12-12 01:26:39 +01:00
echo "$id REFRESHED https://tube.copylaradio.com/ipns/$J"
2021-06-15 20:23:07 +02:00
########################################################################
########################################################################
2021-08-06 15:08:26 +02:00
2020-12-12 01:26:39 +01:00
done
2021-06-15 20:23:07 +02:00
########################################################################
########################################################################
## 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
2021-06-15 20:23:07 +02:00
########################################################################
for ipnslink in $(ls ~/.zen/PIN/*/IPNSLINK); do
ipnsid=$(cat $ipnslink)
ipfsid=$(echo $ipnslink | cut -d '/' -f 6)
mediakey=$(cat ~/.zen/PIN/${ipfsid}/MEDIAKEY)
2021-08-06 15:08:26 +02:00
[[ ! $(echo "${mediakey}" | grep "TMDB_") ]] && continue ## REFRESH ONLY TMDB (level 1), youtube is level 0
2021-06-29 03:08:47 +02:00
[[ ! $(ipfs key list | grep ${mediakey}) ]] && echo "ERROR MISSING MEDIAKEY" && continue
## GET ACTUAL IPNS .chain VALUE
mkdir -p /tmp/${mediakey}
echo "${mediakey} GET IPNS"
ipfs get -o /tmp/${mediakey} /ipns/$ipnsid
[ $? -ne 0 ] && continue
echo "ADD TO IPFS"
NEWIPFS=$(ipfs add -rHq /tmp/${mediakey}/ | tail -n 1)
## PUBLISH IT
ipfs name publish -k ${mediakey} --quieter /ipfs/$NEWIPFS
echo "ECHO PUBLISHING https://tube.copylaradio.com/ipns/$ipnsid TO /ipfs/$NEWIPFS"
2021-08-11 18:15:35 +02:00
rm -Rf /tmp/${mediakey}
done
2021-03-31 01:19:41 +02:00
2021-06-15 20:23:07 +02:00
########################################################################