1
votes

I build a debian package with cmake/cpack.I want the deb execute a bash script after i install the deb.I install the deb use sudo dpkg -i my.deb.if I install the deb like that, the installed program's user and group is root. so I want the deb auto-execute a bash script to modify the user and group using the current logged user and group.

I search the infomations about this with Google.I find SET(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA, ./script/postinst) can do this.So I do like that,but there is no use with it.

I do like this:

install(PROGRAMS ${CMAKE_SOURCE_DIR}/script/postinst DESTINATION ./script)

set(CPACK_GENERATOR "DEB")

set(CPACK_PACKAGE_NAME "mydeb")

set(CPACK_PACKAGE_VERSION "1.0")

set(CPACK_DEBIAN_PACKAGE_MAINTAINER "George")

set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA, ./script/postinst)

set(CPACK_PACKAGING_INSTALL_PREFIX "usr")

include(CPACK)

the postinst is a bash scritp to modify the installed program's user and group with the current logged user and group

If some thing is wrong ? I need help

2

2 Answers

1
votes

I do this in the same way. In my case I use the set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA, ./script/postinst) to set a systemd service to run at boot.

And similarly I use set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA, ./script/prerm) to cleanly remove the service from the boot sequence before actually removing the Debian package.

An important note here is that you do NOT need to install these files seperately. set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA, ./script/postinst) is sufficient, hence install(DIRECTORY ${CMAKE_SOURCE_DIR}/scripts/ DESTINATION ${SCRIPT_DESINATION} is not required. Do make sure the permissions of these additional scripts is set correctly.

0
votes

In general, the postinst script shouldn't modify anything directly related to one user, but should complete the installation for the system as a whole. For example, if you need to generate configuration files based on hardware present on the system, you might use postinst scripts. I don't know what your user script could be doing to suggest a possible alternative.