Archive

Posts Tagged ‘deb’

omxd Debian package

January 1st, 2015 subogero Comments off

I’m through my most swearword-intensive development ever: creating a Debian package from the omxd Raspberry Pi media-player daemon. Debian developers take note: if strange freak-accidents happen to you and your families, it’s my fault. I’m currently being treated with post-traumatic stress disorder and want to forget the whole experience.

Except, I decided to write down the most interesting stations of my journey through the Valley of the Shadow of De… Debian. Documentation is available but hard to find, as most Google hits are about using deb packages, not creating them.

If you are an experienced Debian developer and find that I’m a noob, an idiot and a luser, you’re right. But then, why does Linus Torvalds refuse to provide SubSurface binaries for Linux? Exactly. Because he did not let his brain rot by thinking that creating deb or rpm packages is something sane. And no, the problem is not fragmentation. Once you’ve created you deb package, alien will turn it into and rpm in no time. It’s creating the deb that’s so difficult.

Init Scripts

Originally make install just inserted an omxd call into /etc/rc.local and started omxd. But better don’t mess with existing files, so I changed it to create /etc/init.d/omxd with start/stop/restart verbs and registered it for auto-start by

update-rc.d omxd defaults

and finally doing a

service omxd start

How naive I was…

Automated Releases

I copied the make tag rule from szg, which creates releases, where the tag message is a commit list in Debian changelog format.

$(DESTDIR)

In your Makefile, use the $(DESTDIR) prefix whereever you install something.

cp omxd $(DESTDIR)/usr/bin

debian/omxd.dirs

I did not remember this, but this file is needed with a list of directories you install files into. Note the lack of leading slash:

usr/bin
usr/share/man/man1
usr/share/doc/omxd
etc/init.d

force-reload

Lintian throws an error that you need a force-reload verb in your init script. So I gave in.

Auto start/restart/stop omxd – The Real Troubles Begin

Having make install starting and registering your daemon does not help. dpkg-buildpackage just uses this rule to collect the installed files. Later when the deb is installed, it’s not run. You need a debian/postinst maintainer script to do a

service omxd start

But during upgrades you need to stop it first, so add prerm and preinst scripts too with

service omxd stop

Idempotency

But a reinstall/upgrade will fail if your init script returns an error when attempting starting an already started daemon or stopping an already stopped one or trying to do anything with a non-existing one. So make sure they are idempotent: running them repeatedly has no effect at all, not even an error. In case of preinst:

service omxd stop || true

Also make sure the init scripts start/stop verbs don’t fail for these cases.

debian/conffiles, Bloody conffiles

dpkg-buildpackage considers anything you install into the /etc directory a configuration file and adds them automatically to the debian/conffiles file. Result: if you develop something using make install/uninstall, then install the deb package again, dpkg will refuse to install the those files, because their lack is a modification by the sysadmin. Unbelievable but true. And there is no obvious workaround, either. All you can do, and this is confirmed by the Debian docs, is to create anything in /etc by the debian/postinst script.

There are no words for the idiocy of the Debian conffiles policy. How often have you been prompted by Ubuntu/Debian package upgrades about mysterious config file changes you’ve never ever touched? It’s all because it’s so difficult to get it right.

And why is anything in /etc added to conffiles with no possibility to override? Sure, /etc/init.d/omxd is a config file. But it’s the init system’s config file, not mine!

And Finally, lintian

I used lintian. Did it complain about the lacking debian/omxd.dirs file? No. Did it warn me about the auto-start idempotency problems? No. Did it complain about a completely useless force-reload initscript verb? Yes. Did it complain about the lack of all the useless and paranoid GCC warning options in my makefile? Yes. And finally did it throw an error upon the only existing workaround for the conffile-hell? Yes.

Lintian is a useless piece of shite. I threw it out.

make utag

During packaging I had to undo release commits and tags countless times. I even automated it with make utag.

Conclusion

The Debian packages for omxd and the latest stable omxplayer are available in my repo. Just add it to your software sources by adding the file /etc/apt/sources.list.d/subogero.list containing this:

deb http://linux.subogero.com/deb/ /

The install

apt-get update
apt-get install omxd

I’m also accepting donations for my post-traumatic stress disorder treatment on my PayPal account.


szg The Calculator

December 2nd, 2011 subogero 8 comments


Get szg now!

Get szg now!


szg is the Lazy Man’s command line calculator, crunching the maximum number of numbers with the minimum number of keystrokes.

