astrXbian/zen/ipns_PLAYER_publish.sh

32 lines
1.8 KiB
Bash
Executable File

#!/bin/bash
########################################################################
MY_PATH="`dirname \"$0\"`" # relative
MY_PATH="`( cd \"$MY_PATH\" && pwd )`" # absolutized and normalized
ME="${0##*/}"
countMErunning=$(ps auxf --sort=+utime | grep -w $ME | grep -v -E 'color=auto|grep' | wc -l)
[[ $countMErunning -gt 2 ]] && echo "$ME already running $countMErunning time" && exit 0
########################################################################
MOATS=$(date -u +"%Y%m%d%H%M%S%4N")
PLAYER=$(cat ~/.zen/game/players/.current/.player 2>/dev/null) || ( echo "noplayer" && exit 1 )
PSEUDO=$(cat ~/.zen/game/players/.current/.pseudo 2>/dev/null) || ( echo "nopseudo" && exit 1 )
G1PUB=$(cat ~/.zen/game/players/.current/.g1pub 2>/dev/null) || ( echo "nog1pub" && exit 1 )
IPFSNODEID=$(cat ~/.zen/game/players/.current/.ipfsnodeid 2>/dev/null) || ( echo "noipfsnodeid" && exit 1 )
PLAYERNS=$(cat ~/.zen/game/players/.current/.playerns 2>/dev/null) || ( echo "noplayerns" && exit 1 )
MOANS=$(cat ~/.zen/game/players/.current/.moans 2>/dev/null) || ( echo "noplayermoans" && exit 1 )
QOOPNS=$(cat ~/.zen/game/players/.current/.qoopns 2>/dev/null) || ( echo "noplayerqoopns" && exit 1 )
ipfs --timeout=3s ls /ipns/$PLAYERNS
if [ $? != 0 ]; then
IPUSH=$(ipfs add -Hq ~/.zen/game/players/$PLAYER/index.html | tail -n 1)
echo $IPUSH > ~/.zen/game/players/$PLAYER/$PLAYER.chain
echo $MOATS > ~/.zen/game/players/$PLAYER/$PLAYER.ts
echo 1 > ~/.zen/game/players/$PLAYER/$PLAYER.n
ipfs name publish --key=${PLAYER} /ipfs/$IPUSH 2>/dev/null
else
## MISE A JOUR CACHE (TODO : ADD CHAIN TO BE ABLE TO REVERSE TIME) - "Activate archive.org"
ipfs get -o ~/.zen/game/players/$PLAYER/index.html /ipns/$PLAYERNS
fi
echo "PUBLISHED ~/.zen/ipfs TO http://127.0.0.1:8080/ipns/$PLAYERNS"