Astroport.ONE/tools/VOEUX.refresh.sh

97 lines
3.2 KiB
Bash
Raw Normal View History

2022-08-23 13:38:37 +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##*/}"
################################################################################
# Inspect game wishes, refresh latest IPNS version
# Backup and chain
[[ $PLAYER == "" ]] && PLAYER=$(cat ~/.zen/game/players/.current/.player 2>/dev/null)
2022-08-23 19:27:38 +02:00
############################################
2022-08-23 20:02:37 +02:00
echo "## WORLD VOEUX"
2022-08-23 19:27:38 +02:00
2022-08-23 13:38:37 +02:00
for voeu in $(ls ~/.zen/game/world/);
do
echo "VOEU : $voeu"
voeuns=$(ipfs key list -l | grep $voeu | cut -d ' ' -f1)
2022-08-23 13:38:37 +02:00
echo "http://127.0.0.1:8080/ipns/$voeuns"
echo
W=$(cat ~/.zen/game/world/$voeu/.pepper 2>/dev/null)
echo $W
mkdir -p ~/.zen/tmp/work
2022-08-24 11:40:49 +02:00
rm -f ~/.zen/tmp/work/index.html
2022-08-23 13:38:37 +02:00
echo "Getting latest online TW..."
2022-08-24 11:40:49 +02:00
ipfs --timeout 12s cat /ipns/$voeuns > ~/.zen/tmp/work/index.html
2022-08-23 13:38:37 +02:00
if [[ ! -f ~/.zen/tmp/work/index.html ]]; then
2022-08-23 19:34:47 +02:00
echo "UNAVAILABLE WISH! If you want to remove $W $voeu"
echo "ipfs key rm $voeu && rm -Rf ~/.zen/game/world/$voeu"
2022-08-23 13:38:37 +02:00
continue
2022-08-24 11:40:49 +02:00
else
# Update local copy
cp ~/.zen/tmp/work/index.html ~/.zen/game/world/$voeu/index.html
2022-08-23 13:38:37 +02:00
fi
# RECORDING BLOCKCHAIN TIC
MOATS=$(date -u +"%Y%m%d%H%M%S%4N")
cp ~/.zen/game/world/$voeu/.chain ~/.zen/game/world/$voeu/.chain.old
2022-08-24 11:40:49 +02:00
IPUSH=$(ipfs add -Hq ~/.zen/game/world/$voeu/index.html | tail -n 1)
ipfs name publish --key=${voeu} /ipfs/$IPUSH 2>/dev/null
2022-08-23 13:38:37 +02:00
echo $IPUSH > ~/.zen/game/world/$voeu/.chain
echo $MOATS > ~/.zen/game/world/$voeu/.moats
rm -Rf ~/.zen/tmp/work
if [[ -d ~/.zen/game/players/$PLAYER/voeux/$voeu ]]; then
2022-08-23 20:28:31 +02:00
echo "==========================="
echo "Voeu$W : commande de suppression"
echo "ipfs key rm $voeu
rm -Rf ~/.zen/game/world/$voeu
rm -Rf ~/.zen/game/players/$PLAYER/voeux/$voeu"
echo "==========================="
2022-08-23 19:27:38 +02:00
# read QUOI
# [[ "$QUOI" != "" ]] && ipfs key rm $voeu && rm -Rf ~/.zen/game/world/$voeu && rm -Rf ~/.zen/game/players/$PLAYER/voeux/$voeu && echo "SUPRESSION OK"
fi
2022-08-23 20:02:37 +02:00
echo "$W : http://127.0.0.1:8080/ipns/$voeuns"
2022-08-23 19:27:38 +02:00
done
############################################
2022-08-23 20:02:37 +02:00
echo "## PLAYER TW"
2022-08-23 19:27:38 +02:00
for PLAYER in $(ls ~/.zen/game/players/); do
echo "PLAYER : $PLAYER"
2022-08-23 19:27:38 +02:00
## REFRESH ASTRONAUTE TW
ASTRONAUTENS=$(cat ~/.zen/game/players/$PLAYER/.playerns)
rm -Rf ~/.zen/tmp/astro
2022-08-24 11:40:49 +02:00
mkdir -p ~/.zen/tmp/astro
ipfs --timeout 12s cat /ipns/$ASTRONAUTENS > ~/.zen/tmp/astro/index.html
2022-08-23 19:27:38 +02:00
if [ ! -s ~/.zen/tmp/astro/index.html ]; then
2022-08-23 19:27:38 +02:00
echo "ERROR IPNS TIMEOUT. Using local backup..."
2022-08-23 20:28:31 +02:00
continue
2022-08-23 19:27:38 +02:00
else
echo "Upgrade TW local copy..."
cp ~/.zen/tmp/astro/index.html ~/.zen/game/players/$PLAYER/ipfs/moa/index.html
2022-08-23 13:38:37 +02:00
fi
2022-08-24 11:40:49 +02:00
TW=$(ipfs add -Hq ~/.zen/game/players/$PLAYER/ipfs/moa/index.html | tail -n 1)
2022-08-23 19:27:38 +02:00
ipfs name publish --key=$PLAYER /ipfs/$TW
2022-08-23 20:02:37 +02:00
echo "$PLAYER : http://127.0.0.1:8080/ipns/$ASTRONAUTENS"
2022-08-23 13:38:37 +02:00
done
2022-08-23 19:27:38 +02:00
exit 0