Browse Source

refactor entrypoint.sh: use new function `ipfs_config_jq_edit`

Fabian Peter Hammerle 5 years ago
parent
commit
5e7a86fb5b
1 changed files with 9 additions and 9 deletions
  1. 9 9
      entrypoint.sh

+ 9 - 9
entrypoint.sh

@@ -2,30 +2,30 @@
 
 export IPFS_CONFIG_PATH="$IPFS_PATH/config"
 
+function ipfs_config_jq_edit {
+    tmp=$(mktemp)
+    (set -x; jq "$@" < "$IPFS_CONFIG_PATH" > "$tmp")
+    mv "$tmp" "$IPFS_CONFIG_PATH"
+}
+
 if [ ! -e "$IPFS_CONFIG_PATH" ]; then
     (set -x; ipfs init --empty-repo --profile $IPFS_INIT_PROFILE)
 fi
 
 if [ "$IPFS_API_ADDR" != "default" ]; then
-    tmp=$(mktemp)
-    (set -x; jq '.Addresses.API = $ARGS.positional[0]' --args "$IPFS_API_ADDR" <"$IPFS_CONFIG_PATH" >$tmp)
-    mv $tmp "$IPFS_CONFIG_PATH"
+    ipfs_config_jq_edit '.Addresses.API = $ARGS.positional[0]' --args "$IPFS_API_ADDR"
 fi
 
 if [ "$IPFS_SWARM_ADDRS" != "default" ]; then
     # + ipfs config --json Addresses.Swarm '["/ip4/0.0.0.0/tcp/4001"]'
     # Error: api not running
-    tmp=$(mktemp)
-    (set -x; jq '.Addresses.Swarm |= $ARGS.positional' --args $IPFS_SWARM_ADDRS <"$IPFS_CONFIG_PATH" >$tmp)
-    mv $tmp "$IPFS_CONFIG_PATH"
+    ipfs_config_jq_edit '.Addresses.Swarm |= $ARGS.positional' --args $IPFS_SWARM_ADDRS
 fi
 
 if [ ! -z "$IPFS_BOOTSTRAP_ADD" ]; then
     # + ipfs bootstrap add -- /dnsaddr/...
     # Error: api not running
-    tmp=$(mktemp)
-    (set -x; jq '.Bootstrap |= (. + $ARGS.positional | unique)' --args $IPFS_BOOTSTRAP_ADD <"$IPFS_CONFIG_PATH" >$tmp)
-    mv $tmp "$IPFS_CONFIG_PATH"
+    ipfs_config_jq_edit '.Bootstrap |= (. + $ARGS.positional | unique)' --args $IPFS_BOOTSTRAP_ADD
 fi
 
 (set -x; exec "$@")