Modularise megphys script, making it cleaner and more easily modifiable

Pretty self-explanatory. Makes functions for each corresponding option, to make it more easily readable and modifiable. I haven't done that for `test`, because it's a shell built-in function.