azure-osconfig/devops/debian
Ahmed Messaoud 535a8074c5
Removed module identity on package removal (#375)
2022-09-28 14:15:49 -07:00
..
README.md Moving Debian packaging files to dedicated DevOps directory (#11) 2021-11-10 11:21:32 -08:00
postinst Removed module identity on package removal (#375) 2022-09-28 14:15:49 -07:00
postrm Moving Debian packaging files to dedicated DevOps directory (#11) 2021-11-10 11:21:32 -08:00
prerm Removed module identity on package removal (#375) 2022-09-28 14:15:49 -07:00

README.md

Debian Packaging Overview

OSConfig makes use of CPack (CPackDeb) to package the binary into a debian package. Although CPack take care of generating the Debian control file, it does not work well for specifying custom behavior using debhelpers. The Debian Maintainers Guide encourages using the debhelpers to onboard system unit files which CPack doesn't play well with. CPack does provide entrypoints into the mainteannce scripts using the CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA variable, which is what the purpose of the files in this directory.

The scripts contained in this directory are automatically generated by debhelpers but NOT by CPack. See the maintainers guide for more details.

How to generate the debhelpers to feed into CPack

  • Install debhelpers - sudo apt install dh-make dh-systemd
  • Generate source package - cmake --build . --target package
  • Move source package into directory named mkdir <package>-<version> ex.
    mkdir osconfig-0.3.0 && cd osconfig-0.3.0
    mv osconfig-0.3.0-Linux.tar.gz osconfig-0.3.0
    cd osconfig-0.3.0
    dh_make -f osconfig-0.3.0-Linux.tar.gz
    
  • dh_make will stage the debian packaging templates:
.
|-- debian
|   |-- README.Debian
|   |-- README.source
|   |-- changelog
|   |-- control
|   |-- copyright
|   |-- manpage.1.ex
|   |-- manpage.sgml.ex
|   |-- manpage.xml.ex
|   |-- osconfig-docs.docs
|   |-- osconfig.cron.d.ex
|   |-- osconfig.doc-base.EX
|   |-- postinst.ex
|   |-- postrm.ex
|   |-- preinst.ex
|   |-- prerm.ex
|   |-- rules
|   |-- salsa-ci.yml.ex
|   |-- source
|   |   `-- format
|   `-- watch.ex
`-- osconfig-0.3.0.tar.gz
  • Copy the osconfig.service file into the debian directory. The debhelpers will automatically detect a service file and use it to stage the the scripts accordingly.
  • Modify debian/rules and add a new target called override_dh_installsystemd which performs the dh_installsystemd command like so....
override_dh_installsystemd:
	dh_installsystemd --name=osconfig
  • Now run debian/rules binary, this will generate the debian package. We are not interested in the package as we will be using CPack's package but what is of interest here is the maintenance scripts, namely postinst, postrm and prerm which we will use to build our own based on these scripts and the templates named accordingly (*.ex).
.
|-- debian
|   |-- README.Debian
|   |-- README.source
|   |-- changelog
|   |-- control
|   |-- copyright
|   |-- debhelper-build-stamp
|   |-- files
|   |-- manpage.1.ex
|   |-- manpage.sgml.ex
|   |-- manpage.xml.ex
|   |-- osconfig
|   |   |-- DEBIAN
|   |   |   |-- control
|   |   |   |-- md5sums
|   |   |   |-- postinst  <-----------------
|   |   |   |-- postrm    <-----------------
|   |   |   `-- prerm     <-----------------
|   |   |-- lib
|   |   |   `-- systemd
|   |   |       `-- system
|   |   |           `-- osconfig.service
|   |   `-- usr
|   |       `-- share
|   |           `-- doc
|   |               `-- osconfig
|   |                   |-- README.Debian
|   |                   |-- changelog.Debian.gz
|   |                   `-- copyright
|   |-- osconfig-docs.docs
|   |-- osconfig.cron.d.ex
|   |-- osconfig.doc-base.EX
|   |-- osconfig.postrm.debhelper
|   |-- osconfig.service
|   |-- osconfig.substvars
|   |-- postinst.ex     <---- templates
|   |-- postrm.ex       <---- templates
|   |-- preinst.ex      <---- templates
|   |-- prerm.ex
|   |-- rules
|   |-- salsa-ci.yml.ex
|   |-- source
|   |   `-- format
|   `-- watch.ex
`-- osconfig-0.3.0.tar.gz
  • To builds the scripts in this directory, we use the template as a base and replace the #DEBHELPER# with the contents of <build_root>/osconfig-0.3.0/debian/osconfig/DEBIAN/<script>
  • These scripts are used in CPack's CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA variable.