Astroport.ONE/ASTROBOT/PLAYER.refresh.sh

213 lines
9.2 KiB
Bash
Raw Normal View History

2022-08-25 17:21:39 +02:00
#!/bin/bash
################################################################################
# Author: Fred (support@qo-op.com)
# Version: 0.1
# 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##*/}"
################################################################################
## Publish All PLAYER TW,
# Run TAG subprocess: tube, voeu
2022-08-25 17:21:39 +02:00
############################################
echo "## RUNNING PLAYER.refresh"
2022-08-25 17:21:39 +02:00
## RUNING FOR ALL LOCAL PLAYERS
2022-08-25 17:21:39 +02:00
for PLAYER in $(ls ~/.zen/game/players/); do
echo "##################################################################"
echo ">>>>> PLAYER : $PLAYER"
echo "##################################################################"
2022-09-12 19:53:55 +02:00
PSEUDO=$(cat ~/.zen/game/players/$PLAYER/.pseudo 2>/dev/null)
2022-08-25 17:21:39 +02:00
## REFRESH ASTRONAUTE TW
ASTRONAUTENS=$(ipfs key list -l | grep $PLAYER | cut -d ' ' -f1)
[[ ! $ASTRONAUTENS ]] && echo "Missing $PLAYER IPNS KEY -- CONTINUE --" && continue
2022-08-25 17:21:39 +02:00
rm -Rf ~/.zen/tmp/astro
mkdir -p ~/.zen/tmp/astro
# Get PLAYER wallet amount
BAL=$($MY_PATH/../tools/jaklis/jaklis.py -k ~/.zen/game/players/$PLAYER/secret.dunikey balance)
echo "+++ WALLET BALANCE _ $BAL (G1) _"
myIP=$(hostname -I | awk '{print $1}' | head -n 1)
2022-10-01 16:18:15 +02:00
echo "Getting latest online TW..."
YOU=$(ps auxf --sort=+utime | grep -w ipfs | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d " " -f 1);
LIBRA=$(head -n 2 ~/.zen/Astroport.ONE/A_boostrap_nodes.txt | tail -n 1 | cut -d ' ' -f 2)
echo "$LIBRA/ipns/$ASTRONAUTENS"
echo "http://$myIP:8080/ipns/$ASTRONAUTENS"
2022-10-01 16:18:15 +02:00
[[ $YOU ]] && ipfs --timeout 12s cat /ipns/$ASTRONAUTENS > ~/.zen/tmp/astro/index.html \
|| curl -m 12 -so ~/.zen/tmp/astro/index.html "$LIBRA/ipns/$ASTRONAUTENS"
2022-08-25 19:38:58 +02:00
## PLAYER TW IS ONLINE ?
2022-08-25 17:21:39 +02:00
if [ ! -s ~/.zen/tmp/astro/index.html ]; then
echo "ERROR_PLAYERTW_TIMEOUT : /ipns/$ASTRONAUTENS"
echo "------------------------------------------------"
echo "MANUAL PROCEDURE NEEDED"
echo "------------------------------------------------"
echo "TW=$(ipfs add -Hq ~/.zen/game/players/$PLAYER/ipfs/moa/index.html | tail -n 1)"
echo "ipfs name publish -t 72h --key=$PLAYER /ipfs/\$TW"
2022-08-25 17:21:39 +02:00
continue
2022-08-25 17:21:39 +02:00
else
2022-10-07 02:23:11 +02:00
## CHECK IF myIP IS LAST GATEWAY
tiddlywiki --load ~/.zen/tmp/astro/index.html --output ~/.zen/tmp --render '.' 'miz.json' 'text/plain' '$:/core/templates/exporters/JsonFile' 'exportFilter' 'MadeInZion'
OLDIP=$(cat ~/.zen/tmp/miz.json | jq -r .[].secret)
2022-09-27 02:00:50 +02:00
[[ $OLDIP != $myIP ]] && echo "ASTRONAUTE GATEWAY IS http://$OLDIP:8080/ipns/$ASTRONAUTENS - BYPASSING -" && continue
2022-09-27 02:00:50 +02:00
## RUN ASTROBOT SUBPROCESS
##############################################################
## TAG="tube" tiddler => Dowload youtube video links (playlist accepted) ## WISHKEY=PLAYER or G1PUB !
$MY_PATH/TUBE.copy.sh ~/.zen/tmp/astro/index.html $PLAYER
##############################################################
##############################################################
## TAG="voeu" => Creation G1Voeu "TW"
$MY_PATH/VOEU.create.sh ~/.zen/tmp/astro/index.html $PLAYER
##############################################################
## ANY CHANGES ?
##############################################################
2022-08-28 19:18:46 +02:00
DIFF=$(diff ~/.zen/tmp/astro/index.html ~/.zen/game/players/$PLAYER/ipfs/moa/index.html)
if [[ $DIFF ]]; then
echo "DIFFERENCE DETECTED !! "
2022-08-28 19:18:46 +02:00
echo "Backup & Upgrade TW local copy..."
cp ~/.zen/tmp/astro/index.html ~/.zen/game/players/$PLAYER/ipfs/moa/index.html
else
echo "No change since last Refresh..."
2022-08-28 19:18:46 +02:00
fi
##############################################################
2022-08-25 17:21:39 +02:00
fi
#
##############################################################
##############################################################
2022-09-09 21:01:01 +02:00
2022-08-31 18:02:06 +02:00
##########################
# Generate G1BARRE for each wish
2022-08-31 18:02:06 +02:00
for g1wish in $(ls ~/.zen/game/players/$PLAYER/voeux/); do
wishname=$(cat ~/.zen/game/players/$PLAYER/voeux/$g1wish/.title)
wishns=$(ipfs key list -l | grep $g1wish | cut -d ' ' -f1)
echo "MISE A JOUR G1BARRE pour VOEU $wishname : "
echo "G1WALLET $g1wish"
echo "G1VOEUTW /ipns/$wishns"
# Create last g1barre
2022-08-31 18:02:06 +02:00
G1BARRE="https://g1sms.fr/g1barre/image.php?pubkey=$g1wish&target=1000&title=$wishname&node=g1.duniter.org&start_date=2022-08-01&display_pubkey=true&display_qrcode=true&progress_color=ff07a4"
2022-09-01 02:21:45 +02:00
echo "curl -o ~/.zen/tmp/g1barre.png $G1BARRE"
rm -f ~/.zen/tmp/g1barre.png
2022-09-01 02:21:45 +02:00
curl -so ~/.zen/tmp/g1barre.png "$G1BARRE"
# Verify file exists & non/empy before copy new version in "world/$g1wish"
2022-09-01 02:21:45 +02:00
[[ ! -s ~/.zen/tmp/g1barre.png ]] && echo "No Image ! ERROR. PLEASE VERIFY NETWORK LOCATION FOR G1BARRE" && continue
cp ~/.zen/tmp/g1barre.png ~/.zen/game/world/$g1wish/g1barre.png
##################################################################"
OLDIG1BAR=$(cat ~/.zen/game/world/$g1wish/.ig1barre)
2022-09-09 21:14:13 +02:00
BAL=$($MY_PATH/../tools/jaklis/jaklis.py balance -p $g1wish )
2022-09-09 21:07:14 +02:00
echo "MONTANT (G1) $BAL"
##################################################################"
IG1BAR=$(ipfs add -Hq ~/.zen/game/world/$g1wish/g1barre.png | tail -n 1)
if [[ $OLDIG1BAR != "" && $OLDIG1BAR != $IG1BAR ]]; then # Update
echo "NEW VALUE !! Updating G1VOEU Tiddler /ipfs/$IG1BAR"
2022-09-09 20:57:46 +02:00
## Replace IG1BAR "in TW" ipfs value (hash unicity is cool !!)
sed -i "s~${OLDIG1BAR}~${IG1BAR}~g" ~/.zen/game/players/$PLAYER/ipfs/moa/index.html
echo $IG1BAR > ~/.zen/game/world/$g1wish/.ig1barre
echo "Update new g1barre: /ipfs/$IG1BAR"
2022-09-09 21:14:13 +02:00
MOATS=$(date -u +"%Y%m%d%H%M%S%4N")
echo "Avancement blockchain TW $PLAYER : $MOATS"
cp ~/.zen/game/players/$PLAYER/ipfs/moa/.chain ~/.zen/game/players/$PLAYER/ipfs/moa/.chain.$MOATS
2022-09-09 21:14:13 +02:00
TW=$(ipfs add -Hq ~/.zen/game/players/$PLAYER/ipfs/moa/index.html | tail -n 1)
echo "ipfs name publish --key=$PLAYER /ipfs/$TW"
ipfs name publish --allow-offline --key=$PLAYER /ipfs/$TW
2022-09-09 20:57:46 +02:00
2022-09-09 21:14:13 +02:00
# MAJ CACHE TW $PLAYER
echo $TW > ~/.zen/game/players/$PLAYER/ipfs/moa/.chain
echo $MOATS > ~/.zen/game/players/$PLAYER/ipfs/moa/.moats
echo "##################################################################"
##################################################################
2022-09-09 20:57:46 +02:00
2022-09-09 21:14:13 +02:00
fi
2022-09-09 21:14:13 +02:00
### NO OLDIG1BAR, MEANS FIRST RUN
if [[ $OLDIG1BAR == "" ]]; then # CREATE Tiddler
TEXT="<a target='_blank' href='"/ipns/${wishns}"'><img src='"/ipfs/${IG1BAR}"'></a><br><br><a target='_blank' href='"/ipns/${wishns}"'>"${wishname}"</a>"
# NEW G1BAR TIDDLER
echo "## Creation json tiddler : G1${wishname} /ipfs/${IG1BAR}"
echo '[
{
"title": "'G1${wishname}'",
"type": "'text/vnd.tiddlywiki'",
"ipns": "'/ipns/$wishns'",
"ipfs": "'/ipfs/$IG1BAR'",
"player": "'/ipfs/$PLAYER'",
"text": "'$TEXT'",
"tags": "'g1voeu g1${wishname} $PLAYER'"
}
]
' > ~/.zen/tmp/g1${wishname}.bank.json
rm -f ~/.zen/tmp/newindex.html
echo "Nouveau G1${wishname} : http://127.0.0.1:8080/ipns/$ASTRONAUTENS"
2022-10-07 21:28:21 +02:00
tiddlywiki --load ~/.zen/game/players/$PLAYER/ipfs/moa/index.html \
2022-09-09 21:14:13 +02:00
--import ~/.zen/tmp/g1${wishname}.bank.json "application/json" \
--output ~/.zen/tmp --render "$:/core/save/all" "newindex.html" "text/plain"
echo "PLAYER TW Update..."
if [[ -s ~/.zen/tmp/newindex.html ]]; then
echo "Mise à jour ~/.zen/game/players/$PLAYER/ipfs/moa/index.html"
cp -f ~/.zen/tmp/newindex.html ~/.zen/game/players/$PLAYER/ipfs/moa/index.html
fi
2022-09-09 21:14:13 +02:00
echo $IG1BAR > ~/.zen/game/world/$g1wish/.ig1barre
2022-09-09 21:14:13 +02:00
fi
2022-08-31 18:02:06 +02:00
done
##############################################################
##############################################################
2022-08-31 18:02:06 +02:00
2022-09-12 14:58:08 +02:00
############################
## ASTRONAUTE SIGNALING ##
[[ ! $(grep -w "$ASTRONAUTENS" ~/.zen/game/astronautes.txt ) ]] && echo "$PSEUDO:$PLAYER:$ASTRONAUTENS" >> ~/.zen/game/astronautes.txt
2022-08-31 18:02:06 +02:00
############################
MOATS=$(date -u +"%Y%m%d%H%M%S%4N")
2022-08-29 17:33:07 +02:00
[[ $DIFF ]] && cp ~/.zen/game/players/$PLAYER/ipfs/moa/.chain ~/.zen/game/players/$PLAYER/ipfs/moa/.chain.$MOATS
2022-08-25 17:21:39 +02:00
TW=$(ipfs add -Hq ~/.zen/game/players/$PLAYER/ipfs/moa/index.html | tail -n 1)
ipfs name publish --allow-offline -t 72h --key=$PLAYER /ipfs/$TW
[[ $DIFF ]] && echo $TW > ~/.zen/game/players/$PLAYER/ipfs/moa/.chain
echo $MOATS > ~/.zen/game/players/$PLAYER/ipfs/moa/.moats
2022-08-28 19:18:46 +02:00
echo "================================================"
echo "$PLAYER : http://$myIP:8080/ipns/$ASTRONAUTENS"
2022-08-28 19:18:46 +02:00
echo "================================================"
2022-08-25 17:21:39 +02:00
done
2022-10-01 16:18:15 +02:00
#################################################################
2022-09-12 14:58:08 +02:00
## IPFSNODEID ROUTING
2022-10-01 16:18:15 +02:00
## PUBLISHING ASTRONAUTS LIST
## EVOLVE TO P2P QOS MAP JSON
2022-09-12 14:58:08 +02:00
ROUTING=$(ipfs add -q ~/.zen/game/astronautes.txt)
echo "PUBLISHING IPFSNODEID / Astronaute List"
ipfs name publish /ipfs/$ROUTING
2022-08-25 17:21:39 +02:00
exit 0