0

I have a bunch of packages "enhanced" by some Debian repository. Now I've disabled that repo from /etc/apt/sources.list.d and I want to re-install all packages that were "enhanced" to... whatever is available. I can get the list of packages just fine using grep, but

apt-get install --reinstall \
  $(dpkg-query -Wf '${Version}\t${Package}\n' | grep SOMEREPO | awk '{print $2}' )

reports that those packages can't be downloaded. And of course they can't — not at their current version. --reinstall --downgrade is rejected by apt. It seems that the only way to downgrade is to name a specific version (which would require even more nasty scripting for a batch of packages).

Anything I'm overlooking? Maybe aptitude can do it?

Update: I know it can be done via pinning (thanks so much, mods!), but really, that's not a solution. It's laborious, and I don't care about which specific source the downgrade comes from. I want to downgrade to whatever is available from the currently-enabled sources.

Update 2: I'm using a Debian-derivative (MX Linux), so downgrades could come from

  • Debian buster
  • buster-backports
  • the distro-specific https://mirrors.*/mx/MX-Packages/mx/repo/
usretc
  • 629

2 Answers2

2

Pin-priorities are the solution; add this either to /etc/apt/preferences, or to a new file under /etc/apt/preferences.d:

Package: *
Pin: release a=*
Pin-Priority: 1001

apt upgrade will install the latest version of any installed package that it knows about, even if it means downgrading. apt only knows about packages from the currently-configured repositories, after apt update, so this will have the desired effect.

Stephen Kitt
  • 434,908
0

For future reference, from the do as you're told, Debian department... After some furious scripting:

ps=$(for p in $(dpkg-query -Wf '${Version}\t${Package}\n' | grep REPO | awk '{print $2}'); do
  apt --quiet list $p | grep -v /now | grep / | awk '{print $1}' | head -1
done)
# this still leaves some /oldstable,oldstable broken versions
apt install --reinstall $(echo "$ps" | cut -f1 -d,)

Not that I recommend it; it's just annoying when the system gets in the way of simple tasks.

usretc
  • 629