How do customize settings.php during installation profile I'm creating an installation profile for my current company internal project.

During the installation process, one of the custom modules crashes during init(), since it tries to use one global variable defined on settings.php (that's current default behavior of the module)

Using system_form_install_settings_form_alter() I changed the settings form, by adding one input textfield for user's input, and on submit the value is appended to settings.php, but settings.php is rewrited before profile installation starts.

There is any way to prevent cleanup of settings.php by the installation process?
You may find it easier to use a settings.common.php

Often during team projects, we have local settings.php with db credentials etc.. and a settings.common.php with settings common to the install and deployment environments.

You can add settings.common.php with an include / require line in settings.php

require 'settings.common.php'; // same directory, e.g sites/default/settings.common.php


and then write to it as needed during install.