HowtoForge

pkgwatch -- A Package Management Wrapper

pkgwatch -- A Package Management Wrapper

Introduction

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:

  1. to free me from remembering the exact commands for different systems
  2. 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.

 

Installation

 

Usage examples

Instead of listing all the details, I describe the commands I use most frequently and the effect of each command.

pkg-update

Update the package management:

pkg-install vim

Install package vim. The details of this command will be explained later.

pkg-remove vim

Remove package vim.

pkg-list

List all installed packages on my system:

pkg-file vim

List all files belonging to package vim.

pkg-own /usr/bin/vim

Find which package owns file /usr/bin/vim:

pkg-info vim

Display info about package vim:

pkg-check vim

Check whether package vim is already installed on my system:

pkg-search vim

Search for all packages containing vim in their name:

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:

PWTOOL=aptitude-deb
PWDIR=/root/config/pkgwatch

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.

 

Further notes

pkgwatch -- A Package Management Wrapper