Best practice when automating Drupal (or other soft) installation regarding database settings
Your question sounds like you should have a look at what I call Features Configuration Management, aka FCM. FCM is not only about using Drupal's Features module, and not about Configuration Management (as introduced in Drupal version 8). Instead, it is a special case of Software Configuration Management, aka SCM, applied to Drupal.

Mostly because Features can be considered as a code generator, whereas that generated code may be considered as the build script (as in your question). Which can then also be used to be migrated through multiple environments.

Have a look at my (popular) answer to "How to use the Features module in a 3 dev environments?" for (way) more details about all this.