Skip to content

Changing the Dependencies of a Debian Package.

Sometimes a package will not install because of failing dependencies on a minor version. This can be overcome by changing the dependency file in the package.

Manual Execution

You can change the dependencies of a debian package in the following steps.

Unpack deb

Will create i.e. three files: debian-binary control.tar.gz data.tar.gz

ar x <package>.deb

Unpack control archive

Wwill create: postinst postrm preinst prerm md5sums control

Could be that not all files exist like preinst and prerm

tar xzf control.tar.gz

Fix dependencies in control using a text editor

editor control

Repack control.tar.gz file

tar c {post,pre}{inst,rm} md5sums control | gzip -c > control.tar.gz
or
tar c post{inst,rm} md5sums control | gzip -c > control.tar.gz

Repack deb: (order important!)

ar rcs <package>.deb debian-binary control.tar.gz data.tar.gz 

Scripted Execution

Create a script

#!/bin/bash
#set -x

if [[ -z "$1" ]]; then
  echo "Syntax: $0 debfile"
  exit 1
fi

if [[ ! -f "$1" ]]; then
  echo "File '$1' not found!"
  exit 1
fi


DEBFILE="$1"
TMPDIR=`mktemp -d /tmp/deb.XXXXXXXXXX` || exit 1
OUTPUT=`basename "${DEBFILE}" .deb`.modfied.deb

if [[ -e "${OUTPUT}" ]]; then
  echo "Directory '${OUTPUT}' exists!"
  rm -r "${TMPDIR}"
  exit 1
fi

dpkg-deb -x "$DEBFILE" "$TMPDIR"
dpkg-deb --control "${DEBFILE}" "${TMPDIR}"/DEBIAN

if [[ ! -e "${TMPDIR}"/DEBIAN/control ]]; then
  echo DEBIAN/control not found.
  rm -r "${TMPDIR}"
  exit 1
fi

CONTROL="$TMPDIR"/DEBIAN/control

MOD=`stat -c "%y" "${CONTROL}"`
joe -nobackup --wordwrap "${CONTROL}"

if [[ "${MOD}" == `stat -c "%y" "${CONTROL}"` ]]; then
  echo Not modfied.
else
  echo Building new deb...
  dpkg -b "${TMPDIR}" "${OUTPUT}"
fi

rm -r "$TMPDIR"