Topic: Utility to edit .deb file control data
True, if you know why you might want to edit a deb file's control data you probably know how to do it - or will after you've checked out half a dozen man pages to remind yourself of the exact commands... So if you're not doing this every day it can be handy to have a script that remebers it all for you.
Occasionally you might have downloaded a deb file with a dependency that you know you don't need, can't install or maybe doesn't exist because it's mis-spelled - whatever, gdebi or dpkg won't let you install it unless you change the dependencies in the control file. If you add this script to your Thunar custom actions, for "other files", pattern "*.deb", then it will appear in the right-click menu for .deb files, and let you make a modified file in the same directory with edited control data. Be careful. Don't do this kind of thing too often, as you can get in a real mess (as I discovered yesterday trying to install a recent vlc on #! 9.04). Even so, it can come in quite handy now and then.
This script is adapted from this Ubuntu forums thread, tweaked to be usable without a terminal (using notify-send for feedback) and a couple of other what-I-like-to-think-of-as improvements ![]()
#!/bin/bash
# edit the control data of a deb file,
# usually to get round a dependency problem
# adapted from http://ubuntuforums.org/showthread.php?t=636724
# needs libnotify-bin for notifications if used without a terminal
# choose your editor:
EDITOR=gedit
####################
[[ "$1" ]] || { echo "Syntax: $0 debfile" >&2; exit 1; }
DEBFILE="$1"
TMPDIR=$(mktemp -d /tmp/deb.XXXXXXXXXX) || exit 1
OUTPUT="${DEBFILE%.deb}".modfied-$( date +%FT%T ).deb
if [[ -e "$OUTPUT" ]]; then
echo "$0: $OUTPUT exists." >&2
rm -r "$TMPDIR"
exit 1
fi
dpkg-deb -x "$DEBFILE" "$TMPDIR"
dpkg-deb --control "$DEBFILE" "$TMPDIR"/DEBIAN
CONTROL="$TMPDIR"/DEBIAN/control
[[ -e "$CONTROL" ]] || {
echo "$0: DEBIAN/control not found in $1." >&2
[ -t 1 ] || notify-send "$1: DEBIAN/control not found."
rm -r "$TMPDIR"
exit 1
}
MOD=$(md5sum "$CONTROL")
$EDITOR "$CONTROL"
if [[ $MOD = $(md5sum "$CONTROL") ]]; then
[ -t 1 ] && echo "Not modfied."
else
[ -t 1 ] && echo "Building new deb..." || notify-send "Building new deb..." "Please wait a moment."
dpkg -b "$TMPDIR" "$OUTPUT"
[ -t 1 ] && echo "Built new debfile: $OUTPUT" || notify-send "Built new debfile:" "$OUTPUT"
fi
rm -r "$TMPDIR"
exit------------------------
( a boring Japan blog , and idle twitterings )
“Good morning sir, which way up would you like your reality today?” "As it comes, Jeeves, as it comes..."