意外删除了 postinst、preinst、postrm 和 prerm 脚本

意外删除了 postinst、preinst、postrm 和 prerm 脚本

由于 shell 脚本出现错误,我意外地*.postinst, *.preinst, *.prerm and *.postrm从路径中删除了脚本/var/lib/dpkg/info。现在,每次尝试升级系统或安装新软件包时,我都会收到此错误。有什么想法可以修复它吗?

# apt -y upgrade
Reading package lists...
Building dependency tree...
Reading state information...
Calculating upgrade...
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
24 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Setting up apache2 (2.4.29-1ubuntu4.3) ...
/var/lib/dpkg/info/apache2.postinst: line 351: update-rc.d: command not found
dpkg: error processing package apache2 (--configure):
 installed apache2 package post-installation script subprocess returned error exit status 127
Setting up cups-daemon (2.2.7-1ubuntu2.1) ...
/var/lib/dpkg/info/cups-daemon.postinst: 150: /var/lib/dpkg/info/cups-daemon.postinst: update-rc.d: not found
dpkg: error processing package cups-daemon (--configure):
 installed cups-daemon package post-installation script subprocess returned error exit status 127
Setting up initramfs-tools (0.130ubuntu3.3) ...
/var/lib/dpkg/info/initramfs-tools.postinst: 41: /var/lib/dpkg/info/initramfs-tools.postinst: update-initramfs: not found
dpkg: error processing package initramfs-tools (--configure):
 installed initramfs-tools package post-installation script subprocess returned error exit status 127
Setting up postgresql-10 (10.5-0ubuntu0.18.04) ...
/var/lib/dpkg/info/postgresql-10.postinst: 110: /var/lib/dpkg/info/postgresql-10.postinst: invoke-rc.d: not found
dpkg: error processing package postgresql-10 (--configure):
 installed postgresql-10 package post-installation script subprocess returned error exit status 127
dpkg: dependency problems prevent configuration of cups-core-drivers:
 cups-core-drivers depends on cups-daemon (>= 2.2.7-1ubuntu2.1); however:
  Package cups-daemon is not configured yet.

dpkg: error processing package cups-core-drivers (--configure):
 dependency problems - leaving unconfigured
Setting up avahi-daemon (0.7-3.1ubuntu1.1) ...
/var/lib/dpkg/info/avahi-daemon.postinst: 19: /var/lib/dpkg/info/avahi-daemon.postinst: adduser: not found
dpkg: error processing package avahi-daemon (--configure):
 installed avahi-daemon package post-installation script subprocess returned error exit status 127
Setting up grub-common (2.02-2ubuntu8.4) ...
/var/lib/dpkg/info/grub-common.postinst: 12: /var/lib/dpkg/info/grub-common.postinst: update-rc.d: not found
dpkg: error processing package grub-common (--configure):
 installed grub-common package post-installation script subprocess returned error exit status 127
Setting up unattended-upgrades (1.1ubuntu1.18.04.5) ...
/var/lib/dpkg/info/unattended-upgrades.postinst: 111: /var/lib/dpkg/info/unattended-upgrades.postinst: update-rc.d: not found
dpkg: error processing package unattended-upgrades (--configure):
 installed unattended-upgrades package post-installation script subprocess returned error exit status 1
dpkg: dependency problems prevent configuration of avahi-utils:
 avahi-utils depends on avahi-daemon; however:
  Package avahi-daemon is not configured yet.

dpkg: error processing package avahi-utils (--configure):
 dependency problems - leaving unconfigured
Setting up apport (2.20.9-0ubuntu7.3) ...
apport-autoreport.service is a disabled or a static unit, not starting it.
/var/lib/dpkg/info/apport.postinst: 68: /var/lib/dpkg/info/apport.postinst: update-rc.d: not found
dpkg: error processing package apport (--configure):
 installed apport package post-installation script subprocess returned error exit status 127
Setting up avahi-autoipd (0.7-3.1ubuntu1.1) ...
/var/lib/dpkg/info/avahi-autoipd.postinst: 7: /var/lib/dpkg/info/avahi-autoipd.postinst: adduser: not found
dpkg: error processing package avahi-autoipd (--configure):
 installed avahi-autoipd package post-installation script subprocess returned error exit status 127
dpkg: dependency problems prevent configuration of brltty:
 brltty depends on initramfs-tools (>= 0.40ubuntu30); however:
  Package initramfs-tools is not configured yet.

