Packaging a Script #1

As I am doing some programming for the last time, and want to create Debian packages from my scripts, I needed to read something about it. I could not find a really short and easy understandable tutorial, there is one now.

The whole thing will be (as it is a lot of stuff) devided into some parts.

  1. The Makefile
  2. Packaging
  3. Upload into a PPA

I will only talk about a small Python script.

First the program has to be written, and should be working on your machin. Mine is an easy “hello world” script, printing this on the terminal and using the Ubuntu messaging system. The script should be placed in an own working directory. All other files will be created in and commands are run from this directory.

First I create the file world-example (the script itself):


import os
print("Hello World")
os.system('notify-send "Hello World"')

The first line is the shebang and is needed for the computer to know how to run the program. In this case this is Python.

The second line is importing a needed library.

Line three prints “Hello World” in the terminal.

And line four tells the operating system to use the programm notify-send for a grafical message.

For everything to run propperly you need Python 2.6 and the package libnotify-bin. If this is the case you need to give the file rights to be executed. Now you can try to run it using ./world-example.

Installing the script is mainly to put it in the right directory of your system. The makefile is responsible for this (and compiling programs in other languages). Therefore we create the file Makefile and fill it with the following content.

# Define Vars
# install copies files -d = directory, -m = acces rights
INSTALL = /usr/bin/install -c

# Targets

The first part is configuring some variables. We do not need it for a small file like this, but you should get used to it for bigger programmes.

USERBINPATH is the path where the file, starting the program, should be placed. In our case this is the whole program.

INSTALL is the path for the program used for installing.

INSTALL_PROGRAMM is also setting the access rights.

The targets tell, what is done while running the Makefile. We only have one target here, the installation. First the programme install is anked to create the directory DESTDIR/usr/bin if it is not existing. DESTDIR is needed for the packaging, that is coming later. It will be ignored, if not given. Then we move the program into the created directory and give it the right to be executed. Targets like clean (as used in big programs) are not needed here, as we do not compile the program. The uninstallation will also be done by the package manager later.

Now the program should be ready for installation.

$ sudo make install

Now try to run it from the terminal.

$ world-example

The next issue will talk about creating a .deb package

Published by


Linux User, Programmer and Start-up founder

2 thoughts on “Packaging a Script #1”

  1. Na toll, jetzt, wo es spannend wirst, hörst du auf 🙂 Nein im Ernst, guter Artikel, ich bin auf die weiteren Teile sehr gespannt!

Comments are closed.