A peer-to-peer stack for code collaboration
#!/usr/bin/env bash
#
# Wrapper for the 'ipfs' command that talks to the IPFS daemon instance
# for the Radicle network.
#
# Respects the RAD_IPFS_API_URL environment variable.
set -eo pipefail
vendored_ipfs=/usr/lib/radicle/bin/ipfs
if which ipfs >/dev/null 2>/dev/null; then
ipfs=ipfs
elif [ -f "$vendored_ipfs" ]; then
ipfs=$vendored_ipfs
else
echo "ERROR: Command not found: ipfs" 1>&2
echo "To install IPFS follow the instructions here: https://docs.ipfs.io/guides/guides/install/" 1>&2
exit 1
fi
if [ -n "$RAD_IPFS_API_URL" ]; then
api_url=$(echo "$RAD_IPFS_API_URL" | sed -n -E \
-e "s/^http:\/\/([a-zA-Z0-9_\.\-]+):([0-9]{1,5})/\/dns4\/\1\/tcp\/\2/;tprint" \
-e "q" \
-e ":print" \
-e "p")
if [ -z "$api_url" ]; then
echo "Invalid value for RAD_IPFS_API_URL: $RAD_IPFS_API_URL"
exit 1
fi
else
api_url="/ip4/127.0.0.1/tcp/9301"
fi
IPFS_PATH=${IPFS_PATH:-"$HOME/.local/share/radicle/ipfs"} exec $ipfs --api "$api_url" "$@"