QT Deployment III – Generating a .deb package with Terminal command

It’s the 3rd chapter of deployment series. Why do you want to have a deb packaging?

Well, it gives upgradability, integration and packaging related with your file system. You can add it to your ppa and call with apt install command. It’s the legacy version of packaging. This chapter’s content files are added to GitHub Repository.

In first two chapters I’ve demonstrated to create with Qt’s installer framework option. This time this option will be closed for Debian packaging.

    "clear": true,
    "deploySystem": true,
    "extractPlugins": true,
    "noCheckRPATH": true,
    "qif": false,
    "qmlDir": "${CMAKE_SOURCE_DIR}",
    "qmake": "${CMAKE_PREFIX_PATH}/bin/qmake",
    "targetDir" : "${CMAKE_BINARY_DIR}/DeploymentPackage"

It is possible to remove “qif” key and it’s value from our Json template. It is possible to give a CMake variable to turn it on and off, if you want to build run and deb files in the same deployment time. I just want to declare and show it to you, so I turned this flag off. QIF option removes binary, libraries and other dependencies from deployment folder, this is why I turned it off.

Primitive way creating it from Terminal

Firstly I will deploy it with CQTDeployer then create .deb package with shell commands to show steps from it’s core. Next thing I want to do is using CMake’s CPack utility. As I told you CMake has a powerful arsenal. Let’s build our project and create deployable package.

Package Management

Pack is created for a Debian package we need a control file that specifies our package properties and for deployed pack. It also gives opportunity to run some commands for pre-post installation and remove processes of package.

In this tutorial I will deploy project under /opt/<project_name> path and link runner .sh script to /usr/local/bin to call it from terminal. Let’s start with control file and add a few parameters to it.

Package: deploymentproject
Maintainer: Muhammet Kucuk
Architecture: amd64
Version: 1.0.0
Homepage: https://muhammetkucuk.com
Description: It's an example for deployment

Maintainer parameter is a must for control file and you cannot deploy your project without a control file. It’s the most primitive control file. You also can make it like a template as I showed in previous post by using configure_file() function. At least you can add your project version package name from your CMake’s project name and etc.

From the previous slide our application runs with DeploymentProject.sh script it contains environment variables to export then calls our project’s binary. It is possible to export this variables to your .bashrc, but why do you want to suffer more?

BASE_DIR=$(dirname "$(readlink -f "$0")")
export QTDIR="$BASE_DIR"
"$BASE_DIR"/bin/DeploymentProject "$@"

Whenever .deb package deploys itself to client’s file system it will copy and paste it’s content but we need to link this .sh script to /usr/local/bin after it’s installed with a post installation script, then whenever client wants to remove it it also has to do call pre remove script to remove link. It’s about to time introduce postinst and prerm files and their contents.

chmod +x /opt/DeploymentProject/bin/DeploymentProject
chmod 755 /opt/DeploymentProject/bin/DeploymentProject
cp /opt/DeploymentProject/DeploymentProject.sh /opt/DeploymentProject/DeploymentProject
chmod +x /opt/DeploymentProject/DeploymentProject
chmod 755 /opt/DeploymentProject/DeploymentProject
ln -s /opt/DeploymentProject/DeploymentProject /usr/local/bin/DeploymentProject
rm /opt/DeploymentProject/DeploymentProject
rm /usr/local/bin/DeploymentProject

Note that, our control files permissions must be between >=555 and <=775

Okay we have control scripts and our deployment package. It’s time to create our own .deb file. YAAAY! Let’s create a folder MyDebianPackage and create another one called DEBIAN inside of it. Then move all control files under DEBIAN folder.

Control Files

Copy Deployment Project

It’s time to copy our deployment files to MyDebianPackage/opt/DeploymentPackage. After that we have a hierarchy like:

Packing it up!

Now file structure is ready to create our first .deb file for Qt application. we will just call one line of command to generate our file.

dpkg-deb --build MyDebianPackage

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *