Writable files

There are a few raw calls to chmod on upgrade.php, this PR replace those calls with a function for better handling