astrXbian/zen/ipns_self_publish.sh

39 lines
1.9 KiB
Bash
Executable File
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/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
########################################################################
IPFSNODEID=$(ipfs --timeout=20s id -f='<id>\n')
[[ $IPFSNODEID == "" ]] && echo "ipfs TIMEOUT" && exit 1
########################################################################
## TESSERACT DOUBLE ACTION
########################################################################
echo "Adding ~/.zen/ipfs to IPFS"
# MIPFS=$(ipfs add -rHq ~/.zen/ipfs | tail -n 1)
# OLDCHAIN=$(cat ~/.zen/ipfs/.${IPFSNODEID}/.chain)
# echo "OLD: $OLDCHAIN != NEW:$MIPFS ?"
# if [[ "$OLDCHAIN" != "$MIPFS" ]] # MODIFY CHAIN only if something was changed
# then
echo "$(date -u +%s%N | cut -b1-13)" > ~/.zen/ipfs/.${IPFSNODEID}/.timestamp
echo $MIPFS > ~/.zen/ipfs/.${IPFSNODEID}/.chain
MIPFS=$(ipfs add -rHq ~/.zen/ipfs | tail -n 1)
NODEIPNS=$(ipfs --timeout=180s name publish --quieter /ipfs/$MIPFS)
echo "$NODEIPNS:TIME:$(cat ~/.zen/ipfs/.${IPFSNODEID}/.timestamp):CHAIN:$(cat ~/.zen/ipfs/.${IPFSNODEID}/.chain)"
# fi
echo "PUBLISHED ~/.zen/ipfs TO http://127.0.0.1:8181/ipns/$IPFSNODEID"
########################################################################
## READ BLOCK CHAIN ##
# TIME=$(ipfs cat /ipns/${IPFSNODEID}/.${IPFSNODEID}/.timestamp)
# BLOCK=$(ipfs cat /ipns/${IPFSNODEID}/.${IPFSNODEID}/.chain)
# while [[ $BLOCK ]]
# do
# TIME=$(ipfs cat /ipfs/$BLOCK/.${IPFSNODEID}/.timestamp)
# BLOCK=$(ipfs cat /ipfs/$BLOCK/.${IPFSNODEID}/.chain)
# echo $TIME:$BLOCK
# done
########################################################################