extract a deb file, including "control" files

Need help with C, C++, perl, python, etc?

extract a deb file, including "control" files

Postby cc » 2011-02-16 00:17

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.
cc
 
Posts: 820
Joined: 2005-06-08 19:14

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

Postby Bro.Tiag » 2011-02-16 01:43

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.
User avatar
Bro.Tiag
 
Posts: 1937
Joined: 2007-06-02 19:14

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

Postby cc » 2011-02-16 02:06

Code: Select all
# dpkg-deb -e package.deb
seems to extract "control" file into "DEBIAN" directory.
cc
 
Posts: 820
Joined: 2005-06-08 19:14

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

Postby Bro.Tiag » 2011-02-16 03:45

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
User avatar
Bro.Tiag
 
Posts: 1937
Joined: 2007-06-02 19:14

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

Postby vangelis » 2011-03-21 17:29

To extract deb file,including control files use this command:
Code: Select all
 sudo dpkg -i package.deb *
vangelis
 
Posts: 2
Joined: 2011-03-13 12:57

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

Postby dzz » 2011-03-22 00:32

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?
dzz
 
Posts: 257
Joined: 2007-02-05 20:39
Location: Devon, England

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

Postby jmtd » 2011-04-14 19:24

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
User avatar
jmtd
Debian Developer
Debian Developer
 
Posts: 35
Joined: 2010-10-14 22:21

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

Postby dzz » 2011-04-15 01:19

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?
dzz
 
Posts: 257
Joined: 2007-02-05 20:39
Location: Devon, England

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

Postby eric1959 » 2011-04-15 06:05

Debian Bits And Snips
Squeeze, Gnome, amd64, Intel Core i3-530, Geforce GT330
eric1959
 
Posts: 1299
Joined: 2008-12-15 13:17
Location: Amsterdam

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

Postby nadir » 2011-04-15 10:51

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.
User avatar
nadir
 
Posts: 5964
Joined: 2009-10-05 22:06
Location: away

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

Postby dzz » 2011-04-15 11:12

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

Thanks nadir, an excellent summary.
dzz
 
Posts: 257
Joined: 2007-02-05 20:39
Location: Devon, England

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

Postby jmtd » 2011-04-15 13:41

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
jmtd
Debian Developer
Debian Developer
 
Posts: 35
Joined: 2010-10-14 22:21

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

Postby phenest » 2011-04-16 08:50

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
Dell XPS 17 L702X i7 2860QM 2.5GHz - 32GB RAM - 4G WWAN - Pioneer TD05-BDR
NEC Spirit 550 P4 3.6GHz HT - 2GB RAM - nVidia 7600GT - Pioneer BDR-209DBK
ASUS P8P67 EVO i7 3770K - 32GB RAM - 2x nVidia 660GTX SLI'd
User avatar
phenest
 
Posts: 1156
Joined: 2010-03-09 09:38
Location: The Matrix

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

Postby jmtd » 2011-04-22 11:33

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.
User avatar
jmtd
Debian Developer
Debian Developer
 
Posts: 35
Joined: 2010-10-14 22:21

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

Postby milomak » 2014-08-01 21:21

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.
iMac - MacOS and Windows 10 (Bootcamp)/ Debian Sid (External SSD)
Laptop (64-bit) - Debian Sid, Win10,
Kodi Box - Debian Sid
milomak
 
Posts: 1630
Joined: 2009-06-09 22:20


Return to Programming

Who is online

Users browsing this forum: No registered users and 2 guests

fashionable