Monthly Archives: April 2009

How to build a Debian package

The following are some notes on how to build a Debian package. It is not really a complete tutorial.

I will assume that you are using subversion, and I will assume that you will add your package to an apt repository.

*) Install dependencies
apt-get install svn-buildpackage gcc debhelper dh-make epm fakeroot

*) Make a directory for your source code
mkdir -p packageName/branches
mkdir -p packageName/tags
mkdir -p packageName/packageName-0.1

*) Enter packageName-0.1 directory and touch a fake tarball
cd packageName/packageName-0.1
touch ../packageName-0.1.tar.gz

*) Use dh_make to create your default debian directory.
dh_make -n -s -e yourEmail@yourDomain.com -f ../packageName-0.1.tar.gz
“-n” is the flag for creating a native Debian package.
“-s” is the flag for creating a single binary.

*) Move packageName-0.1 to trunk
cd ../;mv packageName-0.1 trunk
Now, you may remove the tar balls.
rm packageName_0.1.orig.tar.gz; rm packageName-0.1.tar.gz

*) Step into trunk/debian. Since I do not want to create any cron jobs or emacs or init scripts or man pages in this package, I am going to delete these example scripts.
cd trunk/debian
rm cron.d.ex emacsen-install.ex emacsen-remove.ex emacsen-startup.ex init.d.ex manpage.1.ex menu.ex manpage.xml.ex manpage.sgml.ex watch.ex

*) Rename the example install scripts that you want to keep.
mv postinst.ex postinst; mv preinst.ex preinst; mv postrm.ex postrm; mv prerm.ex prerm

*) Remove any other example scripts that you do not want.
rm *.EX; rm *.ex

*) Edit the control file to update the “Description:” and to add any package dependencies to “Depends:” (if any exist).
vi control

*) If you want postinst commands to run, edit postinst and add commands on a new line after:
case "$1" in
configure)
#echo "My command"

*) Step into trunk, and create a Makefile.
cd ../; vi Makefile
Below are a few examples of what could be in your Makefile.
SHELL=/bin/sh
INSTALL_TMP = install -d -m 1777 -o root -g root
INSTALL_DIR = install -d -m 755 -o root -g root
INSTALL_DIR_APACHE = install -d -m 755 -o www-data -g www-data
INSTALL_PROGRAM = install -c -m 755 -o root -g root
INSTALL_MAN = install -c -m 444 -o bin -g bin
INSTALL_APACHE = install -c -m 644 -o www-data -g www-data


PEAR=$(DESTDIR)/usr/share/php
TMP=$(DESTDIR)/tmp


install:
^t $(INSTALL_DIR) $(PEAR)
^t $(INSTALL_TMP) $(TMP)
^t $(INSTALL_PROGRAM) myProgram.sh $(TMP)

You will need to use tabs (^t) after “install:” The commands above will create the /usr/share/php and the /tmp directory in your fakeroot environment. Then, you can copy files into these two directories. The last command will install the “myProgram.sh” file (which is located in trunk) into the /tmp directory with the permissions of 755 and with the ownership of root:root. If you want to execute this program as a post installation script, you will need to enter it in debian/postinst with the path, e.g., “/tmp/myProgram.sh”.

*) Before you build your package, add your source code to subversion. Step into the directory above the package directory.
cd ../../ ; svn add packageName; svn ci -m "Adding packageName source code to subversion"

*) Now, you are ready to build the Debain package. Step into trunk (where your Makefile is located) and execute the following command.
cd packageName/trunk; dpkg-buildpackage -us -uc -rfakeroot

*) You package will be built and copied one level up in the directory tree. So, cd up one level, and add your package to your apt repository. The following command assumes that your apt repository is on the local machine in /var/www/yourRepo/. And, it assumes that your username is a sudoer.
cd ../ ; sudo reprepro -Vb /var/www/yourRepo/ includedeb yourRepo-unstable packageName_0.1-1_i386.deb

Creating a Debian package is really not that complicated. But, do not forget to test your package to make sure that it installs without errors. If you have errors, fix them, and then rebuild the package. You can delete the package from the apt repository and re-add it after rebuilding.
sudo reprepro -Vb /var/www/yourRepo/ remove yourRepo-unstable packageName_0.1-1_i386.deb
sudo reprepro -Vb /var/www/yourRepo/ includedeb yourRepo-unstable packageName_0.1-1_i386.deb

Subversion: How to merge a branch back into trunk

Typically, subversion (svn) is used to manage releases. If your latest code is being developed in trunk, for a release, you should create a release branch and then release from a tag created from that release branch. After a period of time, you will probably introduce patches in the release branch and perhaps you might even add additional features to the release branch. At some point, you will probably want to merge your changes back into the trunk. The follow are some steps to merging your changes back into trunk using the command line version of subversion (svn).

1. Step into the release branch and find out what has changed since you created the release branch.
svn log --stop-on-copy http://svn.example.com/proj/branches/branchname

2. Once you have discovered the revision number from the creation date of the release branch (e.g., 999), use this revision number to merge the branch to the trunk. Step into the trunk and execute:
svn merge -r999:HEAD http://svn.example.com/proj/branches/branchname@999 .
The dot at the end indicates your current “trunk” working directory as your target. “HEAD” means the latest revision.

3. Once you have merged the branch into the trunk, then you can commit the changed code to the trunk.
svn ci -m "Merged the branch code changes from revision 999 into trunk."
If there are conflicts, you will have to edit the code and resolve the conflicts. You can use “svn resolved” to clean up the conflict files. Then use “svn ci” or “svn commit” to try again.

Control codes for serial communication

Typically, devices that communicate over serial connections are expecting to receive a control code, e.g., an ACK or a NAK. The following are some common control codes.

$SOH = chr(1); // start of heading
$STX = chr(2); // start of text
$ETX = chr(3); // end of text
$EOT = chr(4); // end of transmission
$ACK = chr(6); // acknowledge
$NAK = chr(21); // negative acknowledge

http://www.asciitable.com/