Packaged For Apt

Putting together a .deb package is fairly simple, if you follow the steps. I have included a very simple example of a .deb that will install a wallpaper and make it readable. It's a silly example, but will hopefully clarify the steps.

To do this, you will probably want to install build-essential. At the very least, you will need to install dpkg-dev.

  1. Choose a package name, with version number and architecture. The version number should be x.y-z (major version, minor version, package version). (eg. lakewallpaper_1.0-1_all)
  2. Decide what files will be copied to the target system (the payload) (eg. lake.jpg)
  3. Decide what other tasks need to be done, before or after the installation and before or after the removal. (eg. chmod 555)
  4. Set up a directory structure. It should probably start in your ~/ directory, the next directory will be named <package>_<version>_<architecture>, then it should mirror the / directory, where the packages will be installed. (eg. ~/lakewallpaper_1.0-1_all/usr/share/wallpapers/).
  5. The payload should be placed in the correct directory (eg. cp lake.jpg ~/lakewallpaper_1.0-1_all/usr/share/wallpapers/).
    • Optional: create documentation -- a copyright file and a man page.
    • A copyright file is located in /usr/share/doc/<package>/ (eg. ~/lakewallpaper_1.0-1_all/usr/share/doc/lakewallpaper/copyright)
    • It should contain your name, the date and the licence that your package is released under. You can find many examples in /usr/share/doc in various subdirectories.
    • A man page is located in /usr/share/man. You must decide which section your package belongs in (search the web for help). (eg. For man(1), create the directory ~/lakewallpaper_1.0-1_all/usr/share/man/man1/. Within that directory, create the file lakewallpaper.1 and edit it with a text editor.)
    • You can find the proper format for a man page on the internet. It should include the name of the program, the options it takes, the files it uses, the name of the maintainer and an email address.
    • The man page must be gzipped. (eg. gzip --best ~/lakewallpaper_1.0-1_all/usr/share/man/man1/lakewallpaper.1)
  6. Make a control directory called DEBIAN (case is important) (eg. mkdir ~/lakewallpaper_1.0-1_all/DEBIAN).
  7. Within the DEBIAN directory, create a text file called md5sums. Go to your root directory and get an md5sum for each payload file, the copyright file and the man page. Paste them in to the md5sums text file. (eg md5sum /usr/share/wallpapers/lake.jpg) It should look like:
    2bc058b436cea5bee168689ff75819a6  usr/share/wallpapers/lake.jpg
    9d2e3eb543570c076a6c8e23aadb89d5  usr/share/man/man8/lakewallpaper.1.gz
    4bfab06f67c59c311d3f2402a2343fd7  usr/share/doc/lakewallpaper/copyright 
  8. Now create a file called control and edit it with a text editor. It must contain these sections:
    Package: <name>
    Version: <version>
    Section: <???>
    Priority: <required | important | standard | optional | extra>
    Architecture: <architecture>
    Depends: <packages it depends on, with (>= | = | <=version)>, separated by commas
    Maintainer: name <email>
    Description: short title
     lines beginning with a space.
     .
     no empty lines
    
    
    It should look like this:
    Package: lakewallpaper
    Version: 1.0-1
    Section: graphics
    Priority: optional
    Architecture: all
    Depends: libjpeg (<=1.0-1)
    Maintainer: deadDuck <eeepcrepos@tuxfamily.org>
    Description: Beautiful Lake Wallpaper
     This wallpaper is so beautiful, you will
     be astounded.
     .
     It will brighten up your desktop.
    
    It must end with a blank line. Save the file.
  9. You can create four scripts to run when your package is used: preinst, postinst, prerm, postrm. They are regular shell scripts. (eg. postinst
    #!/bin/sh
    chmod 555 /usr/share/wallpapers/lake.jpg
    
  10. Go back to your base directory. (eg. cd ~)
  11. run dpkg --build <directory> (eg. dpkg --build lakewallpaper_1.0-1_all)
  12. If it doesn't complain, you have a working .deb package!