Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

extract a deb file, including "control" files

Programming languages, Coding, Executables, Package Creation, and Scripting.
Post Reply
Message
Author
cc
Posts: 820
Joined: 2005-06-08 19:14

extract a deb file, including "control" files

#1 Post by cc »

Hello

Howto extract a deb file, including "control" file using dpkg-deb?
BTW I'd like to change one file and create back a deb file.
Last edited by cc on 2011-02-16 02:06, edited 1 time in total.

User avatar
Bro.Tiag
Posts: 1924
Joined: 2007-06-02 19:14

Re: extract a deb file, including "control" files

#2 Post by Bro.Tiag »

cc wrote:Hello

Howto extract a deb file, including "control" files using dpkg-deb?
BTW I'd like to change one file and create back a deb file.
dpkg -x filename.deb target-directory will extract what is in the deb, but I'm not sure where the "control" file is.

ar -x filename.deb will give you the "control" file

-OR-


ar -t filename.deb to see what's in the deb.

cc
Posts: 820
Joined: 2005-06-08 19:14

Re: extract a deb file, including "control" files

#3 Post by cc »

Code: Select all

# dpkg-deb -e package.deb
seems to extract "control" file into "DEBIAN" directory.

User avatar
Bro.Tiag
Posts: 1924
Joined: 2007-06-02 19:14

Re: extract a deb file, including "control" files

#4 Post by Bro.Tiag »

cc wrote:

Code: Select all

# dpkg-deb -e package.deb
seems to extract "control" file into "DEBIAN" directory.
Ah, there you have it.

From the dpkg man page it says;
dpkg can also be used as a front-end to dpkg-deb(1). The following are dpkg-deb
actions, and if they are encountered, dpkg just runs dpkg-deb with the parameters
given to it:
-b, --build,
-c, --contents,
-I, --info,
-f, --field,
-e, --control,
-x, --extract,
-X, --vextract, and
--fsys-tarfile.
Please refer to dpkg-deb(1) for information about these actions.
which in turn says;
-e, --control archive [directory]
Extracts the control information files from a package archive into the speci‐
fied directory.

If no directory is specified then a subdirectory DEBIAN in the current direc‐
tory is used.

The target directory (but not its parents) will be created if necessary.
Which is why dpkg -h was criptic.
Use dpkg -b|--build|-c|--contents|-e|--control|-I|--info|-f|--field|
-x|--extract|-X|--vextract|--fsys-tarfile on archives (type dpkg-deb --help).
Thanks
Cheers

vangelis
Posts: 2
Joined: 2011-03-13 12:57

Re: extract a deb file, including "control" files

#5 Post by vangelis »

To extract deb file,including control files use this command:

Code: Select all

 sudo dpkg -i package.deb *

dzz
Posts: 257
Joined: 2007-02-05 20:39
Location: Devon, England

Re: extract a deb file, including "control" files

#6 Post by dzz »

Surely 'dpkg -i' is to install not extract? and you don't need root to extract a deb. I did read, you should use fakeroot to rebuild.

Because I always forget the syntax I keep a script to extract and rebuild. It works for me, maybe it's useful to someone. Don't run it as root.

Code: Select all

#!/bin/bash

# script name: rebuild-deb.sh
# extracts/rebuilds a deb package
# Put your deb and the script in a new directory and run it from there
# 

echo "This script extracts and rebuilds a deb package. "
echo "It should called from the directory containing the original deb and run as:"
echo "./rebuild-deb.sh"
echo
ls
echo
echo "1.	Extract deb?"
echo "2.	Make deb?"
echo "Enter <1/2> :"
read REPLY
echo

	if [ "$REPLY" = "1" ]; then
ls

DEB=$(ls *.deb 2>&1)
mkdir package
cd ./package
ar -x ../$DEB

	rm debian-binary
	tar xvzf data.tar.gz && rm data.tar.gz
	mkdir DEBIAN && cd DEBIAN
	tar xvzf ../control.tar.gz && rm ../control.tar.gz

	echo "Extracted to './package'"
	echo "Make your changes. Make sure to update control and md5sum files"	
	elif [ "$REPLY" = "2" ]; then

PACKAGE=$(cat 'package/DEBIAN/control'|grep Package|sed 's|Package: ||')
VERSION=$(cat 'package/DEBIAN/control'|grep Version|sed 's|Version: ||')
ARCH=$(cat 'package/DEBIAN/control'|grep Architecture|sed 's|Architecture: ||')
fakeroot dpkg-deb -b package $PACKAGE\_$VERSION\_$ARCH.deb
	
	echo "Done"
fi
Anyone like to test/improve it?

jmtd
Posts: 35
Joined: 2010-10-14 22:21

Re: extract a deb file, including "control" files

#7 Post by jmtd »

dzz wrote:Anyone like to test/improve it?
It's far too complicated.

Extract can be achieved with just:

dpkg-deb -x foo.deb some-dir
dpkg-deb -e foo.deb some-dir/DEBIAN

Rebuild is even simpler:

dpkg-deb -b some-dir foo.deb

dzz
Posts: 257
Joined: 2007-02-05 20:39
Location: Devon, England

Re: extract a deb file, including "control" files

#8 Post by dzz »

As well as forgetting the syntax, I did a script to also pick out what might be a long-winded name and (on rebuild) to get automatically the updated version line in the control file, hopefully reducing risk of typo errors and subsequent rage

But I like:

dpkg-deb -x foo.deb some-dir
dpkg-deb -e foo.deb some-dir/DEBIAN

better than ar -x and untar/tar and will try that in future

Is it incorrect that fakeroot should be used?

eric1959
Posts: 1298
Joined: 2008-12-15 13:17
Location: Amsterdam