dpkg: error processing package brltty (--configure):
 dependency problems - leaving unconfigured
Setting up console-setup-linux (1.178ubuntu2.7) ...
/var/lib/dpkg/info/console-setup-linux.postinst: 118: /var/lib/dpkg/info/console-setup-linux.postinst: update-rc.d: not found
dpkg: error processing package console-setup-linux (--configure):
 installed console-setup-linux package post-installation script subprocess returned error exit status 1
Setting up x11-common (1:7.7+19ubuntu7.1) ...
/var/lib/dpkg/info/x11-common.postinst: line 17: update-rc.d: command not found
dpkg: error processing package x11-common (--configure):
 installed x11-common package post-installation script subprocess returned error exit status 127
dpkg: dependency problems prevent configuration of console-setup:
 console-setup depends on console-setup-linux | console-setup-freebsd | hurd; however:
  Package console-setup-linux is not configured yet.
  Package console-setup-freebsd is not installed.
  Package hurd is not installed.

dpkg: error processing package console-setup (--configure):
 dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of grub-efi-amd64-bin:
 grub-efi-amd64-bin depends on grub-common (= 2.02-2ubuntu8.4); however:
  Package grub-common is not configured yet.

dpkg: error processing package grub-efi-amd64-bin (--configure):
 dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of grub-efi-amd64:
 grub-efi-amd64 depends on grub-common (= 2.02-2ubuntu8.4); however:
  Package grub-common is not configured yet.
 grub-efi-amd64 depends on grub-efi-amd64-bin (= 2.02-2ubuntu8.4); however:
  Package grub-efi-amd64-bin is not configured yet.

dpkg: error processing package grub-efi-amd64 (--configure):
 dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of gdm3:
 gdm3 depends on x11-common (>= 1:7.6+11); however:
  Package x11-common is not configured yet.

dpkg: error processing package gdm3 (--configure):
 dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of grub2-common:
 grub2-common depends on grub-common (= 2.02-2ubuntu8.4); however:
  Package grub-common is not configured yet.

dpkg: error processing package grub2-common (--configure):
 dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of shim-signed:
 shim-signed depends on grub2-common (>= 2.02-2ubuntu8.1); however:
  Package grub2-common is not configured yet.

dpkg: error processing package shim-signed (--configure):
 dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of cups:
 cups depends on cups-core-drivers (>= 2.2.7-1ubuntu2.1); however:
  Package cups-core-drivers is not configured yet.
 cups depends on cups-daemon (>= 2.2.7-1ubuntu2.1); however:
  Package cups-daemon is not configured yet.

dpkg: error processing package cups (--configure):
 dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of apport-gtk:
 apport-gtk depends on apport (>= 0.41); however:
  Package apport is not configured yet.

dpkg: error processing package apport-gtk (--configure):
 dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of grub-efi-amd64-signed:
 grub-efi-amd64-signed depends on grub-efi-amd64-bin (= 2.02-2ubuntu8.4); however:
  Package grub-efi-amd64-bin is not configured yet.
 grub-efi-amd64-signed depends on grub-efi-amd64 | grub-pc; however:
  Package grub-efi-amd64 is not configured yet.
  Package grub-pc is not installed.

dpkg: error processing package grub-efi-amd64-signed (--configure):
 dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of bluez-cups:
 bluez-cups depends on cups; however:
  Package cups is not configured yet.

dpkg: error processing package bluez-cups (--configure):
 dependency problems - leaving unconfigured
Errors were encountered while processing:
 apache2
 cups-daemon
 initramfs-tools
 postgresql-10
 cups-core-drivers
 avahi-daemon
 grub-common
 unattended-upgrades
 avahi-utils
 apport
 avahi-autoipd
 brltty
 console-setup-linux
 x11-common
 console-setup
 grub-efi-amd64-bin
 grub-efi-amd64
 gdm3
 grub2-common
 shim-signed
 cups
 apport-gtk
 grub-efi-amd64-signed
 bluez-cups

答案1

找到一篇好文章这里关于如何恢复损坏/删除的/var/lib/dpkg目录。

尽管您的问题似乎比完全删除目录“没有那么严重”,但那里的提示足以让您回到正轨。

大概,在你的情况下,这样做就足够了

for i in $(dpkg -l|awk '/^ii/ {print $2}')
do
    apt-get --reinstall -y install $i
done

重新创建相关文件。

相关内容