Thursday, November 19, 2015

Modifying the Source Code of a Debian Package and Unwisely Installing the Modified Version on Your System

Debian's got a hello world package:

$ sudo apt install hello

$ hello
Hello, world!

Remove it!

$ sudo apt remove hello

$ hello
bash: /usr/bin/hello: No such file or directory

Make a directory for unwise experiments:

$ mkdir ~/tmp
$ cd ~/tmp

Get everything we need to build hello ourselves:
 $ sudo apt-get build-dep hello

Get the source:

$ sudo apt-get source hello

Compile the source:

$ sudo apt-get source --compile hello

Install the new package:

$ sudo dpkg --install hello_2.9-2+deb8u1_amd64.deb



Check it's on the system:

$ hello 
Hello, world!

Modify the program:


$ sudo sed -i 's/Hello/Hell/g' hello-2.9/src/hello.c

$ sudo apt-get source --compile hello

Damn it, tests!

$ sudo sed -i 's/Hello/Hell/g' hello-2.9/tests/hello-1

$ sudo apt-get source --compile hello

Run the local copy:

$ hello-2.9/debian/hello/usr/bin/hello

Ship it!

$ sudo dpkg --install hello_2.9-2+deb8u1_amd64.deb

Paranoid Check:

$ hello
Hell, world!

apt can undo the damage we've just done:

$ sudo apt install hello

$ hello
Hello, world!