我的服务器托管在 OVH,并运行 debian Buster。我上周运行了 apt-get update 和 apt-get Upgrade ,没有出现明显的问题。但现在当我尝试再次运行它时收到一条错误消息:
sudo apt-get update
E: Syntax error /etc/apt/apt.conf.d/listchanges.conf:7: Extra junk at end of file
文件本身看起来很干净:
[apt]
frontend=pager
email_address="root"
confirm=0
save_seen=/var/lib/apt/listchanges.db
which=both
我也尝试过跑步无人值守升级-v -d --dry-run,这会返回更多关于易于配置:
Traceback (most recent call last):
File "/usr/bin/unattended-upgrade", line 75, in <module>
import apt
File "/usr/lib/python3/dist-packages/apt/__init__.py", line 34, in <module>
apt_pkg.init_config()
apt_pkg.Error: E:Syntax error /etc/apt/apt.conf.d/listchanges.conf:7: Extra junk at end of file
我该如何解除这种情况?
感谢您的帮助!
答案1
当我使用您的配置文件时,我能够重现您的问题。
man apt-listchanges
显示:
CONFIGURATION FILE
apt-listchanges reads its configuration from the /etc/apt/listchanges.conf. The
file consists of sections with names enclosed in the square brackets. Each section
should contain lines in the key=value format. Lines starting with the "#" sign are
treated as comments and ignored.
Section is a name of profile that can be used as parameter of the --profile
option.
The configuration of the "apt" section can be managed by debconf(7), and most of
the settings there can be changed with the help of the dpkg-reconfigure
apt-listchanges command.
Key is a name of some command-line option (except for --apt, --profile, --help)
with the initial hyphens removed, and the remaining hyphens translated to
underscores, for example: "email_format" or "save_seen".
Value represents the value of the corresponding option. For command-line options
that do not take argument, like "confirm" or "headers", the value should be set
either to "1", "yes", "true", and "on" in order to enable the option, or to "0",
"no", "false", and "off" to disable it.
Additionally key can be one of the following keywords: "browser", "pager" or
"xterm". The value of such configuration entry should be the name of an
appropriate command, eventually followed by its arguments, for example:
"pager=less -R".
Example 1. Example configuration file
[cmdline]
frontend=pager
[apt]
frontend=xterm-pager
email_address=root
confirm=1
[custom]
frontend=browser
browser=mozilla
The above configuration file specifies that in command-line mode, the default
frontend should be "pager". In apt mode, the xterm-pager frontend is default, a
copy of the changelogs (if any) should be emailed to root, and apt-listchanges
should ask for confirmation. If apt-listchanges is invoked with --profile=custom,
the browser frontend will be used, and invoke mozilla.
最主要的是你需要/etc/apt/apt.conf.d/listchanges.conf
搬到/etc/apt/listchanges.conf
。然后一切就应该可以了。
如果您想知道为什么这个错误会破坏 apt,apt-listchanges
(3.22)包会部署/etc/apt/apt.conf.d/20listchanges
以下内容:
$ cat 20listchanges
DPkg::Pre-Install-Pkgs { "/usr/bin/apt-listchanges --apt || test $? -lt 10"; };
DPkg::Tools::Options::/usr/bin/apt-listchanges::Version "2";
DPkg::Tools::Options::/usr/bin/apt-listchanges::InfoFD "20";
您可以看到它不是您的文件所在的 INI 格式。 man apt.conf
描述了 apt.conf 所需的文件格式。您的内容的原始翻译会产生如下结果:
Apt {
frontend pager;
email_address "root";
confirm 0;
save_seen /var/lib/apt/listchanges.db;
which both;
};
如果我将你的文件更改为这种格式,apt 会再次工作。那是因为文件格式受到尊重。也许这个文件不会做任何事情(因为 apt.conf 不读取这些密钥),但至少这就是您编写 apt.conf 文件的方式。