Skip to content

Instantly share code, notes, and snippets.

@4DA
Last active April 30, 2021 21:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 4DA/6c11e5bc7018ae0115d1336e9f9a0505 to your computer and use it in GitHub Desktop.
Save 4DA/6c11e5bc7018ae0115d1336e9f9a0505 to your computer and use it in GitHub Desktop.
Update IPFS pin
#!/bin/bash
DIR=$1
CIDFILE="$1_cid"
IPFSOPTS="--nocopy"
DNSLINK_UPDATE="~/scripts/dnslink.sh"
if [ -f $CIDFILE ]; then
CID=`cat $CIDFILE`
echo "Current CID=$CID"
else
CID=`ipfs add -r $DIR $IPFSOPTS -Q`
echo "Computed CID = $CID"
echo $CID > $CIDFILE
fi
echo "Starting watching $DIR for changes"
while true; do
inotifywait -e modify,delete,move,close_write -r $DIR
ipfs pin rm $CID
NEWCID=`ipfs add -r $DIR $IPFSOPTS -Q`
echo "updated $CID -> $NEWCID"
CID=$NEWCID
$DNSLINK_UPDATE $CID
echo $CID > $CIDFILE
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment