Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I want to create a DEB file manually. I would like to just provide a folder which contains data to install, and a script to be executed after installation.

Is this possible?

share|improve this question
    
Not very good answer you choose? –  Phpdna Jan 31 '12 at 2:05
    
@David , actually i made it with "dpkg-deb" , it's much easier , that's why i picked Gilles , by listing the files in the package folder give me a clear view of file to place there. So i think his answer is better.. –  warl0ck Jan 31 '12 at 2:27
    
I've listing all the files in the package, too. –  Phpdna Jan 31 '12 at 2:47
6  
@David I mean, arguing that his answer is derivative is one thing, but "not a very good answer"? Gilles' answer is excellent; it doesn't matter if your answer was first, his is far more complete. And there's nothing wrong with taking an existing answer and expanding on it; that's a good thing –  Michael Mrozek Jan 31 '12 at 23:13

6 Answers 6

up vote 16 down vote accepted

Making a source package

My recommendation is to make a source package. Install build-essential, debhelper, dh-make. Change to the directory where the files you want to install are (the directory name must be of the form $PACKAGE-$VERSION, e.g. myapp-4.2-1 for your first attempt at packaging Myapp V4.2), and run dh_make --createorig. Answer the questions, then edit debian/rules to install the files in the right place.

  • Edit debian/copyright to add license information about your package and information on where to get the latest version (if relevant).
  • Edit debian/changelog to remove the reference to an ITP (that's only relevant if you're working for the Debian project). Rename debian/postinst.ex to debian/postinst and add your post-installation commands there. If you later update your package, run debchange -i to add a changelog entry or edit the file in Emacs (with dpkg-dev-el installed).
  • Run dpkg-buildpackage -rfakeroot -us -uc to build the package (remove -us -uc if you want to sign the package with your PGP key).

Making a binary package directly

If you decide to make a binary package directly without building it from a source package, which is not really easier because there aren't as many tools to facilitate the process, you'll need some basic familiarity with the format of deb packages. It is described in the Debian Policy Manual, in particular ch. 3 (format of binary packages), ch. 5 (control files), ch. 6 (installation scripts) and appendix B (binary package manipulation).

You make sure that your package installs the expected files /usr/share/doc/copyright (containing the license of the package contents, as well as where to find the latest version of the package) and /usr/share/doc/changelog.Debian.gz (containing the changelog of the deb package). You don't need these if you're only going to use the package in-house, but it's better to have them.

On Debian and derivatives

If you have the Debian tools available, use dpkg-deb to construct the package. In the directory containing the data to install, add a directory called DEBIAN at the top level, containing the control files and maintainer scripts.

$ ls mypackage-42
DEBIAN etc usr var
$ dpkg-deb -b mypackage-42

The hard way

If you don't have the Debian tools, build an archive of the files you want to package called data.tar.gz, a separate archive of the control files called control.tar.gz (no subdirectories), and a text file called debian-binary and containing the text 2.0.

cd mypackage-42
tar czf ../data.tar.gz [a-z]*
cd DEBIAN
tar czf ../../control.tar.gz *
cd ../..
echo 2.0 > debian-binary
ar r mypackage-42.deb debian-binary control.tar.gz data.tar.gz

You need at least a control file with the fields Package, Maintainer, Priority, Architecture, Installed-Size, Version, and any necessary dependency declaration.

The script to be executed after installation is called postinst. Be sure to make it executable. It goes alongside control.

Converting a binary package from a different format

If you already have a binary package from another distribution, you can use alien to convert it.

share|improve this answer
1  
IMO it's a copy from my anwser? What do you think? –  Phpdna Jan 31 '12 at 1:51
1  
The answer presupposes the OP knows how to use emacs. Is emacs really necessary here? For editing changelogs, I think one can use dch -i. –  Faheem Mitha Jan 31 '12 at 4:27
    
+1 for an amorphously useful answer. –  ixtmixilix Feb 12 '12 at 1:08

See the Debian Wiki on Packaging, maybe equivs (see link) already satisfies your requirements.

Wikipedia's page on the deb file format also includes many useful links.

share|improve this answer

First off you need to create a build folder and an archive of your files: tar czvf data.tar.gz files

Then in the build folder you must create a control file with some wanted informations:

 Package: xxxxxx
 Version: 0.0.1
 Section: user/hidden 
 Priority: optional
 Architecture: armel
 Installed-Size: `du -ks usr|cut -f 1`
 Maintainer: Your Name <xxx@xxx.xx>
 Description: This is optional, but creates warnings if left out

Then you can add independently preinst, postint, prerm and postrm shell scripts to control pre and post install and pre and post remove behaviour of the .deb file and then you can create the control archive with tar: tar czvf control.tar.gz control preinst postinst prerm postrm

Then you need a debian-binary file: echo 2.0 > debian-binary. In your build folder you should have now these files: debian-binary control.tar.gz and data.tar.gz.

Finally you need ar package to create the .deb file: ar -r xxx.deb debian-binary control.tar.gz data.tar.gz

share|improve this answer

I do a lot of packages, and to do a full one is not a trivial matter. On a positive note, files and scripts are much less work. You can create such a package, very simply, with a tool known as debreate.

Debreate is a really simple GUI, for just creating simple DEB packages. You can just specify which files, where they go, and if/what should execute on post/pre install/uninstall. I used to just do all my packages the standard way, but after I started using this tool, I will only go back when necessary.

share|improve this answer
$ apt-get install build-essential dh-make debhelper devscripts
$ wget http://nmap.org/dist/nmap-LAST.tar.bz2
$ tar xf nmap-LAST.tar.bz2
$ cd nmap-LAST
$ dh_make -s -e youremail@site.org -f ../nmap-LAST.tar.bz2
$ apt-get install libgtk2.0-dev flex bison libpcap0.8-dev \
  libpcre3-dev binutils-dev python-all-dev
$ dpkg-buildpackage
share|improve this answer

Ran into this with Zimbra 7 on Debian using its Ubuntu packages. (I'm stubborn, I like Debian > bUbuntu.) Not sure how I worked around this before, I'm certain I didn't have to do this when I installed this previously!

mkdir new
for i in *.deb
 do echo `date`: working on $i
 ar x $i
 cd control
 rm * 2> /dev/null
 tar -xzpvf ../control.tar.gz
 tr "_" "-" < control > control2
 mv -v control2 control
 tar -czpvf ../control.tar.gz .
 cd ..
 ar r new/$i debian-binary control.tar.gz data.tar.gz
done
rm -rf debian-binary control.tar.gz data.tar.gz control

All your new .deb files will be in new/.

Note: this was on squeeze - dpkg on wheezy has --force-bad-version now.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.