Onpremise: ./install.sh does not work on CentOS 7

Created on 12 Aug 2020  路  5Comments  路  Source: getsentry/onpremise

Starting from version 20.7.1 install.sh does not work on CentOS 7. Install script can't process line:

source <(grep -v '^#' .env | sed -E 's|^(.+)=(.*)$|: ${\1=\2}; export \1|g')

the error:

[root@sentry sentry]# source <(grep -v '^#' .env | sed -E 's|^(.+)=(.*)$|: ${\1=\2}; export \1|g')
-bash: /dev/fd/63: line 9: unexpected EOF while looking for matching `"'
-bash: /dev/fd/63: line 10: syntax error: unexpected end of file
Bug help wanted

All 5 comments

Despite error, env variables got exported correctly. My solution is to add || true at the end of line, so the error is ignored:

source <(grep -v '^#' .env | sed -E 's|^(.+)=(.*)$|: ${\1=\2}; export \1|g') || true

Thanks a lot for the report @NullIsNot0!

That's quite peculiar. Could it be due to GNU vs Linux versions of sed or grep? Or maybe an older bash version? I'd rather fix the error rather than ignore it.

Ok, I found the problem. This works fine when variables in .env file are in form:

VAR1=value1
VAR2=value2

I have made LDAP auth integration with Sentry and put LDAP specific variables in .env, so my .env file looks like (notice quotes):

VAR1=value1
VAR2=value2
LDAP_BASE_DN="OU=XX,DC=example,DC=com"
LDAP_PASSWORD="myldappassword"

It throws error when I put variables in single or double quotes. When I removed quotes, everything started to work correctly.
This works fine:

VAR1=value1
VAR2=value2
LDAP_BASE_DN=OU=XX,DC=example,DC=com
LDAP_PASSWORD=myldappassword

Even Docker Compose reads LDAP_BASE_DN value OU=XX,DC=example,DC=com correctly. I thought that multiple equal signs in one line would confuse Docker Compose, but no - it works fine. And your script also correctly exports variables with multiple equal signs in values.

Funny, but on macOS 10.15 (sed ??, grep 2.5.1) and Ubuntu 20.04 (sed 4.7, grep 3.4) this works even with quotes, but not on CentOS7 with following versions: sed 4.2.2, grep 2.20.

I think, this can be left unfixed (maybe some notice in docs about quotes when base system is CentOS7), because CentOS8 does not have this issue (I tested it myself), and everyone who use CentOS7 will switch to CentOS8 when Docker will support it.

Thanks a lot once again for the investigation! I'll keep this issue and mark it as "help needed" in case someone from the community wants to fix it.

As you did not want to close this issue (thank you for this) I went deeper on exploration to load .env file in environment vars. Problem is not in quotes, but in my LDAP_BASE_DN which contains multiple equal signs. Sed command finds last = and tries to export variable LDAP_BASE_DN="OU=XX,DC=example,DC and complains about quotes in variable name.
Tried to rewrite sed regex, but it does not support un-greedy search, that's why I started to search for working solutions. The simpliest to me seemed loading variables with source and exporting them globally, and I found this comment https://unix.stackexchange.com/a/79077 on Unix Stackexchange.

If I changed line in install.sh

source <(grep -v '^#' .env | sed -E 's|^(.+)=(.*)$|: ${\1=\2}; export \1|g')

to

set -a && . ./.env && set +a

everything works for me now. Tested on CentOS7, macOS 10.15 and Ubuntu 20.04.

Was this page helpful?
0 / 5 - 0 ratings