Astroport.ONE/ASTROBOT/PLAYER.refresh.sh

221 lines
11 KiB
Bash
Raw Normal View History

2022-08-25 17:21:39 +02:00
#!/bin/bash
################################################################################
# Author: Fred (support@qo-op.com)
# 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
################################################################################
## 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
2022-12-11 04:40:50 +01:00
PLAYERONE="$1"
2023-01-12 23:42:03 +01:00
[[ $isLAN ]] && PLAYERONE=$(cat ~/.zen/game/players/.current/.player 2>/dev/null)
2023-01-01 21:42:31 +01:00
[[ ! $PLAYERONE ]] && PLAYERONE=($(ls -t ~/.zen/game/players/ | grep -Ev "localhost" 2>/dev/null))
2022-12-11 04:40:50 +01:00
## RUNING FOR ALL LOCAL PLAYERS
2022-12-11 20:39:27 +01:00
for PLAYER in ${PLAYERONE[@]}; do
2022-12-15 02:35:59 +01:00
[[ ! -d ~/.zen/game/players/$PLAYER ]] && echo "BAD $PLAYERONE" && continue
2022-12-09 03:21:41 +01:00
MOATS=$(date -u +"%Y%m%d%H%M%S%4N")
2022-12-27 16:46:09 +01:00
[[ ! $(echo "$PLAYER" | grep '@') ]] && continue
2022-12-09 19:10:45 +01:00
mkdir -p ~/.zen/tmp/${MOATS}
echo "##################################################################"
2022-10-31 01:58:26 +01:00
echo ">>>>> PLAYER : $PLAYER >>>>>>>>>>>>> REFRESHING TW STATION"
echo "##################################################################"
2022-12-09 00:58:48 +01:00
# Get PLAYER wallet amount
2022-12-30 22:55:10 +01:00
COINS=$($MY_PATH/../tools/jaklis/jaklis.py -k ~/.zen/game/players/$PLAYER/secret.dunikey balance)
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 "##################################################################"
echo "################### REFRESH ASTRONAUTE TW ###########################"
2022-10-24 14:59:14 +02:00
echo "##################################################################"
2022-09-12 19:53:55 +02:00
PSEUDO=$(cat ~/.zen/game/players/$PLAYER/.pseudo 2>/dev/null)
2022-11-05 21:56:34 +01:00
G1PUB=$(cat ~/.zen/game/players/$PLAYER/.g1pub 2>/dev/null)
ASTRONS=$(cat ~/.zen/game/players/$PLAYER/.playerns 2>/dev/null)
2022-10-31 01:58:26 +01:00
2022-08-25 17:21:39 +02:00
## REFRESH ASTRONAUTE TW
2022-12-25 22:26:34 +01:00
ASTRONAUTENS=$(ipfs key list -l | grep -w $PLAYER | cut -d ' ' -f1)
2022-11-14 20:45:06 +01:00
[[ ! $ASTRONAUTENS ]] && echo "WARNING No $PLAYER in keystore --" && ASTRONAUTENS=$ASTRONS
2022-11-07 01:37:00 +01:00
2022-11-11 18:22:35 +01:00
## VISA EMITER STATION MUST ACT ONLY
2022-12-08 21:08:57 +01:00
[[ ! -f ~/.zen/game/players/$PLAYER/secret.dunikey ]] && echo "$PLAYER secret.dunikey NOT HERE CONTINUE -- " \
2022-11-07 01:37:00 +01:00
&& mv ~/.zen/game/players/$PLAYER ~/.zen/game/players/.$PLAYER && continue
2022-08-25 17:21:39 +02:00
2022-12-08 21:08:57 +01:00
## MY PLAYER
2022-12-09 19:10:45 +01:00
ipfs key export $G1PUB -o ~/.zen/tmp/${MOATS}/$PLAYER.key
[[ ! $(ipfs key list -l | grep $PLAYER | cut -d ' ' -f1) ]] && ipfs key import $PLAYER ~/.zen/tmp/${MOATS}/$PLAYER.key
2022-12-09 19:10:45 +01:00
rm -f ~/.zen/tmp/${MOATS}/$PLAYER.key
2022-11-11 18:22:35 +01:00
## REFRESH 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)
2022-12-11 21:09:53 +01:00
echo "/ipns/$ASTRONAUTENS ON $LIBRA"
2022-12-15 02:35:59 +01:00
2022-12-25 22:20:50 +01:00
ipfs --timeout 60s get -o ~/.zen/tmp/${IPFSNODEID}/${PLAYER}/index.html /ipns/$ASTRONAUTENS \
|| curl -m 60 -so ~/.zen/tmp/${IPFSNODEID}/${PLAYER}/index.html "$LIBRA/ipns/$ASTRONAUTENS" \
2022-12-11 21:09:53 +01:00
|| cp ~/.zen/game/players/$PLAYER/ipfs/moa/index.html ~/.zen/tmp/${IPFSNODEID}/${PLAYER}/index.html
2022-08-25 19:38:58 +02:00
## PLAYER TW IS ONLINE ?
2022-11-05 22:32:28 +01:00
if [ ! -s ~/.zen/tmp/${IPFSNODEID}/${PLAYER}/index.html ]; then
echo "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
2022-11-05 21:56:34 +01:00
echo "ERROR_PLAYERTW_OFFLINE : /ipns/$ASTRONAUTENS"
echo "------------------------------------------------"
echo "MANUAL PROCEDURE NEEDED"
echo "------------------------------------------------"
2022-12-29 14:51:05 +01:00
echo "$myIPFS/ipfs/"
2022-11-29 16:39:58 +01:00
echo "/ipfs/"$(cat ~/.zen/game/players/$PLAYER/ipfs/moa/.chain.* | tail -n 1)
echo "ipfs name publish -t 24h --key=$PLAYER ..."
echo "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
2022-11-05 21:56:34 +01:00
2022-08-25 17:21:39 +02:00
continue
2022-08-25 17:21:39 +02:00
else
2022-11-02 18:51:55 +01:00
## FOUND TW
#############################################################
2022-12-09 03:21:41 +01:00
## CHECK WHO IS ACTUAL OFFICIAL GATEWAY
2022-12-09 19:10:45 +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-07 20:44:57 +01:00
[[ ! -s ~/.zen/tmp/${MOATS}/MadeInZion.json ]] && echo "${PLAYER} MadeInZion : BAD TW (☓‿‿☓) " && continue
2022-12-09 03:21:41 +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
[[ $player == $PLAYER ]] \
&& echo "$PLAYER OFFICIAL TW - (⌐■_■) -" \
|| ( echo "BAD PLAYER=$player in TW" && continue)
fi
#############################################################
## GWIP == myIP or TUBE !!
#############################################################
2022-09-27 02:00:50 +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"
${MY_PATH}/../tools/Connect_PLAYER_To_Gchange.sh "$PLAYER"
# VOEUX.create.sh
##############################################################
## SPECIAL TAG "voeu" => Creation G1Voeu (G1Titre) makes AstroBot TW G1Processing
##############################################################
2022-12-04 15:06:09 +01:00
${MY_PATH}/VOEUX.create.sh ~/.zen/tmp/${IPFSNODEID}/${PLAYER}/index.html "$PLAYER"
# VOEUX.refresh.sh
##############################################################
2022-12-04 15:06:09 +01:00
## RUN ASTROBOT G1Voeux SUBPROCESS (SPECIFIC Ŋ1 COPY)
##############################################################
${MY_PATH}/VOEUX.refresh.sh "$PLAYER" "$MOATS" ~/.zen/tmp/${IPFSNODEID}/${PLAYER}/index.html
##############################################################
2023-01-03 19:56:30 +01:00
## CHECK G1PALPAY TO MAKE
2023-01-09 03:45:02 +01:00
${MY_PATH}/G1PalPay.sh ~/.zen/tmp/${IPFSNODEID}/${PLAYER}/index.html "$PLAYER"
2023-01-03 19:56:30 +01: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-12-13 13:44:50 +01:00
FEEDNS=$(ipfs key list -l | grep -w "${PLAYER}_feed" | cut -d ' ' -f 1)
[[ ! $FEEDNS ]] && FEEDNS=$(ipfs key gen "${PLAYER}_feed")
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
###########################
# 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-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
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" \
--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
## ANY CHANGES ?
##############################################################
2022-11-05 22:32:28 +01: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
echo "DIFFERENCE DETECTED !! "
2022-08-28 19:18:46 +02:00
echo "Backup & Upgrade TW local copy..."
2022-11-05 22:32:28 +01:00
cp ~/.zen/tmp/${IPFSNODEID}/${PLAYER}/index.html ~/.zen/game/players/$PLAYER/ipfs/moa/index.html
2022-08-28 19:18:46 +02:00
fi
##############################################################
2022-11-02 18:51:55 +01:00
##################################################
##################################################
################## UPDATING PLAYER MOA
2022-10-10 00:39:07 +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-25 17:21:39 +02:00
TW=$(ipfs add -Hq ~/.zen/game/players/$PLAYER/ipfs/moa/index.html | tail -n 1)
2022-11-20 12:57:41 +01:00
ipfs name publish --allow-offline -t 24h --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 "================================================"
2022-12-29 14:51:05 +01:00
echo "$PLAYER : $myIPFS/ipns/$ASTRONAUTENS"
2022-11-11 18:22:35 +01:00
echo " = /ipfs/$TW"
2022-08-28 19:18:46 +02:00
echo "================================================"
2022-08-25 17:21:39 +02:00
######################### PLAYER_feed
2022-12-14 17:34:55 +01:00
IFRIENDHEAD="$(cat ~/.zen/tmp/${IPFSNODEID}/rss/${PLAYER}/IFRIENDHEAD 2>/dev/null)"
echo "(☉_☉ ) (☉_☉ ) (☉_☉ )"
echo "IFRIENDHEAD :" ${IFRIENDHEAD}
echo "(☉_☉ ) (☉_☉ ) (☉_☉ )"
2023-01-07 20:44:57 +01:00
# cp -f ~/.zen/game/players/${PLAYER}/ipfs/${FPLAYER}.rss.json ~/.zen/game/players/$PLAYER/FRIENDS/${FPLAYER}.rss.json
2022-12-14 00:24:14 +01:00
[[ -d ~/.zen/game/players/$PLAYER/FRIENDS ]] \
2023-01-12 23:58:06 +01:00
&& 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-14 00:24:14 +01:00
[[ -s ~/.zen/game/players/$PLAYER/FRIENDS/index.html ]] \
&& FRAME=$(ipfs add -Hq ~/.zen/game/players/$PLAYER/FRIENDS/index.html | tail -n 1) \
&& ipfs name publish --allow-offline -t 24h --key="${PLAYER}_feed" /ipfs/$FRAME
2022-08-25 17:21:39 +02:00
done
2022-10-01 16:18:15 +02:00
#################################################################
2022-11-05 21:56:34 +01:00
## IPFSNODEID ASTRONAUTES SIGNALING ## 12345 port
############################
# Scan local cache
2023-01-12 23:42:03 +01:00
if [[ -d ~/.zen/tmp/${IPFSNODEID} ]]; then
BSIZE=$(du -b ~/.zen/tmp/${IPFSNODEID} | tail -n 1 | cut -f 1)
## Merge actual online version
ipfs get -o ~/.zen/tmp/${IPFSNODEID} /ipns/${IPFSNODEID}/
2023-01-12 23:58:06 +01:00
## MAP CACHE CLEANING
rm -f ~/.zen/tmp/${IPFSNODEID}/*TW.json
############################################
2023-01-12 23:42:03 +01:00
NSIZE=$(du -b ~/.zen/tmp/${IPFSNODEID} | tail -n 1 | cut -f 1)
[[ $BSIZE != $NSIZE ]] \
&& ROUTING=$(ipfs add -rwHq ~/.zen/tmp/${IPFSNODEID}/* | tail -n 1 ) \
&& echo "PUBLISH BALISE STATION /ipns/${IPFSNODEID} = $NSIZE octets" \
&& ipfs name publish --allow-offline -t 24h /ipfs/$ROUTING
fi
2022-11-05 21:56:34 +01:00
2022-11-11 18:22:35 +01:00
echo "PLAYER.refresh DONE."
2022-09-12 14:58:08 +02:00
2022-08-25 17:21:39 +02:00
exit 0