[asterisk-users] Starpy and Asterisk on different machines ? [SOLVED]

A J Stiles asterisk_list at earthshod.co.uk
Fri Jan 17 08:41:33 CST 2014


On Friday 17 January 2014, Olivier wrote:
> 2014/1/16 A J Stiles <asterisk_list at earthshod.co.uk>
> > If you need to install something on several boxen, you can make your own
> > .deb
> > package -fairly- easily --
> 
> For a complete packager beginner, how much time would it (very roughly)
> take to its first .deb package ?

There is plenty of information out there on the Internet  (and to be quite 
honest I have to check everytime I do this, because it's a bit of a rarity),  
but here's my quick executive summary of the process.  There are other ways to 
do it and if you find one that works better for you, feel free to use that 
method.


We are going to create a package "wibble_1.1-1_all.deb".  This is a trivial 
example, and just prints a silly message; but what is special about it is, the 
same package can be installed on 32-bit, 64-bit and Raspberry Pi 
architectures.  (It most probably will work on other architectures too, but I 
have no way to test this at the moment.)

1.  Make a folder in which to hold the files for your package, named after the 
package itself with version number  (see how other people's .deb files are 
named),  and navigate to there;

$ mkdir wibble_1.1-1_all
$ cd wibble_1.1-1_all

2.  Make a folder structure consisting of everything that the package is going 
to install, but under here instead of under / .  So for example there may be 
folders usr/ , usr/bin/ , usr/lib/ , usr/share/ , etc/ and so forth.  
("wibble" doesn't have any configuration files, so it doesn't need anything 
under /etc/ .)

Important:  Your package *must* have been built to install under /usr/ and 
*not* under /usr/local/ !  /usr/local/ is supposed to be off limits to .deb 
packages!

In order to work out what you need to put here, look at the Makefile and see 
what it installs.


My package "wibble" consists of the following:

usr/src/wibble-1.1/wibble.c :
#include <stdio.h>
int main() {
    printf("Wibble!\n");
};

And that's almost all there is to it.  I said it was a trivial example.

3.  Make sure you have a folder under usr/share/doc/*/ with "changelog" and 
"copyright" files.

usr/share/doc/wibble/changelog :
wibble (1:1.1) stable; urgency=low
First .deb version of package.

usr/share/doc/wibble/copyright :
This package is licenced under a "Don't Ask, Don't Tell" licence.

Don't ask us for permission to copy it, and we won't tell you not to .....

4.  Create a tarball "data.tar.gz" with your folder structure in it.  This is 
going to get extracted under / as part of the installation process.  Now, a 
.deb file is also supposed to include a file with the MD5 sums of all files in 
data.tar.gz.  We can use the power of bash to create the tarball and the 
MD5sums file in one operation;

$ md5sum $(tar cvzf data.tar.gz usr | awk '!/\/$/{print}') > md5sums

Now, this needs explaining.
The inner command is
tar cvzf data.tar.gz usr
(obviously, if you have other folders beside usr, include these too)
and the v makes it list the files it added to the archive.  This output then 
gets piped through an awk filter:
awk '!/\/$/{print}'
which passes through only lines that don't end with a / character  (lines 
ending in / are folders).  The $() wrapped around this pipeline command runs 
the commands between the round brackets, and passes the final output  (i.e., 
all the files processed by tar, but no folders)  to the command which is using 
it as an argument -- in this case, md5sum .  So what this does is, it takes 
the md5sum of every file  (but not the folders)  that is being added to the tar 
archive.  Finally, the more-than sign > directs the output into a file called 
"md5sums".

5.  Create a file "control" explaining the package.  Here is mine:
Package: wibble
Version: 1:1.1
Architecture: all
Maintainer: AJS <adam at priceengines.co.uk>
Installed-Size: 123
Depends: build-essential
Section: stuff
Priority: standard
Homepage: http://blog.earthshod.co.uk/
Description: Just prints "wibble", which isn't very fantastic.  What is
 special about this package is, the same package should install correctly on
 32-bit, 64-bit or Raspberry Pi architectures.  (And others, but these have
 not been tested for want of suitable candidate hardware.)

You will need to refer to other documentation online here.  What is most 
important is the "Depends:" line.  Here you list every package that your 
package depends on.  If you get this right, then it will always pull in all 
the packages it needs to install, even on a totally pristine, minimal system.  
(Raspberry Pi users have the advantage here, because it is so quick and easy 
to clone an SD card.)  In particular, the "Installed-Size:123" is wrong  (but 
it seems to work in spite of this).  Where storage space is tight, it will be 
more important to get this right.  Note also that continuation lines  (as 
after Description: above)  start with a space.

6.  Create shell scripts "postinst"  (which runs after data.tar.gz is 
unpacked, and finishes off the installation process)  and "prerm"  (which runs 
first thing before you uninstall the package, and is supposed to tidy things 
up).  Here we are actually going to install the Source Code under /usr/src/ 
and then build it in the postinst script.  This is going to create files that 
were not in data.tar.gz, so we have to remove them in the prerm script.

Don't forget to run chmod +x on these scripts.

prerm:
#!/bin/bash
rm -rf /usr/src/wibble-1.1/
rm -f /usr/bin/wibble

postinst:
#!/bin/bash
OLDPWD=$(pwd)
cd /usr/src/wibble-1.1
gcc -owibble wibble.c
install -c -m755 wibble /usr/bin
cd "$OLDPWD"

7.  Now you have to make an archive called "control.tar.gz" which contains the 
"control" file, the prerm and postinst scripts and the md5sums file:

$ tar cvzf control.tar.gz control prerm postinst md5sums

8.  Create a file called "debian-binary" which just tells dpkg the version of 
the .deb format.  This should contain the characters "2.0" followed by a line 
break.  Don't bother using your favourite editor; just type

$ echo "2.0" > debian-binary

9.  Now we are ready to make the .deb file!  We will create it outside the 
folder so as not to pollute its structure.

$ ar rv ../$(basename $PWD).deb debian-binary control.tar.gz data.tar.gz
$() runs a command and uses its output.
basename $PWD returns just the name of the current folder  (without the path 
to it).  If we are in a folder called /home/adam/programming/wibble_1.1-1_all 
then it will return wibble_1.1-1_all .  We use ../ before this to put it in 
the parent folder, and .deb afterwards to give it a .deb extension.

10.  Install the new package:

$ cd ..
$ sudo dpkg -i wibble_1.1-1_all.deb

11.  Try it out:
$ wibble

12.  Once you're bored of the package, uninstall it:
$ sudo dpkg -r wibble


13.  (Just for fun)  Make a new, architecture-specific .deb package called 
wibble-bin_1.1-1-amd64.deb  (or whatever architecture you are using)  which 
installs the compiled "wibble" binary as created here.


I've attached a tarball of my wibble_1.1-1_all folder, so you can try all this 
out for yourself.

-- 
AJS

Answers come *after* questions.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: wibble_1.1-1_all.tar.gz
Type: application/x-compressed-tar
Size: 2700 bytes
Desc: not available
URL: <http://lists.digium.com/pipermail/asterisk-users/attachments/20140117/f3241420/attachment.bin>


More information about the asterisk-users mailing list