refactor bash scripts into functions

add some comments
Merge pull request #2563 from rolandwalker/devscript_functions

refactor bash scripts into functions