Made script more robust to linux updates and added permission fixing code.