Add setting file mode in file_write calls.
Set perms on cfg and script file.
Add cpp includes for msg types.