![如何隐藏软件包而不出现在 apt 系统中?](https://linux22.com/image/2213/%E5%A6%82%E4%BD%95%E9%9A%90%E8%97%8F%E8%BD%AF%E4%BB%B6%E5%8C%85%E8%80%8C%E4%B8%8D%E5%87%BA%E7%8E%B0%E5%9C%A8%20apt%20%E7%B3%BB%E7%BB%9F%E4%B8%AD%EF%BC%9F.png)
我的中出现的已卸载软件包列表aptitude
非常庞大,但其中充满了我确信我永远不会安装的软件包。例如,我的笔记本电脑使用的是英特尔显卡,因此安装xserver-xorg-video-nouveau
.所以我想永远隐藏它。这在列出 using 时很重要!~i!~v
,因为它显示了所有可供安装的包(我仍然需要知道具有标记为 UNAVAILABLE 的依赖项的包的过滤器),所以如果我可以隐藏它们,就更容易找到我尚未尝试过的包。
如果可能的话,如何让整个 apt 数据库忽略不感兴趣的包?
答案1
#!/bin/sh
# apt-filter
# Shell script for filtering the apt packages list. Useful if you don't want to
# see too many packages in your synaptic/aptitude. Improves startup time of
# both, at the expense of time taken for filtering the updates.
# © 2011 Ahmad Syukri
listpath=/var/lib/apt/lists
skiplist=/etc/apt/skiplist # This is user defined list of package to skip. Put yours there
skiplist_prev=/var/cache/apt/skiplist
statustmp=/tmp/apt-update.1
cd $listpath
if [ ! -e orig ]
then
#first time running. create the required folder
mkdir -p orig
mv *_dists_* orig
skiplist_changed=1
else
#compare current skiplist with last time's
skiplist_changed=$(diff -q $skiplist $skiplist_prev)
#delete prev skiplist, in case update fails, then it will be forced to refilter
[ -e $skiplist_prev ] && rm $skiplist_prev
fi
#check for new package lists. Save the output to list, with progress visible.
apt-get update -o Dir::State::Lists=$listpath/orig | tee $statustmp
cd orig
cp *InRelease ..
if [ ! $skiplist_changed ]
then
#skip processing package lists with no updates
#apt-get update displays "Get" for each repository that has updated
pkgs=$(grep Get $statustmp | awk '{\
if (/Packages/ && !/Diff/){\
sub(/(ht|f)tp:\/*/,"",$2);\
sub(/\//,"_",$3);\
print $2"_debian_dists_"$3"_binary-"$4"_Packages"\
}\
}')
else
#skiplist changed, must reprocess all
pkgs=$(ls *Packages 2>/dev/null)
fi
#now let the fun begin!
for pkglist in $pkgs
do
#there is chance the list failed to download, check if it exists
if [ -e $pkglist ]
then
echo Processing $pkglist...
awk '{\
skiplist = "'$skiplist'";\
if (/^Package/){\
skip = 0;\
while (!skip && (getline pkg < skiplist) > 0)\
skip=(pkg==$2);\
close(skiplist);\
};\
if (!skip) print $0\
}' $pkglist > ../$pkglist
fi
done
#finally, save state of skiplist for future comparison
cp $skiplist $skiplist_prev
只需编写脚本即可!
买者自负:
- 它将现有列表放在另一个文件夹中,而过滤后的列表将取代它们。这意味着如果通过传统方式更新,过滤列表将被破坏,并且必须再次运行过滤脚本。
- 过滤器未优化,过程可能需要很长时间。
- 较小的列表应该意味着更快的突触/能力启动,尽管我对此无法保证。
- 可能会导致许多不可安装的软件包仍在列表中。如果你知道如何过滤它们,请回答我的另一个问题!
结果
结果?我不再看到 emacs 及其奴才,也不再看到 windowmaker。谈论地球和平!
答案2
我确信现在有办法了,除非您创建自己的 APT 存储库。有很多工具可以实现这一点,我最喜欢的是复制品。设置完成后,从存储库中删除单个包就像以下一样简单:
reprepro --basedir /path/to/.custom_repo remove custom_repo_name unwanted_package
它从索引和文件系统中删除两者。之后,您当然需要更新您的 APT 列表apt-get update
。