Astroport.ONE/tools/PLAYER.refresh.sh

79 lines
3.0 KiB
Bash
Executable File

#!/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 "## PLAYER TW"
for PLAYER in $(ls ~/.zen/game/players/); do
echo "PLAYER : $PLAYER"
## REFRESH ASTRONAUTE TW
ASTRONAUTENS=$(ipfs key list -l | grep $PLAYER | cut -d ' ' -f1)
[[ ! $ASTRONAUTENS ]] && echo "Missing $PLAYER IPNS KEY -- EXIT --" && exit 1
rm -Rf ~/.zen/tmp/astro
mkdir -p ~/.zen/tmp/astro
ipfs --timeout 12s cat /ipns/$ASTRONAUTENS > ~/.zen/tmp/astro/index.html
if [ ! -s ~/.zen/tmp/astro/index.html ]; then
echo "ERROR IPNS TIMEOUT. Unchanged local backup..."
continue
else
## Replace tube links with downloaded video
$MY_PATH/TUBE.copy.sh ~/.zen/tmp/astro/index.html $PLAYER
echo "DIFFERENCE ?"
DIFF=$(diff ~/.zen/tmp/astro/index.html ~/.zen/game/players/$PLAYER/ipfs/moa/index.html)
if [[ $DIFF ]]; then
echo "Backup & Upgrade TW local copy..."
cp -f ~/.zen/game/players/$PLAYER/ipfs/moa/index.html ~/.zen/game/players/$PLAYER/ipfs/moa/index.backup.html
cp ~/.zen/tmp/astro/index.html ~/.zen/game/players/$PLAYER/ipfs/moa/index.html
else
echo "No change since last Refresh"
fi
fi
##########################
# Generate Corwdfunding Bars for each wish
for g1wish in $(ls ~/.zen/game/players/$PLAYER/voeux/); do
wishname=$(cat ~/.zen/game/players/$PLAYER/voeux/$g1wish/.title)
echo "VOEU $wishname : $g1wish"
# TOTO Install g1barre on localhost !!
G1BARRE="https://g1sms.fr/g1barre/image.php?pubkey=$g1wish&target=1000&title=$wishname&node=g1.duniter.org&start_date=2022-08-01&display_pubkey=true&display_qrcode=true&progress_color=ff07a4"
echo "LANCEZ curl $G1BARRE "
done
############################
MOATS=$(date -u +"%Y%m%d%H%M%S%4N")
[[ $DIFF ]] && cp ~/.zen/game/players/$PLAYER/ipfs/moa/.chain ~/.zen/game/players/$PLAYER/ipfs/moa/.chain.$MOATS
TW=$(ipfs add -Hq ~/.zen/game/players/$PLAYER/ipfs/moa/index.html | tail -n 1)
ipfs name publish --key=$PLAYER /ipfs/$TW
[[ $DIFF ]] && echo $TW > ~/.zen/game/players/$PLAYER/ipfs/moa/.chain
echo $MOATS > ~/.zen/game/players/$PLAYER/ipfs/moa/.moats
echo "================================================"
echo "$PLAYER : http://127.0.0.1:8080/ipns/$ASTRONAUTENS"
echo "================================================"
done
exit 0