apt 要求反复升级同一个软件包

apt 要求反复升级同一个软件包

我正在使用一个 shell 脚本来让我的一台服务器保持最新软件包的更新,该脚本通过 cron 作业每 3 小时运行一次,然后通过电子邮件将结果发送给我。
以下是脚本:

#!/bin/sh
export PATH=$PATH:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
DATE=`date +%F_%H:%M`
DOY=`date +%j`
FILENAME=$DATE"_Upgrade_results.log"
FILENAME=${FILENAME// /_}
FILEPATH="/Custom/logs/upgrade/$FILENAME"
apt-key update
apt-get update 
apt-get dist-upgrade -y  >"$FILEPATH"
#Mailing section removed to prevent exposing api keys. (I'm using mailgun)

有时我会在电子邮件中收到以下信息:

Reading package lists...
Building dependency tree...
Reading state information...
The following package was automatically installed and is no longer required:
  python-support
Use 'apt-get autoremove' to remove it.
The following packages will be REMOVED:
  mysql-client-5.5 mysql-server-5.5 mysql-server-core-5.5 The following NEW packages will be installed:
  libseccomp2 mysql-client-5.6 mysql-client-core-5.6 mysql-server-5.6
  mysql-server-core-5.6 python-funcsigs python-pbr The following packages have been kept back:
  rsyslog
The following packages will be upgraded:
  e2fslibs e2fsprogs ifupdown libsystemd0 libudev1 manpages mysql-common
  mysql-server python-mock python-ndg-httpsclient python-requests python-six
  python-urllib3 systemd systemd-sysv udev
16 upgraded, 7 newly installed, 3 to remove and 1 not upgraded.
Need to get 26.9 MB/27.1 MB of archives.
After this operation, 59.2 MB of additional disk space will be used.
WARNING: The following packages cannot be authenticated!
  e2fslibs e2fsprogs mysql-server mysql-client-core-5.6 mysql-common
  mysql-client-5.6 mysql-server-core-5.6 mysql-server-5.6 libseccomp2
  libsystemd0 libudev1 udev systemd ifupdown systemd-sysv manpages
  python-funcsigs python-ndg-httpsclient python-six python-pbr python-urllib3
  python-requests python-mock

下次运行脚本时,输出是干净的:

Reading package lists...
Building dependency tree...
Reading state information...
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

问题是我在不同的日子一次又一次地遇到这个部分:

The following packages will be upgraded:
  e2fslibs e2fsprogs ifupdown libsystemd0 libudev1 manpages mysql-common
  mysql-server python-mock python-ndg-httpsclient python-requests python-six
  python-urllib3 systemd systemd-sysv udev
16 upgraded, 7 newly installed, 3 to remove and 1 not upgraded.
Need to get 26.9 MB/27.1 MB of archives.
After this operation, 59.2 MB of additional disk space will be used.
WARNING: The following packages cannot be authenticated!
  e2fslibs e2fsprogs mysql-server mysql-client-core-5.6 mysql-common
  mysql-client-5.6 mysql-server-core-5.6 mysql-server-5.6 libseccomp2
  libsystemd0 libudev1 udev systemd ifupdown systemd-sysv manpages
  python-funcsigs python-ndg-httpsclient python-six python-pbr python-urllib3
  python-requests python-mock

看起来这些软件包没有升级,但是当我apt-get update && apt-get dist-upgrade通过控制台手动运行时,我得到了0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
如果有人能解释为什么会发生这种情况,我将不胜感激?
PS:我的问题与此不同

答案1

您在那里使用了apt-get-y选项。在apt-get手册页中,已经写了关于-y选项的内容

-y, --yes, --assume-yes
           Automatic yes to prompts; assume "yes" as answer to all prompts and run non-interactively. If an undesirable situation, such as changing
           a held package, trying to install a unauthenticated package or removing an essential package occurs then apt-get will abort.
           Configuration Item: APT::Get::Assume-Yes.

从您的输出中可以清楚地看出,有些包未经认证,因此apt-get中止了操作。由于它正在中止,您会一次又一次地得到相同的输出。

要强制apt-get静默安装未经身份验证的软件包,您需要使用--allow-unauthenticated现有选项-y。从手册页来看,它是

--allow-unauthenticated
       Ignore if packages can't be authenticated and don't prompt about it. This can be useful while working with local repositories, but is a
       huge security risk if data authenticity isn't ensured in another way by the user itself. The usage of the Trusted option for
       sources.list(5) entries should usually be preferred over this global override. Configuration Item: APT::Get::AllowUnauthenticated.

相关内容