Script to automate IPNS republication: input welcome

This was just a quickly hacked reply over in this thread by @raucoule1u :

But I’m adding the actual script here, so if you have improvements, please chime in. (Also linking to this thread from the original one.)

#!/bin/bash
IPFS=""
IPNS_LIST=$(cat "$HOME/.ipns/ipns-pubs.txt") # change path to ipns-pubs.txt to your liking, then add hashes & their publishing keys (use 'self' for default PeerID)
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."
1 Like

There is also WIP PR to go-ipfs that solves it: https://github.com/ipfs/go-ipfs/pull/3951

3 Likes

Good news regarding the PR.

PS: now also tested my script. Seems to work, but I’m glad it won’t be necessary anymore soon. :wink:

Does it mean that the “auto-republication” for generated keys is now embedded in go-ipfs ?
And we don’t have to deal with it manually ?

That’s how I understand it, yes. Not sure, when it’ll be released.

Ok great, hope it will be soon ! :grin:

It is still Work In Progress but should be there if not in the next version then in the one after it.

2 Likes

I hope it is going to be on the next version !

It is. v0.4.10 will add republish for keys other than self. :clap: Among loads of other additions & enhancements. Wow! :tada:

1 Like

This is a great news! :slight_smile: