Several bugfixes to postinstall script