Refactor and simplify bash scripts

Simplifies run.sh by
- moving all common methods to functions.bash
- sharing the generate_settings_file function between run and
  generate-settings-file.sh
- making setting.sh into a script

Change-Id: I33ede728b64dda503a4235861987f28c5c503722