fixed some errors with using the wrong variables
better creation of directories.

make sure they exist, but don't bomb if they do. be idempotent.

also, actually write config file. use mode 0700. etc.
got configuration writing working mostliy