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

  • 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:

      aptitude-deb
      apt-deb
      urpm
      yast-rpm
      yum-rpm
      fink-deb
      macports-port

    • PWDIR is a directory to keep track of package installation/removal.
  • since I use mostly debian-based systems, I set default as follows:
    PWTOOL=aptitude-deb
    PWDIR=/root/config/pkgwatch

 

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:

  • 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

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:

  • on deb-based system this is similar to dpkg --get-selections
  • on rpm-based system this is similar to rpm -qa

pkg-file vim

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

pkg-own /usr/bin/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

pkg-info 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

pkg-check 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

pkg-search 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:
PWTOOL=aptitude-deb
PWDIR=/root/config/pkgwatch
  • Let's install vim:

    pkg-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:
      + vim
      + vim-runtime
    • /root/config/pkgwatch/pkglist.vim: symlink to pkglist.0
  • Let's try remove vim:

    pkg-remove vim

    . This will invoke aptitude purge vim, plus:
    • create a file /root/config/pkgwatch/pkglist.2: list of packages removed by aptitude:
      - vim
      - vim-runtime
    • 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.

 

Further notes

  • 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.
Share this page:

9 Comment(s)

Add comment

Comments

From: LinuxClassicist at: 2009-02-17 16:11:54

This is a welcome addition.


One small suggestion for aptitude: disk space is cheap. Therefore I always use:


aptitude --with-recommends [install|safe-upgrade|full-upgrade]

From: Anonymous at: 2009-02-17 01:21:22

Don't forget pacman, the Archlinux package manager, which uses .tar.gz packets.


update database and install all updates:


$ pacman -Syu


install one package from the online server:


$ pacman -S package_name


install one local package:


$ pacman -U /path/to/package.tar.gz


etc...

From: Anonymous at: 2009-02-16 22:24:24

I hope this will provide some convergence

From: ignacio at: 2009-02-16 22:35:01

Some back-ends are out-of-date, since I don't use the underlying system anymore: urpmi, yast, or yum.


So then why not use something that is kept up-to-date, such as PackageKit?

From: at: 2009-02-13 14:51:58

All hail Tony.


I have dreamed about something like this.
I hope your work will inspire others to improve the wrapper.


 


Sam


PS. Why not simply use install command? A lot easier to remember.

From: at: 2009-02-18 20:59:17

Hi,


if I happen to use arch linux, the first thing I would do after installing the OS is to add support for pacman to pkgwatch, which I expect to be quick. As said, the scripts are really simple and far from complete or bug-free. I just use it regularly and find it useful, hence would like to share it. Anyone with little familiarity with shell scripting can adapt the scripts  to his taste.

From: at: 2009-02-18 21:04:06

yes it's perhaps desirable to do so (you can look into pkgwatch and change it to your taste). I am just an old time freak who would like to keep my systems clean and small, which makes little sense today.

From: at: 2009-02-18 21:06:51

Hi,  


just install <something> would be too simple and can be confused with other commands. Hence I chose to add the pkg- prefix, to make clear that we are dealing with packages. Hope it makes sense.

From: at: 2009-02-18 21:10:45

Hi, 


because I got stuck with those pkg-* commands and I am too lazy to switch to something else :). Besides that, I prefer the simplicity of pkgwatch over any GUI tools. This is purely a personal preference.