Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env bash
- # Usage:
- # ./ipns_publish.sh keyname some_file.txt
- LIFETIME="2160h"
- # Check valid number of arguments
- if [ "$#" -ne 2 ]; then
- echo "Invalid arguments. Expected 2, got $#"
- exit 1
- fi
- # Check valid file
- if [ -z "$2" ]; then
- echo "No file specified."
- exit 1
- fi
- # Add to IPFS
- IPFS_HASH=$(ipfs add --quieter "$2")
- [ -z "$IPFS_HASH" ] && exit 1
- echo "Added $2 to IPFS. Hash: ${IPFS_HASH}"
- # Check valid key
- if [ -z "$1" ]; then
- echo "No key specified."
- exit 1
- fi
- # Publish to IPNS
- read -p "Publish to: $1? [y/n]: " choice
- case "$choice" in
- y|Y )
- IPNS_HASH=$(ipfs name publish --quieter --key "$1" --lifetime "$LIFETIME" --allow-offline "$IPFS_HASH")
- [ -z "$IPNS_HASH" ] && exit 1
- echo "Published $2 to the $1 IPNS hash: ${IPNS_HASH}"
- ;;
- * )
- echo "Exiting..."
- exit 0
- ;;
- esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement