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?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityMy 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. Debhelper will create the basic infrastructure needed to build a package by generating files in a subdirectory called debian
, both some mandatory files and templates for optional files. You may need to modify some of these files:
debian/rules
to build what needs building and install the files in the right place. If you just need to copy some files and not to compile stuff, just edit the file debian/install
to specify which files need to be installed where.debian/copyright
to add license information about your package and information on where to get the latest version (if relevant).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 .deb
package (remove -us -uc
if you want to sign the package with your PGP key).
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.
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
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
.
If you already have a binary package from another distribution, you can use alien to convert it.
dch -i
.
Jan 31, 2012 at 4:27
dh_make --createorig
uses, you need to export DEBEMAIL="[email protected]"
and export DEBFULLNAME="Firstname Lastname"
beforehand.
ar
from GNU binutils, which is what you'd normally have on Linux. I think this format is the same as BSD ar
. If you're using a different OS it might have a different format, but GNU binutils are usually easy to install everywhere. And the tar format likewise has to be a format understood by GNU tar, but I think it can read all the classic tar formats.
Jun 15, 2021 at 8:28
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 <[email protected]>
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
ar -r xxx.deb debian-binary control.tar.gz data.tar.gz
it could be worth to stress the order is important: control must come before data.
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.
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.
Ran into this with Zimbra 7 on Debian using its Ubuntu packages. (I'm stubborn, I like Debian > bUbuntu despite Zimbra releasing only for Ubuntu.) 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.
For quick creating of packages you can user checkinstall program. It do a instalation of program, watch changes - and create a deb or rpm package of it.
If you don't want to use official debian helpers, the termux-create-package
python script can also be used to create binary deb files as per debian policies based on yaml/json manifest files and provides some utility config parameters as well.
You can use Alien to convert to .deb format from Slackware tgz. Slackware packages are insanely simple in that they don't really do anything much more than what the OP was asking for namely, copy some files, and run a script. This would save creating the control file and so on because Alien will generate it.
mkdir pkg
pushd pkg
mkdir -p usr/local/bin install
touch usr/local/bin/xxx # <--- something to install
touch install/slack-desc # <---- optional description
cp <<script>> install/doinst.sh # <---- your post-install
tar zcvf ../xxx-1-x86_64-1.tgz *
popd
alien --to-deb --scripts xxx-1-x86_64-1.tgz
If you are unfamiliar with the Slackware package format, note that your install directory in the tarball will not be installed to the target, and if you want a .deb that does update files under /install this is probably not going to work!
$ 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 [email protected] -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
guix pack --format=deb hello
, wherehello
is the name of a Guix package to archive as a deb.