From 6a32d892c5ebcb11d060e4061ec5471070477393 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valent=C3=ADn=20Kivachuk=20Burd=C3=A1?= Date: Wed, 4 Aug 2021 19:27:58 +0200 Subject: [PATCH] Parse envs with IPFSCONFIG prefix and set them in the config --- bin/container_daemon | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/bin/container_daemon b/bin/container_daemon index 8fe429036a7..16af0437e77 100755 --- a/bin/container_daemon +++ b/bin/container_daemon @@ -2,6 +2,7 @@ set -e user=ipfs repo="$IPFS_PATH" +ipfsEnvPrefix="IPFSCONFIG" if [ `id -u` -eq 0 ]; then echo "Changing user to $user" @@ -25,6 +26,27 @@ else ipfs config Addresses.API /ip4/0.0.0.0/tcp/5001 ipfs config Addresses.Gateway /ip4/0.0.0.0/tcp/8080 + # Set config from ENV variables + # Some examples are: + # + # IPFSCONFIG_Swarm_EnableAutoRelay=true + # IPFSCONFIG_Addresses_Swarm=[\"/ip4/0.0.0.0/tcp/4001\",\"/ip6/::/tcp/4001\"] + env | \ + while IFS='=' read -r name value; do + # Since we don't have extended pattern in busybox, will use grep + if echo $name | grep -qxwE "${ipfsEnvPrefix}(_[a-zA-Z0-9]+)+" ; then + removePrefix=${name#$ipfsEnvPrefix*} + replaceToDot=${removePrefix//_/.} + ipfsConfigArg=${replaceToDot:1} + + # Inform user what we are doing, since it could be + # a potential vector for command injections + set -x + ipfs config --json $ipfsConfigArg $value + { set +x; } 2>/dev/null + fi + done + # Set up the swarm key, if provided SWARM_KEY_FILE="$repo/swarm.key"