Improve database password handling in shell scripts.

And consolidate common code into a library.