<div dir="ltr"><div><div>Thank you very much for this invaluable answer !!<br><br></div>I'm gonna try it as soon as possible.<br><br></div>Thanks again.<br></div><div class="gmail_extra"><br><br><div class="gmail_quote">
2014/1/17 A J Stiles <span dir="ltr"><<a href="mailto:asterisk_list@earthshod.co.uk" target="_blank">asterisk_list@earthshod.co.uk</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">On Friday 17 January 2014, Olivier wrote:<br>
> 2014/1/16 A J Stiles <<a href="mailto:asterisk_list@earthshod.co.uk">asterisk_list@earthshod.co.uk</a>><br>
</div><div class="im">> > If you need to install something on several boxen, you can make your own<br>
> > .deb<br>
> > package -fairly- easily --<br>
><br>
> For a complete packager beginner, how much time would it (very roughly)<br>
> take to its first .deb package ?<br>
<br>
</div>There is plenty of information out there on the Internet  (and to be quite<br>
honest I have to check everytime I do this, because it's a bit of a rarity),<br>
but here's my quick executive summary of the process.  There are other ways to<br>
do it and if you find one that works better for you, feel free to use that<br>
method.<br>
<br>
<br>
We are going to create a package "wibble_1.1-1_all.deb".  This is a trivial<br>
example, and just prints a silly message; but what is special about it is, the<br>
same package can be installed on 32-bit, 64-bit and Raspberry Pi<br>
architectures.  (It most probably will work on other architectures too, but I<br>
have no way to test this at the moment.)<br>
<br>
1.  Make a folder in which to hold the files for your package, named after the<br>
package itself with version number  (see how other people's .deb files are<br>
named),  and navigate to there;<br>
<br>
$ mkdir wibble_1.1-1_all<br>
$ cd wibble_1.1-1_all<br>
<br>
2.  Make a folder structure consisting of everything that the package is going<br>
to install, but under here instead of under / .  So for example there may be<br>
folders usr/ , usr/bin/ , usr/lib/ , usr/share/ , etc/ and so forth.<br>
("wibble" doesn't have any configuration files, so it doesn't need anything<br>
under /etc/ .)<br>
<br>
Important:  Your package *must* have been built to install under /usr/ and<br>
*not* under /usr/local/ !  /usr/local/ is supposed to be off limits to .deb<br>
packages!<br>
<br>
In order to work out what you need to put here, look at the Makefile and see<br>
what it installs.<br>
<br>
<br>
My package "wibble" consists of the following:<br>
<br>
usr/src/wibble-1.1/wibble.c :<br>
#include <stdio.h><br>
int main() {<br>
    printf("Wibble!\n");<br>
};<br>
<br>
And that's almost all there is to it.  I said it was a trivial example.<br>
<br>
3.  Make sure you have a folder under usr/share/doc/*/ with "changelog" and<br>
"copyright" files.<br>
<br>
usr/share/doc/wibble/changelog :<br>
wibble (1:1.1) stable; urgency=low<br>
First .deb version of package.<br>
<br>
usr/share/doc/wibble/copyright :<br>
This package is licenced under a "Don't Ask, Don't Tell" licence.<br>
<br>
Don't ask us for permission to copy it, and we won't tell you not to .....<br>
<br>
4.  Create a tarball "data.tar.gz" with your folder structure in it.  This is<br>
going to get extracted under / as part of the installation process.  Now, a<br>
.deb file is also supposed to include a file with the MD5 sums of all files in<br>
data.tar.gz.  We can use the power of bash to create the tarball and the<br>
MD5sums file in one operation;<br>
<br>
$ md5sum $(tar cvzf data.tar.gz usr | awk '!/\/$/{print}') > md5sums<br>
<br>
Now, this needs explaining.<br>
The inner command is<br>
tar cvzf data.tar.gz usr<br>
(obviously, if you have other folders beside usr, include these too)<br>
and the v makes it list the files it added to the archive.  This output then<br>
gets piped through an awk filter:<br>
awk '!/\/$/{print}'<br>
which passes through only lines that don't end with a / character  (lines<br>
ending in / are folders).  The $() wrapped around this pipeline command runs<br>
the commands between the round brackets, and passes the final output  (i.e.,<br>
all the files processed by tar, but no folders)  to the command which is using<br>
it as an argument -- in this case, md5sum .  So what this does is, it takes<br>
the md5sum of every file  (but not the folders)  that is being added to the tar<br>
archive.  Finally, the more-than sign > directs the output into a file called<br>
"md5sums".<br>
<br>
5.  Create a file "control" explaining the package.  Here is mine:<br>
Package: wibble<br>
Version: 1:1.1<br>
Architecture: all<br>
Maintainer: AJS <<a href="mailto:adam@priceengines.co.uk">adam@priceengines.co.uk</a>><br>
Installed-Size: 123<br>
Depends: build-essential<br>
Section: stuff<br>
Priority: standard<br>
Homepage: <a href="http://blog.earthshod.co.uk/" target="_blank">http://blog.earthshod.co.uk/</a><br>
Description: Just prints "wibble", which isn't very fantastic.  What is<br>
 special about this package is, the same package should install correctly on<br>
 32-bit, 64-bit or Raspberry Pi architectures.  (And others, but these have<br>
 not been tested for want of suitable candidate hardware.)<br>
<br>
You will need to refer to other documentation online here.  What is most<br>
important is the "Depends:" line.  Here you list every package that your<br>
package depends on.  If you get this right, then it will always pull in all<br>
the packages it needs to install, even on a totally pristine, minimal system.<br>
(Raspberry Pi users have the advantage here, because it is so quick and easy<br>
to clone an SD card.)  In particular, the "Installed-Size:123" is wrong  (but<br>
it seems to work in spite of this).  Where storage space is tight, it will be<br>
more important to get this right.  Note also that continuation lines  (as<br>
after Description: above)  start with a space.<br>
<br>
6.  Create shell scripts "postinst"  (which runs after data.tar.gz is<br>
unpacked, and finishes off the installation process)  and "prerm"  (which runs<br>
first thing before you uninstall the package, and is supposed to tidy things<br>
up).  Here we are actually going to install the Source Code under /usr/src/<br>
and then build it in the postinst script.  This is going to create files that<br>
were not in data.tar.gz, so we have to remove them in the prerm script.<br>
<br>
Don't forget to run chmod +x on these scripts.<br>
<br>
prerm:<br>
#!/bin/bash<br>
rm -rf /usr/src/wibble-1.1/<br>
rm -f /usr/bin/wibble<br>
<br>
postinst:<br>
#!/bin/bash<br>
OLDPWD=$(pwd)<br>
cd /usr/src/wibble-1.1<br>
gcc -owibble wibble.c<br>
install -c -m755 wibble /usr/bin<br>
cd "$OLDPWD"<br>
<br>
7.  Now you have to make an archive called "control.tar.gz" which contains the<br>
"control" file, the prerm and postinst scripts and the md5sums file:<br>
<br>
$ tar cvzf control.tar.gz control prerm postinst md5sums<br>
<br>
8.  Create a file called "debian-binary" which just tells dpkg the version of<br>
the .deb format.  This should contain the characters "2.0" followed by a line<br>
break.  Don't bother using your favourite editor; just type<br>
<br>
$ echo "2.0" > debian-binary<br>
<br>
9.  Now we are ready to make the .deb file!  We will create it outside the<br>
folder so as not to pollute its structure.<br>
<br>
$ ar rv ../$(basename $PWD).deb debian-binary control.tar.gz data.tar.gz<br>
$() runs a command and uses its output.<br>
basename $PWD returns just the name of the current folder  (without the path<br>
to it).  If we are in a folder called /home/adam/programming/wibble_1.1-1_all<br>
then it will return wibble_1.1-1_all .  We use ../ before this to put it in<br>
the parent folder, and .deb afterwards to give it a .deb extension.<br>
<br>
10.  Install the new package:<br>
<br>
$ cd ..<br>
$ sudo dpkg -i wibble_1.1-1_all.deb<br>
<br>
11.  Try it out:<br>
$ wibble<br>
<br>
12.  Once you're bored of the package, uninstall it:<br>
$ sudo dpkg -r wibble<br>
<br>
<br>
13.  (Just for fun)  Make a new, architecture-specific .deb package called<br>
wibble-bin_1.1-1-amd64.deb  (or whatever architecture you are using)  which<br>
installs the compiled "wibble" binary as created here.<br>
<br>
<br>
I've attached a tarball of my wibble_1.1-1_all folder, so you can try all this<br>
out for yourself.<br>
<div class="HOEnZb"><div class="h5"><br>
--<br>
AJS<br>
<br>
Answers come *after* questions.<br>
</div></div><br>--<br>
_____________________________________________________________________<br>
-- Bandwidth and Colocation Provided by <a href="http://www.api-digital.com" target="_blank">http://www.api-digital.com</a> --<br>
New to Asterisk? Join us for a live introductory webinar every Thurs:<br>
               <a href="http://www.asterisk.org/hello" target="_blank">http://www.asterisk.org/hello</a><br>
<br>
asterisk-users mailing list<br>
To UNSUBSCRIBE or update options visit:<br>
   <a href="http://lists.digium.com/mailman/listinfo/asterisk-users" target="_blank">http://lists.digium.com/mailman/listinfo/asterisk-users</a><br></blockquote></div><br></div>