Astroport.ONE/ASTROBOT/PLAYER.refresh.sh

147 lines
7.0 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
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-10-31 01:58:26 +01:00
for PLAYER in $(ls -t ~/.zen/game/players/); do
2022-10-31 17:22:40 +01:00
[[ $PLAYER == '.toctoc' ]] && echo ".toctoc users " && continue
echo "##################################################################"
2022-10-31 01:58:26 +01:00
echo ">>>>> PLAYER : $PLAYER >>>>>>>>>>>>> REFRESHING TW STATION"
echo "##################################################################"
# Get PLAYER wallet amount
COINS=$($MY_PATH/../tools/jaklis/jaklis.py -k ~/.zen/game/players/$PLAYER/secret.dunikey balance)
echo "+++ WALLET BALANCE _ $COINS (G1) _"
2022-10-31 01:58:26 +01:00
## DROP IF WALLET IS EMPTY : TODO
2022-10-24 16:38:59 +02:00
echo "##################################################################"
echo "## GCHANGE+ & Ŋ1 EXPLORATION: Connect_PLAYER_To_Gchange.sh"
2022-10-24 14:59:14 +02:00
${MY_PATH}/../tools/Connect_PLAYER_To_Gchange.sh "$PLAYER"
echo "##################################################################"
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-10-31 01:58:26 +01:00
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
2022-10-31 01:58:26 +01:00
rm -Rf ~/.zen/tmp/${PLAYER}
mkdir -p ~/.zen/tmp/${PLAYER}
2022-08-25 17:21:39 +02:00
myIP=$(hostname -I | awk '{print $1}' | head -n 1)
isLAN=$(echo $myIP | grep -E "/(^127\.)|(^192\.168\.)|(^10\.)|(^172\.1[6-9]\.)|(^172\.2[0-9]\.)|(^172\.3[0-1]\.)|(^::1$)|(^[fF][cCdD])/")
[[ ! $myIP || $isLAN ]] && myIP="127.0.1.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"
2022-10-10 18:06:37 +02:00
echo "http://$myIP:8080/ipns/$ASTRONAUTENS ($YOU)"
2022-11-02 18:51:55 +01:00
[[ $YOU ]] && ipfs --timeout 12s cat /ipns/$ASTRONAUTENS > ~/.zen/tmp/${PLAYER}/index.html \
2022-10-31 01:58:26 +01:00
|| curl -m 12 -so ~/.zen/tmp/${PLAYER}/index.html "$LIBRA/ipns/$ASTRONAUTENS"
2022-08-25 19:38:58 +02:00
## PLAYER TW IS ONLINE ?
2022-10-31 01:58:26 +01:00
if [ ! -s ~/.zen/tmp/${PLAYER}/index.html ]; then
echo "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
echo "ERROR_PLAYERTW_TIMEOUT : /ipns/$ASTRONAUTENS"
echo "------------------------------------------------"
echo "MANUAL PROCEDURE NEEDED"
echo "------------------------------------------------"
2022-11-02 21:03:52 +01:00
echo "http://$myIP:8080/ipfs/"
cat ~/.zen/game/players/$PLAYER/ipfs/moa/.chain.*
echo "ipfs name publish -t 72h --key=$PLAYER /ipfs/"
echo "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
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
#############################################################
## CHECK IF myIP IS ACTUAL OFFICIAL GATEWAY
2022-10-31 01:58:26 +01:00
tiddlywiki --load ~/.zen/tmp/${PLAYER}/index.html --output ~/.zen/tmp --render '.' 'miz.json' 'text/plain' '$:/core/templates/exporters/JsonFile' 'exportFilter' 'MadeInZion'
2022-10-07 02:23:11 +02:00
OLDIP=$(cat ~/.zen/tmp/miz.json | jq -r .[].secret)
2022-11-02 18:51:55 +01:00
[[ ! $OLDIP ]] && echo "(╥☁╥ ) ERROR - SORRY - TW IS BROKEN - (╥☁╥ ) " && continue
2022-10-31 01:58:26 +01:00
# WHO IS OFFICIAL TW GATEWAY
2022-11-05 16:43:13 +01:00
[[ $OLDIP != $myIP && $OLDIP != "_SECRET_" ]] && ipfs key rm ${PLAYER} && echo "*** OFFICIAL GATEWAY : http://$OLDIP:8080/ipns/$ASTRONAUTENS - (⌐■_■) - ***" && continue
#############################################################
2022-09-27 02:00:50 +02:00
# VOEUX.create.sh
##############################################################
## SPECIAL TAG "voeu" => Creation G1Voeu (G1Titre) makes AstroBot TW G1Processing
##############################################################
2022-10-31 01:58:26 +01:00
$MY_PATH/VOEUX.create.sh ~/.zen/tmp/${PLAYER}/index.html $PLAYER
# VOEUX.refresh.sh
##############################################################
## RUN ASTROBOT G1Voeux SUBPROCESS (SPECIFIC AND STANDARD Ŋ1 SYNC)
##############################################################
2022-10-31 01:58:26 +01:00
$MY_PATH/VOEUX.refresh.sh ~/.zen/tmp/${PLAYER}/index.html $PLAYER
##############################################################
2022-11-02 18:51:55 +01:00
####################
# LOCKING TW : myIP becomes _SECRET_
sed -i "s~${myIP}~_SECRET_~g" ~/.zen/tmp/${PLAYER}/index.html
####################
2022-10-30 19:39:30 +01:00
## ANY CHANGES ?
##############################################################
2022-10-31 01:58:26 +01:00
DIFF=$(diff ~/.zen/tmp/${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-10-31 01:58:26 +01:00
cp ~/.zen/tmp/${PLAYER}/index.html ~/.zen/game/players/$PLAYER/ipfs/moa/index.html
2022-08-28 19:18:46 +02:00
fi
##############################################################
2022-08-25 17:21:39 +02:00
fi
2022-11-02 18:51:55 +01:00
##################################################
##################################################
################## UPDATING PLAYER MOA
MOATS=$(date -u +"%Y%m%d%H%M%S%4N")
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)
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
2022-10-31 02:52:43 +01:00
## TODO ! NOT .current SO ipfs key rm
2022-10-13 19:50:55 +02:00
## PUBLISHING ASTRONAUTS LIST
[[ ! $(grep -w "$ASTRONAUTENS" ~/.zen/game/astronautes.txt ) ]] && echo "$PSEUDO:$PLAYER:$ASTRONAUTENS" >> ~/.zen/game/astronautes.txt
2022-08-25 17:21:39 +02:00
done
2022-10-01 16:18:15 +02:00
#################################################################
## IPFSNODEIDE ASTRONAUTES SIGNALING ##
############################
############################
## TODO EVOLVE TO P2P QOS MAPPING
IPFSNODEID=$(cat ~/.ipfs/config | jq -r .Identity.PeerID)
ls ~/.zen/tmp/${IPFSNODEID}/
ROUTING=$(ipfs add -rwq ~/.zen/tmp/${IPFSNODEID}/* | tail -n 1 )
echo "PUBLISHING ASTRONAUTES SIGNALING"
ipfs name publish --allow-offline -t 72h /ipfs/$ROUTING
echo "THANK YOU."
2022-09-12 14:58:08 +02:00
2022-08-25 17:21:39 +02:00
exit 0