Skip to content

Instantly share code, notes, and snippets.

@junaidpv
Created October 26, 2022 07:34
Show Gist options
  • Save junaidpv/7d188264e43e02aeafef96abcaa5018c to your computer and use it in GitHub Desktop.
Save junaidpv/7d188264e43e02aeafef96abcaa5018c to your computer and use it in GitHub Desktop.
Script showing how db credentials in drushrc.php of an Aegir site can be updated.
<?php
$password = 'blahblahblacksheep1';
$user = 'db_user';
$db_name = 'test';
$lines = file('drushrc.php');
foreach ($lines as $index => $line) {
if (preg_match('/^\$options\[\'db_passwd\'\]\s*\=\s*\'.*?\'\s*\;/', $line)) {
$lines[$index] = "\$options['db_passwd'] = '$password';\n";
}
elseif (preg_match('/^\$options\[\'db_name\'\]\s*\=\s*\'.*?\'\s*\;/', $line)) {
$lines[$index] = "\$options['db_name'] = '$db_name';\n";
}
elseif (preg_match('/^\$options\[\'db_user\'\]\s*\=\s*\'.*?\'\s*\;/', $line)) {
$lines[$index] = "\$options['db_user'] = '$user';\n";
}
}
$new_file = file_put_contents('drushrc.php', implode('', $lines));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment