This article describes a simple way on how to create a home made debian package and include it into a local package repository. Although we could use a existing Debian/Ubuntu package, we will start from scratch by creating our own minimalistic unofficial debian package. Once our package is ready, we will include it into our local package repository. This article illustrates very simplistic approach of creating debian package, however it may serve as a template in many different scenarios.
First we need to create some simple program, compile it and test it. Our program will do nothing else just print "linuxconfig.org" on the screen. Here is a code:
#include <iostream> int main() { using namespace std; cout << "linuxconfig.org\n"; return 0; }
Save the above code as linuxconfig.cc. At this point make sure that you have compiler installed on your system by executing:
apt-get install build-essential
Compile and execute your code with a following command:
$ g++ linuxconfig.cc -o linuxconfig $ ./linuxconfig linuxconfig.org
All is looking good. At this point you should have a binary executable called linuxconfig which prints some string on the screen.
Now that we have our small program ready in form of executable binary we can package it up into a debian package. To do that we would use a dpkg-deb tool. But first we need to create a debian package structure. The only files required in to build a debian package are:
First create a directory called "linuxconfig". This directory will hold all necessary package files:
$ mkdir linuxconfig
Next, create a control file:
$ cd linuxconfig $ mkdir DEBIAN
When ready open up DEBIAN/control file
$ vi DEBIAN/control
and enter a following information:
Package: linuxconfig Version: 1.0 Section: custom Priority: optional Architecture: all Essential: no Installed-Size: 1024 Maintainer: linuxconfig.org Description: Print linuxconfig.org on the screen
Great, the only thing that is missing is our linuxconfig program. Still in root of linuxconfig directory create a directory which will be used to install linuxconfig program and copy our tiny program into this directory. Best choice for us will be /usr/bin:
$ mkdir -p usr/bin/ $ cp /path/to/linuxconfig usr/bin/
At this point we are ready to create a debian package.
$ cd .. $ dpkg-deb --build linuxconfig dpkg-deb: building package `linuxconfig' in `linuxconfig.deb'. $ ls linuxconfig linuxconfig.deb
Change the name to something like:
mv linuxconfig.deb linuxconfig-1.0_i386.deb
All done ! Our package is ready !
NOTE: this is just an example, real debian package to by submitted as a part of debian/ubuntu distribution would require more work.
To do this we would need a webserver. In this case we will use apache with default settings. If you have not done so yet install apache webserver:
# apt-get install apache2
Navigate your browser to the IP address of your webserver. In our case it is http://10.1.1.4/. If this is your default apache webserver configuration you should see a page similar to:
It works!
This is the default web page for this server.
The web server software is running but no content has been added, yet.
The location of this default apache welcome page is:
/var/www
This is exactly the directory where we will store our new debian package. Create a directory "debian" inside /var/www and copy linuxconfig-1.0_i386.deb inside.
# cd /var/www # mkdir debian # cp /path/to/linuxconfig-1.0_i386.deb /var/www/debian/
Still in /var/www create a package list using dpkg-scanpackages:
# dpkg-scanpackages debian /dev/null | gzip -9c > debian/Packages.gz dpkg-scanpackages: warning: Packages in archive but missing from override file: dpkg-scanpackages: warning: linuxconfig dpkg-scanpackages: info: Wrote 1 entries to output Packages file.
Our home made local debian package repository is now ready.
At this point all should be ready to install our own linuxconfig package via our debian repository. All what needs to be done is to edit /etc/apt/sources.list and update package list on a client machine:.
NOTE: change IP address to reflect your webserver
# echo "deb http://10.1.1.4 debian/" >> /etc/apt/sources.list # apt-get update Ign http://10.1.1.4 debian/ Release.gpg Ign http://10.1.1.4/ debian/ Translation-en Ign http://10.1.1.4/ debian/ Translation-en_AU Ign http://10.1.1.4 debian/ Release Ign http://10.1.1.4 debian/ Packages Get:1 http://10.1.1.4 debian/ Packages [303 B]
All done, now simply install linuxconfig package using apt-get tool:
# apt-get install linuxconfig Reading package lists... Done Building dependency tree Reading state information... Done The following NEW packages will be installed: linuxconfig 0 upgraded, 1 newly installed, 0 to remove and 8 not upgraded. Need to get 3,362 B of archives. After this operation, 1,049 kB of additional disk space will be used. WARNING: The following packages cannot be authenticated! linuxconfig Install these packages without verification [y/N]? y Get:1 http://10.1.1.4/ debian/ linuxconfig 1.0 [3,362 B] Fetched 3,362 B in 0s (0 B/s) Selecting previously deselected package linuxconfig. (Reading database ... 95809 files and directories currently installed.) Unpacking linuxconfig (from .../linuxconfig_1.0_all.deb) ... Setting up linuxconfig (1.0) ...
Execute:
# linuxconfig linuxconfig.org
If you feel that you do not need this package any more, simply remove it from the system with:
# dpkg -P linuxconfig (Reading database ... 95810 files and directories currently installed.) Removing linuxconfig ... # linuxconfig bash: /usr/bin/linuxconfig: No such file or directory