szg stands for SZámolóGép, which is Hungarian for calculator.
It also happens to be the initials of the author, a particularly Lazy Man.

If you you’re lazy too;

If you like binary, octal and hex formats;

If you hate typing too much;

If you hate mouse-clicking even more;

If you hate calculators going floating-point after the first division;

If you still need floating-point occasionally;

If you typo a lot and prefer to undo them all;

If you like to comment your calculations (well, you don’t, but it’s possible):

Accept no substitute! Use szg.

Features

  • 32-bit integer or floating-point arithmetic
  • decimal, binary, octal or hexadecimal format (commands D, B, O, X)
  • input of expressions, variable assignments and commands on stdin
  • input of expressions directly from the command line
  • output of calculations on stdout
  • error messages (syntax error, division by zero) or stderr
  • unlimited undo
  • user defined variables like $foo
  • operators ()~ ^ */%& +-| =
  • symbol _ means last result, like Perl/Python
  • missing identifier means _ (+5 means last result + 5) like Perl (sorry Python)
  • math functions @s @c @a @l @e @r = sin cos atan log exp sqrt
  • optional unsigned arithmetic (commands N, S)
  • floating-point not upon division, only by user request, like Python (but not Python3)
  • combination if expressions/commands on same line
  • comments starting with #
  • interpreter mode when input file specified
  • manual page

Installation

Debian Packages

The easiest way to install szg is using apt-get on Debian-based systems. Add my Debian repo to /etc/apt/sources.list:

deb http://linux.subogero.com/deb/ /
deb-src http://linux.subogero.com/deb/ /

And then

# apt-get update
# apt-get install szg

Source Tarball

From http://linux.subogero.com/deb/ get szg_X.Y.orig.tar.gz.
szg can be compiled and installed on Linux or Windows/Cygwin. On Windows, it runs both in Cygwin and Windows command line windows. Download and extract the newest one, then

$ cd szg-X.Y
$ ./configure
$ make
# make install # as root

Windows

From http://linux.subogero.com/deb/ get szg_X.Y.zip.
Download and extract the newest one, then copy szg.exe to C:\WINDOWS or another folder which is on PATH.

Git for the Brave

$ git clone http://subogero.dyndns.org/git/szg.git || \
  git clone https://github.com/subogero/szg.git
$ cd szg
$ ./configure
$ make
$ make install # as root

Examples

Desktop calculator workflow with a twist

d 5000    # one steak
5000
d +3*2000 # three whiskies neat
11000
d +1000   # tip
12000
d 20000-  # Let's see how much money I've got left from my 20000 note
8000
d

Command/statement combination for hex/dec conversion, signed/unsigned modes. Watch the prompt!

d XffffD       # change to hex, enter FFFF, change back to dec
65535
d X ffffffff D # change to hex, enter FFFFFFFF, change back to dec
-1
d N            # unsigned (natural number) mode
4294967295
D 240X         # stay in dec, enter 240, change to hex
f0
X D239X        # change to dec, enter 239, change to hex
ef
X

Undo, difference between subtraction and unary minus.

84
d ~42        # Let's subtract 42 ...
-42
d U-42       # Oops, I hit tilde instead of minus
42

szg works as an interpreter as well, an input file can be specified on the command line. This also allows to create executable szg interpreter scripts. For instance let’s create an executable file called LifeUniverseAndEverything:

#!/usr/bin/szg
33*2 X

szg supports floats and binary formats. You can even peek into the insides of floats.

D 1+2
3
d /2    # no implicit float-conversion upon division
1
d /2.0  # Pythonic float-conversion if float-format entered
0.5
f B     # let's peek inside
00111111 00000000 00000000 00000000
f

You can specify an expression on the command line, to maximize laziness:

$ szg -e XffD
255

Background

This is the first remake of my first shot at a unix-style program. In the first shot you had to enter too many capital letters for hex numbers.
It’s a filter, as in unix nearly everything should be. I tried to follow the Sacred Rules of the Art from esr’s book:

Command line option conventions

-h –help for help
-V –version for version info

Data driven development

The source of the usage and version screens are text files which look exactly like those screens. During make, they are sedded into header files with lists of string initializers. The headers are then included in the middle of const table definitions, to make the text available as a list of strings, line by line.

Undo is possible thanks to a stack data-structure and the user-defined variables’ heart and soul is a hash-table, with buckets and all that.

Write programs to write programs

I used Lex and Yacc to parse the input and to write the syntax. I can still hardly believe what these nearly 40 year old tools can do.