I'm working on deployment script and my need is to replace database (or another system) credentials in configuration file.
I have PHP files with credentials like:
<?php
return [
'mysql-rw' => [
'dns' => 'mysql-rw.local',
'user' => 'local',
'password' => 'PASS__LABELONE__',
],
'mysql-ro' => [
'dns' => 'mysql-ro.local',
'user' => 'local',
'password' => 'PASS__LABELTWO__',
],
];
Also I have Bash environment variables in CI server - LABELONE and LABELTWO. I want to replace templates in file with one-line sed command, but have error or wrong substitution:
LABELONE=pass1 LABELTWO=pass2 sed -r "s/PASS__(.+)__/${!\1}/" tst.txt
bash: s/PASS__(.+)__/${!\1}/: bad substitution
My approach is:
- Find template in file
- Capture a label from it (in PASS__LBL__ it is LBL)
- Replace template with env. variable ($LBL)
How can I evaluate such dynamic variables in sed or it is unreal?