In the past I was trying many different linux distros. Each has its own package management systems: debian has apt, mandrake has urpmi, yellowdog has an apt front-end for rpm, suse has yast… While they all are quite similar and not difficult to use, I found that I often made mistakes because I often forgot which system I was using and the exact commands on that system. Another issue is that I wish I could keep track how I installed/removed those packages. So I wrote a simple wrapper for various package management systems. It serves two purposes:
to free me from remembering the exact commands for different systems
to help me keep track of what packages I installed
For example, when I need to install e.g. vim, I always say pkg-install vim, and the wrapper would invoke aptitude, apt-get or yum depending on the current system.
download from http://download.river-valley.com/pkgwatch/pkgwatch-1.0.tgz
unpack and run installer (as root):
edit /etc/pkgwatchrc to fit your system. You must set PWTOOL and PWDIR:
PWTOOL is the name of the package management system on your system. It must be one of the following:
PWDIR is a directory to keep track of package installation/removal.
since I use mostly debian-based systems, I set default as follows:
Instead of listing all the details, I describe the commands I use most frequently and the effect of each command.
Update the package management:
on an apt-based system this is similar to apt-get update
on an yum system this is similar to yum update
on macports (macosx) this is similar to port selfupdate
Install package vim. The details of this command will be explained later.
Remove package vim.
List all installed packages on my system:
on deb-based system this is similar to dpkg –get-selections
on rpm-based system this is similar to rpm -qa
List all files belonging to package vim.
on deb-based system this is similar to dpkg -L vim
on rpm-based system this is similar to rpm -ql vim
Find which package owns file /usr/bin/vim:
on deb-based system this is similar to dpkg -S /usr/bin/vim
on rpm-based system this is similar to rpm -qf /usr/bin/vim
Display info about package vim:
on deb-based system this is similar to dpkg -p vim
on rpm-based system this is similar to rpm -qi vim
Check whether package vim is already installed on my system:
on deb-based system this is similar to dpkg -s vim
on rpm-based system this is similar to rpm -q vim
Search for all packages containing vim in their name:
on apt-based system this is similar to apt-cache pkgnames vim
on yum-based system this is similar to yum list vim
The above commands don’t cover everything, however I find them enough for regular use. If I need something more specific, then I had no choice but use the exact command of the underlying system, for example apt.
Keep track of installed packages
Let’s again use examples to illustrate things. Assume we have a fresh debian-based system.In our /etc/pkgwatchrc we have:
Let’s install vim:
. This will invoke aptitude install vim to install vim, then create the following files:
/root/config/pkgwatch/pkglist.0: list of installed packages on the system before installing vim. This happens only when we run pkg-install for the first time.
/root/config/pkgwatch/pkglist.1: list of packages installed by aptitude:
/root/config/pkgwatch/pkglist.vim: symlink to pkglist.0
Let’s try remove vim:
. This will invoke aptitude purge vim, plus:
create a file /root/config/pkgwatch/pkglist.2: list of packages removed by aptitude:
remove the symlink /root/config/pkgwatch/pkglist.vim
While it might looks a bit confusing at the first sight, the concept of this is really simple: anytime we run pkg-install or pkg-remove, a new file pkglist.<number> will be created, with the number increased after each run. The contents of this file is the list of package being installed or removed during that run. Packages marked with + are those that have been installed, and packages marked with – are those that have been removed. Apart from that, during installation a symlink pkglist.<package-name> is created, and during removal that symlink is removed.
So the wrapper works a bit like a poor-man version control on the list of packages installed/removed. By examination of the pkglist.* files, it’s easy to find out what I did.
The wrapper is rather trivial, there are too many things to be improved and bugs to be fixed. However I find it good enough for my need. If you want to improve the scripts, please go ahead.
It’s also easy to add support for a new system. I tried this with fink and macports on macosx, and it took very little effort to get pkgwatch working on macosx.
Some back-ends are out-of-date, since I don’t use the underlying system anymore: urpmi, yast, or yum.