You could (if you’re on macOS) create a LaunchAgent that runs e.g. every 4 hours and automates the “republication”. See the script below, but I’m not sure if that’s all that’s needed (I haven’t tested it). If IPFS isn’t yet running, it would run ipfs daemon
and wait 5 seconds before starting the repub loop; I guess that’s time enough. And you would need a text file $HOME/.ipns/ipns-pubs.txt, a path you can obviously change. In that text file you would need one line for each IPNS publication, each with two columns, the first column with the current IPFS parent hash, and the second column with the key that you’re using to (re-) publish that IPFS hash; use “self” if you’re publishing an IPFS hash using your default PeerID. /usr/local/bin
needs to be in your $PATH
, of course… or your $GOPATH
, if you’ve built go-ipfs yourself.
#!/bin/bash
IPFS=""
IPNS_LIST=$(cat "$HOME/.ipns/ipns-pubs.txt")
if [[ "$IPNS_LIST" == "" ]] ; then
echo "No hashes to republish."
echo "Exiting."
exit
fi
if [[ $(ps aux | /usr/bin/grep "ipfs daemon" | grep -v "/usr/bin/grep ipfs daemon") == "" ]] ; then
echo "IPFS daemon not running. Starting now..."
ipfs daemon &
sleep 5
IPFS="start"
else
echo "IPFS daemon already running."
fi
while read -r LINE
do
[[ "$LINE" == "" ]] && continue
IPFS_HASH=$(echo "$LINE" | awk '{print $1}')
IPNS_KEY=$(echo "$LINE" | awk '{print $2}')
[[ "$IPNS_KEY" == "" ]] && continue
echo "Now publishing $IPFS_HASH with $IPNS_KEY"
if [[ "$IPNS_KEY" == "self" ]] ; then
ipfs name publish /ipfs/"$IPFS_HASH"
else
ipfs name publish --key="$IPNS_KEY" /ipfs/"$IPFS_HASH"
fi
done < <(echo "$IPNS_LIST")
if [[ "$IPFS" == "start" ]] ; then
echo "Stopping IPFS daemon..."
killall ipfs
fi
echo "Done."