One of my Raspberry Pi (a Pi 2 running OSMC) threw an update error. Trying to perform a manual dist-upgrade fails with a suspicious error on the apt package itself:
Preconfiguring packages ...
/tmp/ca-certificates.config.M9vjue: 70: /tmp/ca-certificates.config.M9vjue: uniq: not found
ca-certificates failed to preconfigure, with exit status 127
(Reading database ... 30176 files and directories currently installed.)
Preparing to unpack .../archives/apt_1.4.11_armhf.deb ...
/usr/bin/dpkg-maintscript-helper: 588: /usr/bin/dpkg-maintscript-helper: basename: not found
dpkg: warning: subprocess old pre-removal script returned error exit status 127
dpkg: trying script from the new package instead ...
/usr/bin/dpkg-maintscript-helper: 588: /usr/bin/dpkg-maintscript-helper: basename: not found
dpkg: error processing archive /var/cache/apt/archives/apt_1.4.11_armhf.deb (--unpack):
subprocess new pre-removal script returned error exit status 127
Failed to try-restart apt-daily-upgrade.timer: Unit apt-daily-upgrade.timer is masked.
Failed to try-restart apt-daily.timer: Unit apt-daily.timer is masked.
/usr/bin/dpkg-maintscript-helper: 588: /usr/bin/dpkg-maintscript-helper: basename: not found
dpkg: error while cleaning up:
subprocess installed post-installation script returned error exit status 127
Errors were encountered while processing:
/var/cache/apt/archives/apt_1.4.11_armhf.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)
and further inspection confirms apt is broken:
$ sudo dpkg --configure -a
Processing triggers for libc-bin (2.24-11+deb9u4) ...
dpkg: error processing package apt (--configure):
package is in a very bad inconsistent state; you should
reinstall it before attempting configuration
Errors were encountered while processing:
apt
Removing APT (e.g. dpkg -r) for reinstallation is not really an option as rbp2-device-osmc depends on apt-utils, so it would take down the system with it.
How can I recover apt without wiping the entire installation?
apt-get install --reinstall rbp2-device-osmc. That's the only manual operation performed on it.sudo apt list --installed | grep coreutilscoreutils/oldstable,now 8.26-3 armhf [installed]