我在工作中使用debian wheezy。包以特定版本保存。我的/etc/apt/sources.list
包含以下行:
deb http://mycompany.com/debian/debian-main/ wheezy main non-free contrib
deb http://mycompany.com/debian/debian-security/ wheezy/updates main non-free contrib
(...)
不幸的是,我继承了这个系统的前任,出于某种原因添加了这些行:
deb http://http.debian.net/debian wheezy-backports main
deb http://http.us.debian.org/debian/ testing non-free contrib main
在尝试安装新软件之前,我没有检查过这个文件:codelite。
所以,我输入了sudo apt-get install codelite
,[enter]
,然后等到中途失败了。
现在,当我想再次使用apt-get时,我明白了:
$ sudo apt-get install vim
Reading package lists... Done
Building dependency tree
Reading state information... Done
You might want to run 'apt-get -f install' to correct these:
The following packages have unmet dependencies:
dpkg-dev : Depends: libdpkg-perl (= 1.16.15) but 1.18.23 is to be installed
jadetex : Depends: texlive-fonts-recommended but it is not going to be installed
libalgorithm-diff-xs-perl : Depends: perlapi-5.14.2
libapt-pkg-perl : Depends: perlapi-5.14.2
libblkid-dev : Depends: libblkid1 (= 2.20.1-5.3) but 2.29.2-1 is to be installed
libc-dev-bin : Depends: libc6 (< 2.14) but 2.24-10 is to be installed
libc6-dbg : Depends: libc6 (= 2.13-38+deb7u6) but 2.24-10 is to be installed
libc6-dev : Depends: libc6 (= 2.13-38+deb7u6) but 2.24-10 is to be installed
libcairo-perl : Depends: perlapi-5.14.2
libclone-perl : Depends: perlapi-5.14.2
libcrypt-blowfish-perl : Depends: perlapi-5.14.2
libcrypt-rijndael-perl : Depends: perlapi-5.14.2
libcrypt-ssleay-perl : Depends: perlapi-5.14.2
libdbd-sqlite3-perl : Depends: perlapi-5.14.2
libdbi-perl : Depends: perlapi-5.14.2
libfcgi-perl : Depends: perlapi-5.14.2
libfile-fcntllock-perl : Depends: perlapi-5.14.2
libglib-perl : Depends: perlapi-5.14.2
libgnome2-gconf-perl : Depends: perlapi-5.14.2
libgtk2-gladexml-perl : Depends: perlapi-5.14.2
libgtk2-perl : Depends: perlapi-5.14.2
libgtk2-unique-perl : Depends: perlapi-5.14.2
libhtml-parser-perl : Depends: perlapi-5.14.2
libio-pty-perl : Depends: perlapi-5.14.2
libjson-xs-perl : Depends: perlapi-5.14.2
liblist-moreutils-perl : Depends: perlapi-5.14.2
liblocale-gettext-perl : PreDepends: perlapi-5.14.2
liblzma-dev : Depends: liblzma5 (= 5.1.1alpha+20120614-2) but 5.2.2-1.2+b1 is to be installed
libnet-arp-perl : Depends: perlapi-5.14.2
libnet-dns-perl : Depends: perlapi-5.14.2
libnet-pcap-perl : Depends: perlapi-5.14.2
libnet-ssleay-perl : Depends: perlapi-5.14.2
libossp-uuid-perl : Depends: perlapi-5.14.2
libpango-perl : Depends: perlapi-5.14.2
libperl5.14 : Depends: perl-base (= 5.14.2-21+deb7u2) but 5.24.1-2 is to be installed
libselinux1-dev : Depends: libselinux1 (= 2.1.9-5) but 2.6-3+b1 is to be installed
libsnmp-perl : Depends: perlapi-5.14.2
libsocket6-perl : Depends: perlapi-5.14.2
libsub-name-perl : Depends: perlapi-5.14.2
libsvn-perl : Depends: perlapi-5.14.2
libterm-readkey-perl : Depends: perlapi-5.14.2
libtext-charwidth-perl : Depends: perlapi-5.14.2
libtext-iconv-perl : Depends: perlapi-5.14.2
libuuid-perl : Depends: perlapi-5.14.2
libxml-parser-perl : Depends: perlapi-5.14.2
libyaml-libyaml-perl : Depends: perlapi-5.14.2
locales : Depends: libc-bin (> 2.24) but 2.13-38+deb7u6 is to be installed
Depends: libc-l10n (> 2.24) but it is not going to be installed
lsof : Depends: libperl4-corelibs-perl or
perl (< 5.12.3-7) but 5.24.1-2 is to be installed
nfs-common : Depends: init-system-helpers (>= 1.18~) but it is not going to be installed
nfs-kernel-server : Depends: init-system-helpers (>= 1.18~) but it is not going to be installed
nscd : Depends: libaudit1 (>= 1:2.2.1) but it is not going to be installed
Depends: init-system-helpers (>= 1.18~) but it is not going to be installed
texinfo : Depends: tex-common (>= 6) but 3.15 is to be installed
texlive-base : Depends: texlive-binaries (>= 2012.20120516) but it is not going to be installed
Depends: luatex (>= 0.70.1)
texlive-latex-base : Depends: texlive-binaries (>= 2012-0) but it is not going to be installed
texlive-latex-extra : Depends: texlive-binaries (>= 2012-0) but it is not going to be installed
texlive-latex-recommended : Depends: texlive-binaries (>= 2012-0) but it is not going to be installed
texlive-pictures : Depends: luatex
Depends: texlive-binaries (>= 2012-0) but it is not going to be installed
texlive-pstricks : Depends: texlive-binaries (>= 2012-0) but it is not going to be installed
Recommends: texlive-extra-utils but it is not going to be installed
Recommends: texlive-font-utils but it is not going to be installed
tipa : Depends: texlive-base-bin
vim : Depends: vim-common (= 2:8.0.0197-4) but 2:7.3.547-7 is to be installed
Depends: vim-runtime (= 2:8.0.0197-4) but 2:7.3.547-7 is to be installed
Depends: libtinfo5 (>= 6) but 5.9-10 is to be installed
xmltex : Depends: texlive-binaries but it is not going to be installed
E: Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution).
当然,我尝试了sudo apt-get install -f
,但它希望删除可能会进一步破坏我的系统的内容:
The following packages will be REMOVED:
cpp-4.7 empathy evolution evolution-data-server evolution-plugins g++-4.7 gcc-4.7 gcc-4.7-base gdm3 gnome-applets gnome-color-manager gnome-contacts gnome-control-center gnome-core
gnome-documents gnome-panel gnome-session gnome-session-fallback gnome-shell gnome-shell-extensions gnome-sushi gvfs-backends libapt-inst1.5 libatk1.0-dev libaudit0 libcairo2-dev
libcanberra-pulse libcheese-gtk21 libcheese3 libfolks-eds25 libfuse-dev libgconf2-dev libgcr-3-1 libgdk-pixbuf2.0-dev libglib2.0-dev libglibmm-2.4-dev libgnome-desktop-3-2 libgnutls-dev
libgstreamer-plugins-base0.10-dev libgstreamer0.10-dev libgtk2.0-dev libgtkglext1-dev libgtksourceview-3.0-0 libjpeg62 libnss3-1d libpackagekit-glib2-14 libpango1.0-dev libpcre3-dev
libperl5.14 libpng12-dev libpulse-dev librsvg2-dev librtmp-dev libsdl1.2-dev libselinux1-dev libsnmp15 libspice-client-gtk-2.0-dev libstdc++6-4.7-dev libwebkitgtk-1.0-common
libwebkitgtk-3.0-common libxml++2.6-dev lightspark nautilus-sendto-empathy obexd-client packagekit-backend-aptcc ppp pulseaudio python-gobject-2-dev python-gtk2-dev texlive-common
texlive-doc-base xserver-xorg-input-vmmouse xserver-xorg-video-apm xserver-xorg-video-ark xserver-xorg-video-chips xserver-xorg-video-i128 xserver-xorg-video-rendition xserver-xorg-video-s3
xserver-xorg-video-s3virge xserver-xorg-video-sis xserver-xorg-video-tseng xserver-xorg-video-voodoo
好吧,长话短说,我写了一篇快速而又脏的 python脚本来帮助我回到以前的状态:
import subprocess, sys, os
rollback_datetime = "Start-Date: 2017-05-03 14:35:44"
out = "/local/DD/rollback.txt"
history = "/var/log/apt/history.log"
def is_installed(package):
try:
return "Status: install ok installed" in subprocess.check_output("dpkg -s " + package + " 2>/dev/null|grep Status", shell=True)
except:
return False
def installed_version(package):
try:
version = subprocess.check_output("dpkg -s " + package + " 2>/dev/null|grep Version:", shell=True)
return version[len("Version:"):].strip()
except:
return None
def get_apt_version(package, version):
try:
apt_version = subprocess.check_output("apt-cache show " + package + " 2>/dev/null|grep Version:|grep " + version, shell=True).split('\n')[0]
return apt_version[len("Version:"):].strip()
except:
return version
def extract(raw):
items = raw[raw.index(":"):]
items = [r[2:] for r in items.split(')') if len(r) > 2]
items = [i.split('(') for i in items]
cleaned_list = []
for package, version in items:
package = package[:-1]
if ":" in package:
package = package[:package.index(":")]
if "," in version:
version = version[:version.index(",")]
cleaned_list.append((package, version))
return cleaned_list
def add(line, console=True):
if console:
print(line)
with open (out, "a") as f:
f.write(line + "\n")
with open (history, "r") as f:
data=f.readlines()
if os.path.isfile(out):
os.remove(out)
data = data[data.index(rollback_datetime + '\n')+2:]
install, upgrade, remove = data[:3]
#print get_apt_version("vim-common", "7.3.547-7+deb7u3")
#sys.exit()
add("")
add("------- Downgrade upgraded -------")
add("sudo apt-get install " + " ".join([package + "=" + get_apt_version(package, version) for (package, version) in extract(upgrade) if installed_version(package) != version]))
add("")
add("------- Install removed -------")
add("sudo apt-get install " + " ".join([package for (package, version) in extract(remove)]))
add("")
add("------- Remove installed -------")
add("sudo apt-get remove " + " ".join([package for (package, version) in extract(install) if is_installed(package)]))
此脚本解析来自/var/log/apt/history.log
的数据并告诉我:
这是此脚本的输出:
------- Downgrade upgraded -------
sudo apt-get install libsmbclient=2:3.6.6-6+deb7u4 dmsetup=2:1.02.74-8 libpci3=1:3.1.9-6 libdpkg-perl=1.16.15 libkrb5-3=1.10.1+dfsg-5+deb7u2 vim-gui-common=2:7.3.547-7+deb7u3 libk5crypto3=1.10.1+dfsg-5+deb7u2 libpam-winbind=2:3.6.6-6+deb7u4 libmodplug1=1:0.8.8.4-3+deb7u1+git20130828 libperl-dev=5.14.2-21+deb7u2 xserver-xorg-video-all=1:7.7+3~deb7u1 vim-common=2:7.3.547-7+deb7u3 libgmp10=2:5.0.5+dfsg-2 xserver-xorg-video-ati=1:6.14.4-8 libxrandr-dev=2:1.3.2-2+deb7u1 python-numpy=1:1.6.2-1.2 libblkid1=2.20.1-5.3 libnss3=2:3.14.5-1+deb7u3 xserver-xorg-video-openchrome=1:0.2.906-2+deb7u1 libselinux1=2.1.9-5 smbclient=2:3.6.6-6+deb7u4 libsocket-perl=2.002-1 xserver-xorg-video-mga=1:1.5.0-3 libgtk2-perl=2:1.244-1+deb7u1 perl=5.14.2-21+deb7u2 nscd=2.13-38+deb7u11 cli-common=0.8.2 xserver-xorg-core=2:1.12.4-6+deb7u5 libnspr4-dev=2:4.9.2-1+deb7u2 xserver-common=2:1.12.4-6+deb7u5 libdevmapper1.02.1=2:1.02.74-8 xserver-xorg-video-trident=1:1.3.5-1 libio-pty-perl=1:1.08-1+b2 libxi-dev=2:1.6.1-1+deb7u1 texlive-extra-utils=2012.20120611-2 texlive-fonts-recommended=2012.20120611-5+deb7u1 libwbclient0=2:3.6.6-6+deb7u4 perl-base=5.14.2-21+deb7u2 libpcre3=1:8.30-5 python-apt=0.8.8.2 xserver-xorg-video-siliconmotion=1:1.7.6-1 gnome-control-center-data=1:3.4.3.1-2 g++=4:4.7.2-1 xserver-xorg-video-savage=1:2.3.4-1 xserver-xorg-video-tdfx=1:1.4.4-1 texlive-font-utils=2012.20120611-2 liblzma5=5.1.1alpha+20120614-2 vim-tiny=2:7.3.547-7+deb7u3 xserver-xorg-video-intel=2:2.19.0-6 samba-common=2:3.6.6-6+deb7u4 texlive-binaries=2012.20120628-4 libgcc1=1:4.7.2-5 xserver-xorg-input-all=1:7.7+3~deb7u1 locales=2.13-38+deb7u6 xserver-xorg-video-vmware=1:12.0.2-1+b1 cpp=4:4.7.2-1 gcc=4:4.7.2-1 xserver-xorg-input-evdev=1:2.7.0-1+b1 libkrb5support0=1.10.1+dfsg-5+deb7u2 libtirpc1=0.2.2-5 xserver-xorg-video-vesa=1:2.3.1-1+b1 pciutils=1:3.1.9-6 vim-gnome=2:7.3.547-7+deb7u3 dpkg=1.16.15 xserver-xorg=1:7.7+3~deb7u1 libglade2-0=1:2.6.4-1 libkeyutils1=1.5.5-3+deb7u1 xserver-xorg-video-fbdev=1:0.4.2-4+b3 samba=2:3.6.6-6+deb7u4 libglib-perl=3:1.260-1 libio-socket-ip-perl=0.16-2 nfs-kernel-server=1:1.2.6-4 liborc-0.4-0=1:0.4.16-2 libnspr4=2:4.9.2-1+deb7u2 tar=1.26+dfsg-0.1+deb7u1 xserver-xorg-video-nouveau=1:1.0.1-5 xserver-xorg-video-neomagic=1:1.2.6-1 liblvm2app2.2=2.02.95-8 vim=2:7.3.547-7+deb7u3 xserver-xephyr=2:1.12.4-6+deb7u5 xserver-xorg-input-mouse=1:1.7.2-3 libpq-dev=9.1.14-0+deb7u1 bash-completion=1:2.0-1 vim-runtime=2:7.3.547-7+deb7u3 libx11-6=2:1.5.0-1+deb7u1 libpq5=9.1.14-0+deb7u1 xserver-xorg-video-sisusb=1:0.9.4-3 libx11-dev=2:1.5.0-1+deb7u1 patch=2.6.1-3 xvfb=2:1.12.4-6+deb7u5 samba-common-bin=2:3.6.6-6+deb7u4 libcommon-sense-perl=3.6-1 winbind=2:3.6.6-6+deb7u4 xserver-xorg-video-radeon=1:6.14.4-8 libgssapi-krb5-2=1.10.1+dfsg-5+deb7u2 libxi6=2:1.6.1-1+deb7u1 xserver-xorg-video-cirrus=1:1.4.0-2 libc6=2.13-38+deb7u6 libnss-winbind=2:3.6.6-6+deb7u4 nfs-common=1:1.2.6-4 libxrandr2=2:1.3.2-2+deb7u1 libusb-1.0-0=2:1.0.11-1 texinfo=4.13a.dfsg.1-10
------- Install removed -------
sudo apt-get install libfuse-dev texlive-common libgraphite2-2.0.0 xserver-xorg-video-apm gnome-shell xserver-xorg-video-ark gnome-documents libgnome-desktop-3-2 libgconf2-dev libglibmm-2.4-dev gnome-applets libsnmp15 librtmp-dev evolution-plugins cheese xserver-xorg-video-s3virge evolution gvfs-backends libgstreamer-plugins-base0.10-dev xserver-xorg-video-chips g++-4.7 packagekit-backend-aptcc gedit libcheese-gtk21 gnome-session xserver-xorg-video-sis libwebkitgtk-1.0-common libselinux1-dev python-gobject-2-dev libcheese3 libgcr-3-1 python-gtk2-dev icedtea-6-jre-cacao empathy default-jre-headless perl-modules xserver-xorg-input-vmmouse libkrb5-dev libapt-inst1.5 libgstreamer0.10-dev openjdk-6-jre-lib gnome-shell-extensions luatex libcurl4-openssl-dev gcc-4.7 gnome-session-fallback openjdk-6-jre-headless libatk1.0-dev librsvg2-dev libsdl1.2-dev libgdk-pixbuf2.0-dev lightspark default-jdk libgtkglext1-dev default-jre icedtea-6-jre-jamvm libspice-client-gtk-2.0-dev gnome-bluetooth gnome-user-share libxml++2.6-dev xserver-xorg-video-s3 gdm3 libglib2.0-dev libcairo2-dev xserver-xorg-video-voodoo libpango1.0-dev libfolks-eds25 packagekit gnome-contacts gedit-plugins libjpeg62 libperl5.14 gcc-4.7-base gnome-core alsa-base libpulse-dev texlive-doc-base gnome-control-center libpcre3-dev evolution-data-server cpp-4.7 libgnutls-dev gnome-panel arping xserver-xorg-video-tseng krb5-multidev libstdc++6-4.7-dev openjdk-6-jdk libgtk2.0-dev libaudit0 openjdk-6-jre gnome-packagekit libnss3-1d libwebkitgtk-3.0-common nautilus-sendto-empathy xserver-xorg-video-rendition xserver-xorg-video-i128 libpng12-dev
------- Remove installed -------
sudo apt-get remove libxml-libxml-perl perl-modules-5.24 libperl5.24 libudev1 libssl1.1 libdb5.3 libtext-unidecode-perl
在清理和清除apt-get之后,我尝试了这些行,但是apt-get不想玩:
$ sudo apt-get remove perl-modules-5.24 libperl5.24 libudev1 libdb5.3
Reading package lists... Done
Building dependency tree
Reading state information... Done
You might want to run 'apt-get -f install' to correct these:
The following packages have unmet dependencies:
dpkg-dev : Depends: libdpkg-perl (= 1.16.15) but 1.18.23 is to be installed
git : Depends: perl-modules
jadetex : Depends: texlive-fonts-recommended but it is not going to be installed
libalgorithm-diff-xs-perl : Depends: perlapi-5.14.2
libapt-pkg-perl : Depends: perlapi-5.14.2
libblkid-dev : Depends: libblkid1 (= 2.20.1-5.3) but 2.29.2-1 is to be installed
libc-dev-bin : Depends: libc6 (< 2.14) but 2.24-10 is to be installed
libc6-dbg : Depends: libc6 (= 2.13-38+deb7u6) but 2.24-10 is to be installed
libc6-dev : Depends: libc6 (= 2.13-38+deb7u6) but 2.24-10 is to be installed
libcairo-perl : Depends: perlapi-5.14.2
libclone-perl : Depends: perlapi-5.14.2
libcrypt-blowfish-perl : Depends: perlapi-5.14.2
libcrypt-rijndael-perl : Depends: perlapi-5.14.2
libcrypt-ssleay-perl : Depends: perlapi-5.14.2
libdbd-sqlite3-perl : Depends: perlapi-5.14.2
libdbi-perl : Depends: perlapi-5.14.2
libdevmapper1.02.1 : Depends: libudev1 (>= 183) but it is not going to be installed
libfcgi-perl : Depends: perlapi-5.14.2
libfile-fcntllock-perl : Depends: perlapi-5.14.2
libglib-perl : Depends: perlapi-5.14.2
libgnome2-gconf-perl : Depends: perlapi-5.14.2
libgtk2-gladexml-perl : Depends: perlapi-5.14.2
libgtk2-perl : Depends: perlapi-5.14.2
libgtk2-unique-perl : Depends: perlapi-5.14.2
libhtml-parser-perl : Depends: perlapi-5.14.2
libio-pty-perl : Depends: perlapi-5.14.2
libjson-xs-perl : Depends: perlapi-5.14.2
liblist-moreutils-perl : Depends: perlapi-5.14.2
liblocale-gettext-perl : PreDepends: perlapi-5.14.2
liblvm2app2.2 : Depends: libudev1 (>= 183) but it is not going to be installed
liblzma-dev : Depends: liblzma5 (= 5.1.1alpha+20120614-2) but 5.2.2-1.2+b1 is to be installed
libmailtools-perl : Depends: libnet-perl
libnet-arp-perl : Depends: perlapi-5.14.2
libnet-dns-perl : Depends: perlapi-5.14.2
Depends: libmime-base64-perl
libnet-pcap-perl : Depends: perlapi-5.14.2
libnet-ssleay-perl : Depends: perlapi-5.14.2
libossp-uuid-perl : Depends: perlapi-5.14.2
libpango-perl : Depends: perlapi-5.14.2
libperl-dev : Depends: libperl5.24 (= 5.24.1-2) but it is not going to be installed
libperl5.14 : Depends: perl-base (= 5.14.2-21+deb7u2) but 5.24.1-2 is to be installed
libselinux1-dev : Depends: libselinux1 (= 2.1.9-5) but 2.6-3+b1 is to be installed
libsnmp-perl : Depends: perlapi-5.14.2
libsocket6-perl : Depends: perlapi-5.14.2
libsub-name-perl : Depends: perlapi-5.14.2
libsvn-perl : Depends: perlapi-5.14.2
libswitch-perl : Depends: perl-modules
libterm-readkey-perl : Depends: perlapi-5.14.2
libtext-charwidth-perl : Depends: perlapi-5.14.2
libtext-iconv-perl : Depends: perlapi-5.14.2
liburi-perl : Depends: libmime-base64-perl
Depends: libnet-perl
libuuid-perl : Depends: perlapi-5.14.2
libxml-parser-perl : Depends: perlapi-5.14.2
libyaml-libyaml-perl : Depends: perlapi-5.14.2
lintian : Depends: libdigest-sha-perl
locales : Depends: libc-bin (> 2.24) but 2.13-38+deb7u6 is to be installed
Depends: libc-l10n (> 2.24) but it is not going to be installed
lsof : Depends: libperl4-corelibs-perl or
perl (< 5.12.3-7) but 5.24.1-2 is to be installed
nfs-common : Depends: init-system-helpers (>= 1.18~) but it is not going to be installed
nfs-kernel-server : Depends: init-system-helpers (>= 1.18~) but it is not going to be installed
nscd : Depends: libaudit1 (>= 1:2.2.1) but it is not going to be installed
Depends: init-system-helpers (>= 1.18~) but it is not going to be installed
perl : Depends: perl-modules-5.24 (>= 5.24.1-2) but it is not going to be installed
Depends: libperl5.24 (= 5.24.1-2) but it is not going to be installed
Recommends: rename but it is not going to be installed
texinfo : Depends: libperl5.24 (>= 5.24.0) but it is not going to be installed
Depends: tex-common (>= 6) but 3.15 is to be installed
texlive-base : Depends: texlive-binaries (>= 2012.20120516) but it is not going to be installed
Depends: luatex (>= 0.70.1)
texlive-latex-base : Depends: texlive-binaries (>= 2012-0) but it is not going to be installed
texlive-latex-extra : Depends: texlive-binaries (>= 2012-0) but it is not going to be installed
texlive-latex-recommended : Depends: texlive-binaries (>= 2012-0) but it is not going to be installed
texlive-pictures : Depends: luatex
Depends: texlive-binaries (>= 2012-0) but it is not going to be installed
texlive-pstricks : Depends: texlive-binaries (>= 2012-0) but it is not going to be installed
Recommends: texlive-extra-utils but it is not going to be installed
Recommends: texlive-font-utils but it is not going to be installed
tipa : Depends: texlive-base-bin
xmltex : Depends: texlive-binaries but it is not going to be installed
E: Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution).
我现在该怎么办?
更新:我尝试了apt-get -f install
,现在我认为它真的无法修复。现在我要完全重新安装。我下次可能会尝试apt-undo
。