Turn shutit_main entirely into functions

Moves everything that was previously running in the global scope to function scopes.
This makes it much easier to reason about what variables are being modified where, and therefore makes it easier to make small, self contained changes.

Additionally, it is now possible to import shutit without it trying to run as a script.
This is a prerequisite to using shutit as a backend for anything.