I'm trying to sed into phpMyAdmin config file to add a blowfish key.
Here's what I have so far...
k=$(openssl rand -base64 32)
o="\$cfg['blowfish_secret'] = '';"
n="\$cfg['blowfish_secret'] = '$k';"
sed -i -e 's/'"$o"'/'"$n"'/g' /var/www/phpmyadmin/config.inc.php
I don't get any error, but it's not working as expected.
echo -e "$k\n$o\n$n"
returns
Jgcv3FlugcVi5rDYLCdNhxX6sEZatt0zTZV3PISiLJY=
$cfg['blowfish_secret'] = '';
$cfg['blowfish_secret'] = 'Jgcv3FlugcVi5rDYLCdNhxX6sEZatt0zTZV3PISiLJY=';
And...
cat /var/www/phpmyadmin/config.inc.php | grep blowfish
returns
$cfg['blowfish_secret'] = ''; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */
Please help!
AS 123 mentioned in a comment [] characters were interpreted as character classes by sed, simply escaping it with backslash solved my problem.
So this :
k=$(openssl rand -base64 32)
o="\$cfg['blowfish_secret'] = '';"
n="\$cfg['blowfish_secret'] = '$k';"
sed -i -e 's/'"$o"'/'"$n"'/g' /var/www/phpmyadmin/config.inc.php
Was changed to that :
k=$(openssl rand -base64 32)
o="\$cfg\['blowfish_secret'\] = '';"
n="\$cfg\['blowfish_secret'\] = '$k';"
sed -i -e 's/'"$o"'/'"$n"'/g' /var/www/phpmyadmin/config.inc.php
And now it works.
EDIT :
Since openssl rand -base64 32 can generate a string with slashes, it's better to escape it right away. Also, I chose to use perl after all. Here's the corrected code:
k=$(openssl rand -base64 32 | sed 's,\/,\\/,g')
o="\$cfg\['blowfish_secret'\] = '';"
n="\$cfg\['blowfish_secret'\] = '$k';"
sudo perl -p -i -e "s/$o/$n/g" /var/www/phpmyadmin/config.inc.php
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With