Factor out duplicated code from setup.pm and patch-release-upgrade.pl