Table of Content
- Table of Content
- Getting Start
- Generate KEY id.
- Send KEY ID to Ubuntu server
- Generate SSH key
- Setting pbuilder up
- Configure your LaunchPad account
- Confirmation for LaunchPad
- Upload SSH key to LaunchPad
- Configure the shell
- Prepare your program
- Build .deb file
- Tips
Debian/Ubuntu is one of the most popular Linux distributions. Installing new package or program on Ubuntu is very easy. With apt or apt-get commands, the user can manage their installed package, install new packages, upgrade new versions, removed old packages, etc. However, there are a number of things you need to do to get started building package and developing for Ubuntu community. So I suggest you read this post carefully!
This post will explain how can we build our own Debian/Ubuntu package file and upload it to the server. This means that you can distribute your program to everybody via sudo apt-get install YOUR_PROGRAM command!
Getting Start
Original document is available at http://packaging.ubuntu.com/singlehtml/index.html. Although it is very good reference, but the instruction explained in that document may be too complicated for the end-users. I boil it down and explain it in a way you can follow easily.
Generate KEY id.
- Generate KEY id.
gpg --full-gen-key
- Follows an interactive question.
- Question 1:
Please select what kind of key you want:
(1) RSA and RSA (default)
(2) DSA and Elgamal
(3) DSA (sign only)
(4) RSA (sign only)
Your selection? 1
- Question 2:
Please specify how long the key should be valid.
0 = key does not expire
n = key expires in n days
n w = key expires in n weeks
n m = key expires in n months
n y = key expires in n years
Key is valid for 0 0
- Question 3:
Real name: Rangsiman Ketkaew
Email address: test_test@gmail.com
Comment:
- Check your KEY id
gpg --list-secret-keys --keyid-format LONG
Output:
sec rsa3072/TESTKEY112233 2019-05-23 [SC] [expires: XXXX-XX-XX]
4C220144Fd0892C02CF337AC6F0BF90G43CDE61D
uid [ultimate] Rangsiman Ketkaew <test_test@gmail.com>
ssb rsa3072/XXXXXXXXX 2019-05-23 [E] [expires: XXXX-XX-XX]
Send KEY ID to Ubuntu server
gpg --send-keys --keyserver keyserver.ubuntu.com TESTKEY112233
Generate SSH key
- To generate SSH key, use following command:
ssh-keygen -t rsa
- Then you will ask where the ssh key fille will be saved, just enter the default setting.
Generating public/private rsa key pair.
Enter file in which to save the key (/home/nutt/.ssh/id_rsa):
- Type and confirm your passphrase.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
- Done!
Your identification has been saved in /home/rangsiman/.ssh/id_rsa.
Your public key has been saved in /home/rangsiman/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:sdfsfsdfsfdsfsdfsfdsfsdfsfsfdsfdsdfsdfsdf rangsiman@Ubuntu
The key's randomart image is:
+---[RSA 2048]----+
|==_.. |
|++ B |
| .O B . |
| _ X = B E |
|+ X B B S . |
| \* = X . . . |
| + = . . |
| + |
| |
+----[SHA256]-----+
Setting pbuilder up
Execute following command
pbuilder-dist
FYI: You can use following command to check Ubuntu code name:
lsb_release -a
Output:
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 18.04.2 LTS
Release: 18.04
Codename: bionic
Configure your LaunchPad account
-
Go to https://launchpad.net and create your own account.
-
Confirmation e-mail will be sent to your e-mail.
-
Get back to the terminal. Check your KEY id using:
gpg --list-secret-keys --keyid-format LONG
Output:
sec rsa3072/TESTKEY112233 2019-05-23 [SC] [expires: XXXX-XX-XX]
4C220144Fd0892C02CF337AC6F0BF90G43CDE61D
uid [ultimate] Rangsiman Ketkaew <test_test@gmail.com>
ssb rsa3072/XXXXXXXXX 2019-05-23 [E] [expires: XXXX-XX-XX]
- Submit SSH key to Ubuntu server:
gpg --send-keys --keyserver keyserver.ubuntu.com TESTKEY112233
-
Append your Key Fingerprint (a long one) to text box, for example,
4C220144Fd0892C02CF337AC6F0BF90G43CDE61D
- Then click “Import Key”.
Confirmation for LaunchPad
Ref: https://help.launchpad.net/ReadingOpenPgpMail
-
A confirmation e-mail will be sent to your e-mail.
-
In the e-mail there will be a long PGP KEY message like this:
---BEGIN PGP MESSAGE---
Version: GnuPG v1
xxxxxxxxxxx
xxxxxxxxxxx
xxxxxxxxxxx
---END PGP MESSAGE---
- Open your terminal and create file call opgpm.txt.
vi opgpm.txt
-
Copy and paste the PGP message from the e-mail to the file.
-
Then execute the following command
gpg -d opgpm.txt
- Output below confirms that a process is done successfully.
gpg: encrypted with 3072-bit RSA key, ID XXXXXXXXXXXX, created 2019-05-23
"Rangsiman Ketkaew test_test@gmail.com;"
...
...
- Then submit SSH key to Ubuntu server again.
gpg --keyserver keyserver.ubuntu.com --send-keys TESTKEY112233
Upload SSH key to LaunchPad
-
Go to https://launchpad.net/~/+editsshkeys
-
Copy a key from ~/.ssh/id_rsa.pub and paste to text box and then click Import Public Key.
Configure the shell
- Environment variable
export DEBFULLNAME="Rangsiman Ketkaew"
export DEBEMAIL="test_test@gmail.com"
- Now save the file and either restart your terminal or run:
source ~/.bashrc
Prepare your program
-
In this post, I will use a simple program hello world as an example.
-
Download source code of GNU hello version 2.10 from its library.
wget -O hello-2.10.tar.gz "http://ftp.gnu.org/gnu/hello/hello-2.10.tar.gz"
- Uncompress the tarball:
tar xf hello-2.10.tar.gz
cd hello-2.10
- This application uses the autoconf build system so we want to run ./configure to prepare for compilation.
./configure
- Compile program and install it. Binary executable file of hello program will be installed at /usr/local/bin/.
make
sudo make install
- Test program by running:
hello
Build .deb file
The following content is proposed by https://ubuntuforums.org/showthread.php?t=910717 .
- Decide on the name of your package. For example, you could name your first package
helloworld_2.10-1
- Create a directory to make your package in. The name should be the same as the package name.
mkdir helloworld_2.10-1
- Pretend that the packaging directory is actually the root of the file system. Put the files of your program where they would be installed to on a system.
mkdir helloworld_2.10-1/usr
mkdir helloworld_2.10-1/usr/local
mkdir helloworld_2.10-1/usr/local/bin
cp "~/Projects/Hello World/helloworld" helloworld_2.10-1/usr/local/bin
- Now create a special metadata file with which the package manager will install your program…
mkdir helloworld_2.10-1/DEBIAN
gedit helloworld_2.10-1/DEBIAN/control
- Put something like this in that file…
Package: helloworld
Version: 2.10-1
Section: base
Priority: optional
Architecture: i386
Depends: debhelper (>= 9)
Maintainer: Rangsiman Ketkaew <test_test@gmail.com>
Description: Hello World
When you need some sunshine, just run this
small program!
(the space before each line in the description is important)
- Now you just need to make the package:
dpkg-deb --build helloworld_1.0-1
- Done!
Tips
bzr-builddeb includes a plugin to create a new package from a template. The plugin is a wrapper around the dh_makecommand. Run the command providing the package name, version number, and path to the upstream tarball:
sudo apt-get install dh-make bzr-builddeb
bzr dh-make hello 2.10 hello-2.10.tar.gz
When it asks what type of package type s for single binary. This will import the code into a branch and add the debian/packaging directory. Have a look at the contents. Most of the files it adds are only needed for specialist packages (such as Emacs modules) so you can start by removing the optional example files:
cd hello/debian
rm *ex *EX