#!/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
Just script it!
Caveat emptor:
- It puts existing lists in another folder, while the filtered ones take their place. This means if updated via conventional means, the filtered lists will be destroyed, and filter script must be run again.
- The filter isn't optimized, process may take long time.
- Smaller list should mean faster synaptic/aptitude startup, though I have no guarantee on that.
- May result in many non-installable packages which still are on the list. If you know how to filter them, please answer on my other question!
Outcome
The result? I no longer see emacs and its minions, no more windowmaker. Talk about peace on earth!