2022-08-25 17:21:39 +02:00
#!/bin/bash
################################################################################
# Author: Fred (support@qo-op.com)
2022-10-12 23:29:14 +02:00
# Version: 0.2
2022-08-25 17:21:39 +02:00
# 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
2022-12-29 14:51:05 +01:00
. " $MY_PATH /../tools/my.sh "
2022-08-25 17:21:39 +02:00
################################################################################
2022-10-09 23:07:30 +02:00
## Publish All PLAYER TW,
# Run TAG subprocess: tube, voeu
2022-08-25 17:21:39 +02:00
############################################
2022-10-09 23:07:30 +02:00
echo "## RUNNING PLAYER.refresh"
2022-08-25 17:21:39 +02:00
2022-12-11 04:40:50 +01:00
PLAYERONE = " $1 "
2023-02-27 03:44:39 +01:00
# [[ $isLAN ]] && PLAYERONE=$(cat ~/.zen/game/players/.current/.player 2>/dev/null)
2023-04-20 15:09:17 +02:00
[ [ ! ${ PLAYERONE } ] ] && PLAYERONE = ( $( ls -t ~/.zen/game/players/ | grep "@" 2>/dev/null) )
2022-12-11 04:40:50 +01:00
2023-02-23 20:58:01 +01:00
echo " FOUND : ${ PLAYERONE [@] } "
2022-10-09 23:07:30 +02:00
## RUNING FOR ALL LOCAL PLAYERS
2022-12-11 20:39:27 +01:00
for PLAYER in ${ PLAYERONE [@] } ; do
2023-04-20 15:09:17 +02:00
[ [ ! -d ~/.zen/game/players/${ PLAYER :- undefined } ] ] && echo " BAD ${ PLAYERONE } " && continue
[ [ ! $( echo " ${ PLAYER } " | grep '@' ) ] ] && continue
2022-12-28 17:21:50 +01:00
2023-02-25 03:19:33 +01:00
# CLEAN LOST ACCOUNT
2023-04-20 15:09:17 +02:00
[ [ ! -s ~/.zen/game/players/${ PLAYER } /secret.dunikey ] ] \
&& rm -Rf ~/.zen/game/players/${ PLAYER } \
2023-05-01 03:50:19 +02:00
&& mv ~/.zen/game/players/${ PLAYER } ~/.zen/game/players/.${ PLAYER } 2>/dev/null \
2023-04-20 15:09:17 +02:00
&& echo " LOST ${ PLAYER } IS OUT " \
&& continue
2023-02-25 03:19:33 +01:00
2022-12-09 03:21:41 +01:00
MOATS = $( date -u +"%Y%m%d%H%M%S%4N" )
2022-12-09 19:10:45 +01:00
mkdir -p ~/.zen/tmp/${ MOATS }
2023-03-16 20:02:12 +01:00
2022-10-09 23:07:30 +02:00
echo "##################################################################"
2023-04-20 15:09:17 +02:00
echo " >>>>> PLAYER : ${ PLAYER } >>>>>>>>>>>>> REFRESHING TW STATION "
2022-10-09 23:07:30 +02:00
echo "##################################################################"
2023-04-20 15:09:17 +02:00
PSEUDO = $( cat ~/.zen/game/players/${ PLAYER } /.pseudo 2>/dev/null)
G1PUB = $( cat ~/.zen/game/players/${ PLAYER } /.g1pub 2>/dev/null)
ASTRONS = $( cat ~/.zen/game/players/${ PLAYER } /.playerns 2>/dev/null)
2022-12-09 00:58:48 +01:00
# Get PLAYER wallet amount
2023-03-13 18:50:20 +01:00
COINS = $( $MY_PATH /../tools/COINScheck.sh $G1PUB | tail -n 1)
2022-12-09 00:58:48 +01:00
echo " +++ WALLET BALANCE _ $COINS (G1) _ "
#~ ## IF WALLET IS EMPTY : WHAT TODO ?
2022-10-24 16:38:59 +02:00
echo "##################################################################"
2022-10-24 14:59:14 +02:00
echo "##################################################################"
2022-10-24 16:19:33 +02:00
echo "################### REFRESH ASTRONAUTE TW ###########################"
2022-10-24 14:59:14 +02:00
echo "##################################################################"
2022-10-31 01:58:26 +01:00
2022-08-25 17:21:39 +02:00
## REFRESH ASTRONAUTE TW
2023-04-20 15:09:17 +02:00
ASTRONAUTENS = $( ipfs key list -l | grep -w ${ PLAYER } | cut -d ' ' -f1)
[ [ ! ${ ASTRONAUTENS } ] ] \
&& echo " WARNING No ${ PLAYER } in keystore WARNING WARNING " \
&& ASTRONAUTENS = $ASTRONS
2022-11-07 01:37:00 +01:00
2023-05-02 02:51:23 +02:00
[ [ ! ${ ASTRONAUTENS } ] ] && echo " ERROR BAD ${ PLAYER } - CONTINUE " && continue
2023-04-20 15:09:17 +02:00
echo " >>> $myIPFS /ipns/ ${ ASTRONAUTENS } "
2023-01-16 22:38:34 +01:00
2023-04-20 15:09:17 +02:00
## MY PLAYER : RESTORE PLAYER KEY FROM G1PUB (IN CASE IS MISSING : PLAYER LOGOUT)
ipfs key export $G1PUB -o ~/.zen/tmp/${ MOATS } /${ PLAYER } .key
[ [ ! $( ipfs key list -l | grep -w ${ PLAYER } | cut -d ' ' -f1) ] ] && ipfs key import ${ PLAYER } ~/.zen/tmp/${ MOATS } /${ PLAYER } .key
rm ~/.zen/tmp/${ MOATS } /${ PLAYER } .key
2022-08-25 17:21:39 +02:00
2023-04-20 15:09:17 +02:00
## REFRESH PLAYER IN STATION CACHE
2022-11-05 22:32:28 +01:00
rm -Rf ~/.zen/tmp/${ IPFSNODEID } /${ PLAYER } /
mkdir -p ~/.zen/tmp/${ IPFSNODEID } /${ PLAYER } /
2022-08-25 17:21:39 +02:00
2022-10-01 16:18:15 +02:00
echo "Getting latest online TW..."
LIBRA = $( head -n 2 ~/.zen/Astroport.ONE/A_boostrap_nodes.txt | tail -n 1 | cut -d ' ' -f 2)
2023-04-20 15:09:17 +02:00
echo " /ipns/ ${ ASTRONAUTENS } ON $LIBRA "
2022-12-15 02:35:59 +01:00
2023-04-20 15:09:17 +02:00
## IPFS / HTTP / LOCAL
ipfs --timeout 360s get -o ~/.zen/tmp/${ IPFSNODEID } /${ PLAYER } /index.html /ipns/${ ASTRONAUTENS } \
|| curl -m 60 -so ~/.zen/tmp/${ IPFSNODEID } /${ PLAYER } /index.html " $LIBRA /ipns/ ${ ASTRONAUTENS } " \
|| cp ~/.zen/game/players/${ PLAYER } /ipfs/moa/index.html ~/.zen/tmp/${ IPFSNODEID } /${ PLAYER } /index.html
2022-08-25 19:38:58 +02:00
2022-10-09 23:07:30 +02:00
## PLAYER TW IS ONLINE ?
2022-11-05 22:32:28 +01:00
if [ ! -s ~/.zen/tmp/${ IPFSNODEID } /${ PLAYER } /index.html ] ; then
2022-10-09 23:07:30 +02:00
2022-10-12 23:29:14 +02:00
echo "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
2023-04-20 15:09:17 +02:00
echo " ERROR_PLAYERTW_OFFLINE : /ipns/ ${ ASTRONAUTENS } "
2022-10-09 23:07:30 +02:00
echo "------------------------------------------------"
echo "MANUAL PROCEDURE NEEDED"
echo "------------------------------------------------"
2022-12-29 14:51:05 +01:00
echo " $myIPFS /ipfs/ "
2023-04-20 15:09:17 +02:00
echo "/ipfs/" $( cat ~/.zen/game/players/${ PLAYER } /ipfs/moa/.chain.* | tail -n 1)
echo " ipfs name publish -t 24h --key= ${ PLAYER } ... "
2022-10-12 23:29:14 +02:00
echo "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
2022-11-05 21:56:34 +01:00
2022-08-25 17:21:39 +02:00
continue
2022-10-09 23:07:30 +02:00
2022-08-25 17:21:39 +02:00
else
2022-11-02 18:51:55 +01:00
## FOUND TW
2022-10-12 23:29:14 +02:00
#############################################################
2022-12-09 03:21:41 +01:00
## CHECK WHO IS ACTUAL OFFICIAL GATEWAY
2023-02-27 02:34:26 +01:00
tiddlywiki --load ~/.zen/tmp/${ IPFSNODEID } /${ PLAYER } /index.html \
--output ~/.zen/tmp/${ MOATS } \
--render '.' 'MadeInZion.json' 'text/plain' '$:/core/templates/exporters/JsonFile' 'exportFilter' 'MadeInZion'
2023-01-15 15:59:33 +01:00
2023-02-27 02:34:26 +01:00
[ [ ! -s ~/.zen/tmp/${ MOATS } /MadeInZion.json ] ] && echo " ${ PLAYER } MadeInZion : BAD TW (☓‿‿☓) " && continue
2023-01-15 15:59:33 +01:00
2022-12-09 19:10:45 +01:00
player = $( cat ~/.zen/tmp/${ MOATS } /MadeInZion.json | jq -r .[ ] .player)
2022-12-09 03:21:41 +01:00
2023-04-20 15:09:17 +02:00
[ [ $player = = ${ PLAYER } ] ] \
&& echo " ${ PLAYER } OFFICIAL TW - (⌐■_■) - " \
2023-02-27 02:34:26 +01:00
|| ( echo " > BAD PLAYER= $player in TW " && continue )
## DETECT IF GOOD ASTROPORT
tiddlywiki --load ~/.zen/tmp/${ IPFSNODEID } /${ PLAYER } /index.html \
--output ~/.zen/tmp/${ MOATS } \
--render '.' 'Astroport.json' 'text/plain' '$:/core/templates/exporters/JsonFile' 'exportFilter' 'Astroport'
ASTROPORT = $( cat ~/.zen/tmp/${ MOATS } /Astroport.json | jq -r .[ ] .astroport)
2023-04-08 12:18:27 +02:00
CURCHAIN = $( cat ~/.zen/tmp/${ MOATS } /Astroport.json | jq -r .[ ] .chain | rev | cut -f 1 -d '/' | rev) # Remove "/ipfs/" part
2023-04-20 15:09:17 +02:00
[ [ ${ CURCHAIN } = = "" || ${ CURCHAIN } = = "null" ] ] && CURCHAIN = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" # AVOID EMPTY
echo " CURCHAIN= ${ CURCHAIN } "
2023-02-27 02:34:26 +01:00
IPNSTAIL = $( echo ${ ASTROPORT } | rev | cut -f 1 -d '/' | rev) # Remove "/ipns/" part
echo " TW ASTROPORT GATEWAY : ${ ASTROPORT } "
## MOVED PLAYER (KEY IS KEPT ON LAST CONNECTED ASTROPORT)
2023-04-07 13:22:28 +02:00
if [ [ ${ IPNSTAIL } != ${ IPFSNODEID } && ${ IPNSTAIL } != "_ASTROPORT_" ] ] ; then
2023-03-29 14:52:53 +02:00
echo " > I AM ${ IPFSNODEID } : PLAYER MOVED TO ${ IPNSTAIL } : EJECTION "
echo "REMOVE PLAYER & G1VOEU IPNS KEYS"
ipfs key rm " ${ PLAYER } " " ${ PLAYER } _feed " " $G1PUB "
for vk in $( ls -d ~/.zen/game/players/${ PLAYER } /voeux/*/* | rev | cut -d / -f 1 | rev) ; do
ipfs key rm $vk
done
rm -Rf ~/.zen/game/players/${ PLAYER } /
2023-04-20 15:09:17 +02:00
echo " >>>> ASTRONAUT ${ PLAYER } TW CAPSULE EJECTION TERMINATED "
2023-03-29 14:52:53 +02:00
continue
fi
2022-11-16 04:42:27 +01:00
fi
#############################################################
2022-11-17 17:56:50 +01:00
## GWIP == myIP or TUBE !!
2022-10-12 23:29:14 +02:00
#############################################################
2022-11-12 15:05:02 +01:00
# Connect_PLAYER_To_Gchange.sh : Sync FRIENDS TW
##############################################################
echo "##################################################################"
echo "## GCHANGE+ & Ŋ1 EXPLORATION: Connect_PLAYER_To_Gchange.sh"
2023-04-20 15:09:17 +02:00
${ MY_PATH } /../tools/Connect_PLAYER_To_Gchange.sh " ${ PLAYER } "
2022-11-12 15:05:02 +01:00
2022-10-12 23:29:14 +02:00
# VOEUX.create.sh
2022-10-09 23:07:30 +02:00
##############################################################
2022-10-10 16:21:33 +02:00
## SPECIAL TAG "voeu" => Creation G1Voeu (G1Titre) makes AstroBot TW G1Processing
2022-10-09 23:07:30 +02:00
##############################################################
2023-09-04 17:04:20 +02:00
${ MY_PATH } /VOEUX.create.sh ~/.zen/tmp/${ IPFSNODEID } /${ PLAYER } /index.html " ${ PLAYER } " " ${ G1PUB } "
2022-10-12 23:29:14 +02:00
# VOEUX.refresh.sh
2022-10-09 23:07:30 +02:00
##############################################################
2022-12-04 15:06:09 +01:00
## RUN ASTROBOT G1Voeux SUBPROCESS (SPECIFIC Ŋ1 COPY)
2022-10-10 16:21:33 +02:00
##############################################################
2023-04-25 18:17:46 +02:00
${ MY_PATH } /VOEUX.refresh.sh " ${ PLAYER } " " ${ MOATS } " ~/.zen/tmp/${ IPFSNODEID } /${ PLAYER } /index.html
2022-10-10 16:21:33 +02:00
##############################################################
2022-10-09 23:07:30 +02:00
2022-12-13 13:44:50 +01:00
##################################
echo "# TW : GW API + LightBeam Feed + Friends"
2022-11-06 00:13:32 +01:00
TUBE = $( head -n 2 ~/.zen/Astroport.ONE/A_boostrap_nodes.txt | tail -n 1 | cut -d ' ' -f 3)
2022-11-16 04:42:27 +01:00
2022-12-13 13:44:50 +01:00
FEEDNS = $( ipfs key list -l | grep -w " ${ PLAYER } _feed " | cut -d ' ' -f 1)
2023-04-20 15:09:17 +02:00
[ [ ! $FEEDNS ] ] && echo " ERROR ${ PLAYER } _feed IPNS KEY NOT FOUND - ERROR " && continue
2022-12-13 13:44:50 +01:00
echo '[{"title":"$:/plugins/astroport/lightbeams/saver/ipns/lightbeam-name","text":"' ${ PLAYER } _feed'","tags":""}]' > ~/.zen/tmp/${ MOATS } /lightbeam-name.json
echo '[{"title":"$:/plugins/astroport/lightbeams/saver/ipns/lightbeam-key","text":"' ${ FEEDNS } '","tags":""}]' > ~/.zen/tmp/${ MOATS } /lightbeam-key.json
2022-11-16 04:42:27 +01:00
###########################
# Modification Tiddlers de contrôle de GW & API
2023-01-03 19:56:30 +01:00
#~ echo '[{"title":"$:/ipfs/saver/api/http/localhost/5001","tags":"$:/ipfs/core $:/ipfs/saver/api","text":"'$(myPlayerApiGw)'"}]' > ~/.zen/tmp/${MOATS}/5001.json
#~ echo '[{"title":"$:/ipfs/saver/gateway/http/localhost","tags":"$:/ipfs/core $:/ipfs/saver/gateway","text":"'$myIPFS'"}]' > ~/.zen/tmp/${MOATS}/8080.json
2022-11-16 04:42:27 +01:00
2022-12-14 17:34:55 +01:00
FRIENDSFEEDS = $( cat ~/.zen/tmp/${ IPFSNODEID } /rss/${ PLAYER } /FRIENDSFEEDS 2>/dev/null)
2023-01-03 19:57:40 +01:00
echo "FRIENDS qo-op FEEDS : " ${ FRIENDSFEEDS }
2022-12-14 17:34:55 +01:00
2022-12-11 04:40:50 +01:00
## export FRIENDSFEEDS from Gchange stars
echo '[{"title":"$:/plugins/astroport/lightbeams/state/subscriptions","text":"' ${ FRIENDSFEEDS } '","tags":""}]' > ~/.zen/tmp/${ MOATS } /friends.json
2022-12-09 03:21:41 +01:00
2022-11-16 04:42:27 +01:00
tiddlywiki --load ~/.zen/tmp/${ IPFSNODEID } /${ PLAYER } /index.html \
2022-12-13 13:44:50 +01:00
--import ~/.zen/tmp/${ MOATS } /lightbeam-name.json "application/json" \
--import ~/.zen/tmp/${ MOATS } /lightbeam-key.json "application/json" \
2022-12-09 19:10:45 +01:00
--import " $HOME /.zen/tmp/ ${ MOATS } /friends.json " "application/json" \
2022-11-16 04:42:27 +01:00
--output ~/.zen/tmp/${ IPFSNODEID } /${ PLAYER } --render " $:/core/save/all " "newindex.html" "text/plain"
[ [ -s ~/.zen/tmp/${ IPFSNODEID } /${ PLAYER } /newindex.html ] ] \
&& cp ~/.zen/tmp/${ IPFSNODEID } /${ PLAYER } /newindex.html ~/.zen/tmp/${ IPFSNODEID } /${ PLAYER } /index.html \
&& rm ~/.zen/tmp/${ IPFSNODEID } /${ PLAYER } /newindex.html
###########################
2022-11-06 00:13:32 +01:00
2022-11-02 18:51:55 +01:00
####################
2022-10-30 19:39:30 +01:00
2022-10-09 23:07:30 +02:00
## ANY CHANGES ?
##############################################################
2023-04-20 15:09:17 +02:00
DIFF = $( diff ~/.zen/tmp/${ IPFSNODEID } /${ PLAYER } /index.html ~/.zen/game/players/${ PLAYER } /ipfs/moa/index.html)
2022-08-28 19:18:46 +02:00
if [ [ $DIFF ] ] ; then
2022-10-09 23:07:30 +02:00
echo "DIFFERENCE DETECTED !! "
2022-08-28 19:18:46 +02:00
echo "Backup & Upgrade TW local copy..."
2023-04-20 15:09:17 +02:00
cp ~/.zen/tmp/${ IPFSNODEID } /${ PLAYER } /index.html ~/.zen/game/players/${ PLAYER } /ipfs/moa/index.html
2023-04-08 12:18:27 +02:00
2023-04-20 15:09:17 +02:00
[ [ -s ~/.zen/game/players/${ PLAYER } /ipfs/moa/.chain ] ] \
&& ZCHAIN = $( cat ~/.zen/game/players/${ PLAYER } /ipfs/moa/.chain) \
&& echo " # CHAIN : ${ CURCHAIN } -> ${ ZCHAIN } " \
&& sed -i " s~ ${ CURCHAIN } ~ ${ ZCHAIN } ~g " ~/.zen/game/players/${ PLAYER } /ipfs/moa/index.html
2022-08-28 19:18:46 +02:00
fi
2022-10-09 23:07:30 +02:00
##############################################################
2022-11-02 18:51:55 +01:00
##################################################
##################################################
################## UPDATING PLAYER MOA
2023-04-20 15:09:17 +02:00
[ [ $DIFF ] ] && cp ~/.zen/game/players/${ PLAYER } /ipfs/moa/.chain \
~/.zen/game/players/${ PLAYER } /ipfs/moa/.chain.$( cat ~/.zen/game/players/${ PLAYER } /ipfs/moa/.moats)
2022-08-28 19:21:56 +02:00
2023-04-20 15:09:17 +02:00
TW = $( ipfs add -Hq ~/.zen/game/players/${ PLAYER } /ipfs/moa/index.html | tail -n 1)
2023-04-25 18:17:46 +02:00
ipfs name publish --allow-offline -t 24h --key= ${ PLAYER } /ipfs/${ TW }
2022-08-28 19:21:56 +02:00
2023-04-25 18:17:46 +02:00
[ [ $DIFF ] ] && echo ${ TW } > ~/.zen/game/players/${ PLAYER } /ipfs/moa/.chain
echo ${ MOATS } > ~/.zen/game/players/${ PLAYER } /ipfs/moa/.moats
2022-08-28 19:21:56 +02:00
2022-08-28 19:18:46 +02:00
echo "================================================"
2023-04-25 18:17:46 +02:00
echo " MAJ TW ${ PLAYER } : = /ipfs/ ${ TW } "
2023-04-20 15:09:17 +02:00
echo " $myIPFSGW /ipns/ ${ ASTRONAUTENS } "
2022-08-28 19:18:46 +02:00
echo "================================================"
2022-08-25 17:21:39 +02:00
2022-12-13 23:33:28 +01:00
######################### PLAYER_feed
2022-12-14 17:34:55 +01:00
IFRIENDHEAD = " $( cat ~/.zen/tmp/${ IPFSNODEID } /rss/${ PLAYER } /IFRIENDHEAD 2>/dev/null) "
2022-12-13 23:33:28 +01:00
echo "(☉_☉ ) (☉_☉ ) (☉_☉ )"
echo "IFRIENDHEAD :" ${ IFRIENDHEAD }
echo "(☉_☉ ) (☉_☉ ) (☉_☉ )"
2023-01-07 20:44:57 +01:00
2023-04-20 15:09:17 +02:00
# cp -f ~/.zen/game/players/${PLAYER}/ipfs/${FPLAYER}.rss.json ~/.zen/game/players/${PLAYER}/FRIENDS/${FPLAYER}.rss.json
2023-01-07 20:44:57 +01:00
2023-04-20 15:09:17 +02:00
[ [ -d ~/.zen/game/players/${ PLAYER } /FRIENDS ] ] \
&& cat ${ MY_PATH } /../www/iframe.html | sed " s~_ME_~/ipns/ ${ ASTRONAUTENS } ~g " | sed " s~_IFRIENDHEAD_~ ${ IFRIENDHEAD } ~g " > ~/.zen/game/players/${ PLAYER } /FRIENDS/index.html
2022-12-13 23:33:28 +01:00
2023-04-20 15:09:17 +02:00
[ [ -s ~/.zen/game/players/${ PLAYER } /FRIENDS/index.html ] ] \
&& FRAME = $( ipfs add -Hq ~/.zen/game/players/${ PLAYER } /FRIENDS/index.html | tail -n 1) \
2023-01-16 23:36:03 +01:00
&& ipfs name publish --key= " ${ PLAYER } _feed " /ipfs/$FRAME
2022-12-13 23:33:28 +01:00
2022-08-25 17:21:39 +02:00
done
2022-11-11 18:22:35 +01:00
echo "PLAYER.refresh DONE."
2022-09-12 14:58:08 +02:00
2023-05-02 03:08:16 +02:00
${ MY_PATH } /../tools/MAP.refresh.sh
2023-04-06 17:11:24 +02:00
2022-08-25 17:21:39 +02:00
exit 0