Lab 2 - Packages and Packaging and Troubleshooting

Debian: An Introduction to apt and dpkg

In this class, we will be focused on using Debian. As noted before, Debian uses apt/dpkg as its package manager. Other distributions use different package managers.

The frontend package manager is apt. It will be what you’ll be using for 99.9% of the time. Before you do anything, it is good package to update the package list so your package manager can find and fetch the most up-to-date packages. To do that, run:

apt update

To find the package to install:

apt-cache search [package|description]

To install a package, run:

apt install package

To remove a package, run:

apt remove package

Easy? Sometimes, you want to update the packages that you have installed, run:

apt dist-upgrade

There are also other commands, such as removing unneeded dependencies and purging packages but that is what the man pages are for. Please note that you are going to have to use sudo for the above commands since you are actually modifying the system itself.

The backend package manager is dpkg. Traditionally, we use dpkg to install local packages. We also can inspect packages and fix broken installs. To install local packages, run:

dpkg -i packagefilename

To remove a system package:

dpkg --remove package

To inspect a package for more information about the package:

dpkg -I packagefilename

To fix/configure all unpacked but unfinished installs:

dpkg --configure -a

Getting Started

We are going to use GCC to compile source code and a simple utility called fpm to create packages in this lab.

Using the commands above, install gcc, ruby-dev, and ruby-ffi.

Now check if GCC is installed by typing the followng:

gcc --version

Now install fpm using gem, Ruby’s own package manager:

sudo gem install fpm

Now check if fpm is installed:

fpm

Now clone the decal-web repository:

git clone https://github.com/0xcf/decal-labs.git

Exercise 1: Compiling and Packaging

Packaging manually for Debian can be very hard and frustrating, especially for first timers. That’s why for this class, we’ll be using a really cool Ruby package called fpm which simplifies the task of packaging a lot. Please note that if you were going to package for Debian’s own repositories, this is NOT the correct/formal way to go about packaging. It is merely a great way to backport or package your own applications extremely quickly.

Now we will create a very simple package using the hellopenguin executable that you made above. First, move into the a2 folder in the repository that you cloned in the Getting Started section:

cd decal-labs/a2

Now we are going to create a folder to work in for this exercise:

mkdir ex1

And now move into the folder:

cd ex1

Compiling the program

Now, we will make a very simple application in C that prints “Hello Penguin!” named hellopenguin. Invoke:

nano hellopenguin.c

And then type in the following:

#include <stdio.h>

int main()

{

   printf("Hello Penguin!\n");

   return 0;

}

Now save and exit.

We will now compile the source file that you have just written:

gcc hellopenguin.c -o hellopenguin

What this does is to take in a source file hellopenguin.c and compile it to an executable named hellopenguin with the -o output flag.

Packaging the executable

Now, we will create the folder structure of where the executable show reside in. In Debian, user-level packages usually reside in the folder /usr/bin/:

mkdir -p packpenguin/usr/bin

Now move your hellopenguin into the packpenguin/usr/bin/ folder.

mv hellopenguin packpenguin/usr/bin/

Now we will create a package called hellopenguin. Move into the parent directory of the hellopenguin folder and invoke the following:

fpm -s dir -t deb -n hellopenguin -v 1.0~ocf1 -C packpenguin

This specifies that you want to take in a directory, using the -s flag, and to output a .deb package using the -t flag. It takes in a directory called packpenguin, using the -C flag, and output a .deb file named hellopenguin, using the -n, with a version number of 1.0~ocf1, using the -v flag.

Now test it by invoking apt and installing it:

sudo dpkg -i ./hellopenguin_1.0~ocf1_amd64.deb

Now you should be able to run hellopenguin by doing the following:

hellopenguin

Exercise 2: Troubleshooting

Now we are going to try and troubleshoot a package. Move to the other folder. Use the following command if you are in the ex1:

cd ../ex2

Try installing the ocfspy package using dpkg. It should error. Take note what it is erroring on! Now try and fix it.

Hint: You should be missing a dependency. Inspect the package for more details. The file to create that application is in the folder. Try compiling and packaging it. Check exercise 1!

Conclusion:

After you’re done, complete this submission form.

Note that you may want to clean up your VM by removing hellopenguin, ocfdocs, and ocfspy from /usr/bin.