Skip to content

A peer-to-peer stack for code collaboration

rad-ipfs: Respects RAD_IPFS_API_URL

Thomas Scholtes313ac3415dd9
diff --git a/bin/rad-ipfs b/bin/rad-ipfs
index 8a1f687..5ea7e77 100755
--- a/bin/rad-ipfs
+++ b/bin/rad-ipfs
@@ -2,5 +2,20 @@
#
# 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
+
+if [ -n "$RAD_IPFS_API_URL" ]; then
+ api_url=$(echo "$RAD_IPFS_API_URL" | sed --quiet --regexp-extended \
+ 's/^http:\/\/([a-zA-Z0-9\-_\.]+):([0-9]{1,5})/\/dns4\/\1\/tcp\/\2/;T exit; p; :exit')
+ 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"} ipfs --api "/ip4/127.0.0.1/tcp/9301" "$@"
+IPFS_PATH=${IPFS_PATH:-"$HOME/.local/share/radicle/ipfs"} exec ipfs --api "$api_url" "$@"