Re: extract a deb file, including "control" files

#9 Post by eric1959 »

Debian Bits And Snips
Squeeze, Gnome, amd64, Intel Core i3-530, Geforce GT330

User avatar
nadir
Posts: 5961
Joined: 2009-10-05 22:06
Location: away

Re: extract a deb file, including "control" files

#10 Post by nadir »

Found this link per chance a few days ago:
http://blog.ksplice.com/author/spang/
seems like a nice summary.

btw: per chance means that someone (you know who, right?) gave me this perl link:
http://blog.ksplice.com/2010/05/top-10- ... er-tricks/
and i clicked around at that side. This was just a pointless extra-rant.
"I am not fine with it, so there is nothing for me to do but stand aside." M.D.

dzz
Posts: 257
Joined: 2007-02-05 20:39
Location: Devon, England

Re: extract a deb file, including "control" files

#11 Post by dzz »

Thanks eric1959, that's a really good method, it updates name and version change!

Thanks nadir, an excellent summary.

jmtd
Posts: 35
Joined: 2010-10-14 22:21

Re: extract a deb file, including "control" files

#12 Post by jmtd »

dzz wrote:Is it incorrect that fakeroot should be used?
Good catch. You should generally use fakeroot for the build stage: otherwise, the files inside the deb will be owned by whichever user you used to build it (and that used should generally not be "real" root).

Compare:

Code: Select all

jon@inoshiro:~/tmp/q$ dpkg-deb -c game-data-packager_26_all.deb |head -n 3
drwxr-xr-x root/root         0 2011-04-07 22:35 ./
drwxr-xr-x root/root         0 2011-04-07 22:35 ./etc/
-rw-r--r-- root/root       185 2011-03-23 10:00 ./etc/game-data-packager.conf

jon@inoshiro:~/tmp/q$ dpkg-deb -c foo.deb |head -n 3
drwxr-xr-x jon/jon           0 2011-04-15 14:38 ./
drwxr-xr-x jon/jon           0 2011-04-07 22:35 ./etc/
-rw-r--r-- jon/jon         185 2011-03-23 10:00 ./etc/game-data-packager.conf
In this example, 'foo.deb' is just 'game-data-packager_26_all.deb' unpacked (via -x and -e) and repacked (with -b), but not using fakeroot. As a result, all the files are owned by me (jon), not root. When installed, they'd spread jon-owned files over the filesystem. Probably not what you want.

User avatar
phenest
Posts: 1702
Joined: 2010-03-09 09:38
Location: The Matrix

Re: extract a deb file, including "control" files

#13 Post by phenest »

jmtd wrote:
dzz wrote:Is it incorrect that fakeroot should be used?
Good catch. You should generally use fakeroot for the build stage: otherwise, the files inside the deb will be owned by whichever user you used to build it (and that used should generally not be "real" root).

Compare:

Code: Select all

jon@inoshiro:~/tmp/q$ dpkg-deb -c game-data-packager_26_all.deb |head -n 3
drwxr-xr-x root/root         0 2011-04-07 22:35 ./
drwxr-xr-x root/root         0 2011-04-07 22:35 ./etc/
-rw-r--r-- root/root       185 2011-03-23 10:00 ./etc/game-data-packager.conf

jon@inoshiro:~/tmp/q$ dpkg-deb -c foo.deb |head -n 3
drwxr-xr-x jon/jon           0 2011-04-15 14:38 ./
drwxr-xr-x jon/jon           0 2011-04-07 22:35 ./etc/
-rw-r--r-- jon/jon         185 2011-03-23 10:00 ./etc/game-data-packager.conf
In this example, 'foo.deb' is just 'game-data-packager_26_all.deb' unpacked (via -x and -e) and repacked (with -b), but not using fakeroot. As a result, all the files are owned by me (jon), not root. When installed, they'd spread jon-owned files over the filesystem. Probably not what you want.
Good catch indeed. I was just about to ask why fakeroot was needed until your post. I have a local repo with home made debs without using fakeroot. So far, the debs are only use on my computer, but I was going to transfer it to a web site. Can I just use:

Code: Select all

fakeroot dpkg-deb -b foo_dir
ASRock H77 Pro4-M i7 3770K - 32GB RAM - Pioneer BDR-209D

jmtd
Posts: 35
Joined: 2010-10-14 22:21

Re: extract a deb file, including "control" files

#14 Post by jmtd »

phenest wrote:Good catch indeed. I was just about to ask why fakeroot was needed until your post. I have a local repo with home made debs without using fakeroot. So far, the debs are only use on my computer, but I was going to transfer it to a web site. Can I just use:

Code: Select all

fakeroot dpkg-deb -b foo_dir
Yes.

milomak
Posts: 2158
Joined: 2009-06-09 22:20
Been thanked: 1 time

Re: extract a deb file, including "control" files

#15 Post by milomak »

jmtd wrote:
dzz wrote:Anyone like to test/improve it?
It's far too complicated.

Extract can be achieved with just:

dpkg-deb -x foo.deb some-dir
dpkg-deb -e foo.deb some-dir/DEBIAN

Rebuild is even simpler:

dpkg-deb -b some-dir foo.deb
sorry to necro the thread, but this is simply one of the best things i have learnt.
Desktop: A320M-A PRO MAX, AMD Ryzen 5 3600, GALAX GeForce RTX™ 2060 Super EX (1-Click OC) - Sid, Win10, Arch Linux, Gentoo, Solus
Laptop: hp 250 G8 i3 11th Gen - Sid
Kodi: AMD Athlon 5150 APU w/Radeon HD 8400 - Sid

Post Reply