packages/pkgbuild: make pkgbuild_update more robust.

- cd to a temporary directory explicitly
- handle more corner-cases
packages/pkgbuild: small formatting change for indentational consistency.