From 24d56f565e90f288776fec36a6701d86efb357b7 Mon Sep 17 00:00:00 2001 From: rbrooklyn <11929484+rbrooklyn@users.noreply.github.com> Date: Fri, 14 Feb 2020 16:43:58 +0000 Subject: [PATCH] Replace jq with our custom routine for mempool-config.json --- entrypoint.sh | 47 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index eab7121b7..937b86ac2 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,10 +1,51 @@ -#!/bin/sh +#!/bin/bash +## Start SQL mysqld_safe& sleep 5 +## http server: nginx + +## Set up some files: cd /mempool.space/backend -rm -f mempool-config.json rm -f cache.json touch cache.json -jq -n env > mempool-config.json + +## Build mempool-config.json file ourseleves. +## We used to use jq for this but that produced output which caused bugs, +## specifically numbers were surrounded by quotes, which breaks things. +## Old command was jq -n env > mempool-config.json +## This way is more complex, but more compatible with the backend functions. + +## Define a function to allow us to easily get indexes of the = string in from the env output: +strindex() { + x="${1%%$2*}" + [[ "$x" = "$1" ]] && echo -1 || echo "${#x}" +} +## Regex to check if we have a number or not: +NumberRegEx='^[0-9]+$' +## Delete the old file, and start a new one: +rm -f mempool-config.json +echo "{" >> mempool-config.json +## For each env we add into the mempool-config.json file in one of two ways. +## Either: +## "Variable": "Value", +## if a string, or +## "Variable": Value, +## if a integer +for e in `env`; do + if [[ ${e:`strindex "$e" "="`+1} =~ $NumberRegEx ]] ; then + ## Integer add: + echo "\""${e:0:`strindex "$e" "="`}"\": "${e:`strindex "$e" "="`+1}"," >> mempool-config.json + else + ## String add: + echo "\""${e:0:`strindex "$e" "="`}"\": \""${e:`strindex "$e" "="`+1}$"\"," >> mempool-config.json + fi +done +## Take out the trailing , from the last entry. +## This means replacing the file with one that is missing the last character +echo `sed '$ s/.$//' mempool-config.json` > mempool-config.json +## And finally finish off: +echo "}" >> mempool-config.json + +## Start mempoolspace: node dist/index.js