Fixes for Ubuntu: template file generation, diectory permission fix