gen-tarball: Deduplicate directory switching
* packages/gen-tarball.sh: Extract duplicate code done in each branch of the if statement.