Is there a way to easily edit control file in deb package. Doesn't matter on which system (Linux, Mac OS X etc.) Maybe someone knows a good script to make it automated?
3 Answers
Check this out: http://ubuntuforums.org/showthread.php?t=636724 Just in case that thread ever gets deleted, I'll post a copy of the code here as well:
DEBFILE="$1"
TMPDIR=`mktemp -d /tmp/deb.XXXXXXXXXX` || exit 1
OUTPUT=`basename "$DEBFILE" .deb`.modfied.deb
if [[ -e "$OUTPUT" ]]; then
echo "$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"`
vi "$CONTROL"
if [[ "$MOD" == `stat -c "%y" "$CONTROL"` ]]; then
echo Not modfied.
else
echo Building new deb...
dpkg -b "$TMPDIR" "$OUTPUT"
fi
rm -r "$TMPDIR"
Change vi
to any editor of choice. Save it as a shell script (i.e. debcontrol.sh
), make it executable (chmod +x
), and use the deb as first parameter (./debcontrol.sh xxxxx.deb
)
The script from the Ubuntu forums needs a few changes to run. Since my edit to the other post wasn't approved, here is my updated version.
#!/bin/bash
DEBFILE="$1"
TMPDIR=`mktemp -d /tmp/deb.XXXXXXXXXX` || exit 1
OUTPUT=`basename "$DEBFILE" .deb`.modified.deb
if [[ -e "$OUTPUT" ]]; then
echo "$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"`
sensible-editor "$CONTROL"
if [[ "$MOD" == `stat -c "%y" "$CONTROL"` ]]; then
echo Not modified.
else
echo Building new deb...
dpkg -b "$TMPDIR" "$OUTPUT"
fi
rm -r "$TMPDIR"
Save it as a shell script, make it executable (chmod +x videbcontrol
), and run it like so:
fakeroot videbcontrol package.deb
It's important to use fakeroot
, otherwise file ownership gets reset to the current user.
The other method works well and should be the accepted answer. I'm writing this down because not using the dpkg tools might help understand how the deb format works (an ar
archive with two tar
members) and it avoids needing fakeroot which does not work on some architectures like mipsel.
ar x libc-bin_2.36-8_ppc64el.deb
unxz control.tar.xz # because tar --append does not work with compression
tar --to-stdout -xf control.tar ./postinst > postinst
sensible-editor postinst # make edits to postinst
chmod +x postinst
tar --to-stdout -xf control.tar ./control > control
sensible-editor control # bump version in control file
tar --delete -f control.tar ./postinst ./control # avoid duplicate members
tar --append --owner=root --group=root -f control.tar ./postinst
xz control.tar
ar r test.deb debian-binary control.tar.xz data.tar.xz