Configure Modules from a Script
Unfortunately, there is no "right" solution for Drupal 7; in Drupal 8, the configuration management initiative hopes to solve this problem.  There are a few things that you can look at to help you out.


Features: http://drupal.org/project/features:  Take database settings and write them to code, making a new module containing your settings.  Use "strongarm" module (http://drupal.org/project/strongarm) to be able to save items from the variables table in your features.  Once you have your features module, you can copy it to another site and run 'drush fr' to "revert" the feature (copy code back into the database).
Deploy: http://drupal.org/project/deploy: The counterpart of Features, it allows you to move content from one Drupal site to another.
drush generate-profile: http://drupal.org/node/1368242: Work in progress: given an existing site, creates a profile that will recreate that site.  Create your features first, then run generate-profile.  In its current state, it does a good job of creating your makefile and setting up the modules you need, but the template files that generate the profile code are not finished or working yet.  I am still working on this command, as time allows.