#!/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) ############################################ echo "## WORLD VOEUX" for voeu in $(ls ~/.zen/game/world/); do echo "VOEU : $voeu" voeuns=$(ipfs key list -l | grep $voeu | cut -d ' ' -f1) 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 rm -f ~/.zen/tmp/work/index.html echo "Getting latest online TW..." ipfs --timeout 12s cat /ipns/$voeuns > ~/.zen/tmp/work/index.html if [[ ! -f ~/.zen/tmp/work/index.html ]]; then echo "UNAVAILABLE WISH! If you want to remove $W $voeu" echo "ipfs key rm $voeu && rm -Rf ~/.zen/game/world/$voeu" continue else # Update local copy cp ~/.zen/tmp/work/index.html ~/.zen/game/world/$voeu/index.html 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 IPUSH=$(ipfs add -Hq ~/.zen/game/world/$voeu/index.html | tail -n 1) ipfs name publish --key=${voeu} /ipfs/$IPUSH 2>/dev/null 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 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 "===========================" # 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 echo "$W : http://127.0.0.1:8080/ipns/$voeuns" done ############################################ echo "## PLAYER TW" for PLAYER in $(ls ~/.zen/game/players/); do echo "PLAYER : $PLAYER" ## REFRESH ASTRONAUTE TW ASTRONAUTENS=$(cat ~/.zen/game/players/$PLAYER/.playerns) rm -Rf ~/.zen/tmp/astro mkdir -p ~/.zen/tmp/astro ipfs --timeout 12s cat /ipns/$ASTRONAUTENS > ~/.zen/tmp/astro/index.html if [ ! -f ~/.zen/tmp/astro/index.html ]; then echo "ERROR IPNS TIMEOUT. Using local backup..." continue else echo "Upgrade TW local copy..." cp ~/.zen/tmp/astro/index.html ~/.zen/game/players/$PLAYER/ipfs/moa/index.html fi TW=$(ipfs add -Hq ~/.zen/game/players/$PLAYER/ipfs/moa/index.html | tail -n 1) ipfs name publish --key=$PLAYER /ipfs/$TW echo "$PLAYER : http://127.0.0.1:8080/ipns/$ASTRONAUTENS" done exit 0