Ubuntu/Debian: properly check if a package is installed or not:
dpkg-query -s <pkg> returns 0 even when status is "deinstall ok config-files".
Instead, check if the full "Status" string starts with either "install" or "hold".