「APT」- E: Sub-process /usr/bin/dpkg returned an error code (1)

问题描述

在安装 Sunloginclient 应用时,由于依赖关系无法满足,或者系统以来关系被破坏,或者其他原因,都可能产生类似如下错误:

...
  x11-session-utils xinit xorg
Use 'apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 237 not upgraded.
1 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Setting up sunloginclient (10.1.1.38139) ...
Error:unknown OS it not impl
Installation failed
dpkg: error processing package sunloginclient (--configure):
 installed sunloginclient package post-installation script subprocess returned error exit status 1
Errors were encountered while processing:
 sunloginclient
E: Sub-process /usr/bin/dpkg returned an error code (1)

问题原因

错误日志通常会提示失败的原因,失败原因也各有不同。

在我们的场景中,使用 postinst 脚本执行失败(该脚本是在安装过程中要执行的一些脚本,由于设置环境,执行作业等等)。

解决方法

1)我们比较大胆,直接修改 /var/lib/dpkg/info/sunloginclient.postinst 脚本,让安装能够通过。
2)然后,执行 apt -f install 修复
2)最后,再卸载该应用(虽然能够运行,但是它依旧是个不正常的安装,因此我们还是会卸载它)

参考文献

dpkg – How to remove/install a package that is not fully installed? – Ask Ubuntu