Skip to content

Instantly share code, notes, and snippets.

@StephanieSunshine
Last active November 14, 2018 10:26
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 StephanieSunshine/e1274aeddebe2a4a8d9d6f593c39c0e5 to your computer and use it in GitHub Desktop.
Save StephanieSunshine/e1274aeddebe2a4a8d9d6f593c39c0e5 to your computer and use it in GitHub Desktop.
tlosfs.sh -- an ipfs wrapper for Telos
#!/usr/bin/env bash
# set -x
add () {
temp_file=`mktemp`
ipfs add &> $temp_file
ipfs_hash=`awk '{ print $4; }' $temp_file`
ipfs_peers=(`ipfs swarm peers | awk -F/ '{ print $7; }'`)
ipfs_peer_count=${#ipfs_peers[@]}
replica_count=`perl -e 'use POSIX; $p='$ipfs_peer_count'; $a=$p/8; $a=$a+8; $a=$p/$a; $a=$a+2; print ceil($a)'`
for r in $(seq 1 $replica_count)
do
random_number=$(( $RANDOM % ${#ipfs_peers[@]} ))
ipfs pubsub pub ${ipfs_peers[$random_number]} $ipfs_hash
unset ipfs_peers[$random_number]
ipfs_peers=("${ipfs_peers[@]}")
done
echo $ipfs_hash
}
get() {
ipfs cat $2
}
del() {
ipfs pubsub pub unpin $2
}
error() {
echo error
}
case $1 in
add)
add;;
get)
get;;
del)
del;;
*)
error;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment