fix postgres on machines where repos don't already have files installed

builds on #1136 making it work in more environments;
improves OS detection as well as Postgres;
and patches problem where image chooser didn't work if custom template builder was supplied