post_install() {
  if [ ! -f /etc/xml/catalog ]; then
    xmlcatalog --noout --create /etc/xml/catalog
  fi
  _NEW=`echo $1 | sed 's|\(.*\)\-.*|\1|'`

  xmlcatalog --noout --add "rewriteSystem" \
    "http://docbook.sourceforge.net/release/xsl/${_NEW}" \
    "/usr/share/xml/docbook/xsl-stylesheets-${_NEW}" \
    etc/xml/catalog

  xmlcatalog --noout --add "rewriteURI" \
    "http://docbook.sourceforge.net/release/xsl/${_NEW}" \
    "/usr/share/xml/docbook/xsl-stylesheets-${_NEW}" \
    etc/xml/catalog &&

  xmlcatalog --noout --add "rewriteSystem" \
    "http://docbook.sourceforge.net/release/xsl/current" \
    "/usr/share/xml/docbook/xsl-stylesheets-${_NEW}" \
    etc/xml/catalog &&

  xmlcatalog --noout --add "rewriteURI" \
    "http://docbook.sourceforge.net/release/xsl/current" \
    "/usr/share/xml/docbook/xsl-stylesheets-${_NEW}" \
    etc/xml/catalog
}

post_upgrade() {
  post_remove $2
  post_install $1
}

post_remove() {
  _OLD=`echo $1 | sed 's|\(.*\)\-.*|\1|'`
  xmlcatalog --noout --del "/usr/share/xml/docbook/xsl-stylesheets-${_OLD}" etc/xml/catalog

  if [ $(vercmp $1 1.72.0-3) -lt 0 ]; then
    xmlcatalog --noout --del "/usr/share/xml/docbook" etc/xml/catalog
    xmlcatalog --noout --del "file:///etc/xml/docbook" etc/xml/catalog
  fi
}

op=$1
shift

$op $*