Only run apt-get update when it is needed

This refactors the debian packaging to make sure apt-get updates only
happen when they're needed.