Fix some bugs in postinstall script