[CMake] How to run bash shell script during rpm installation?

Eric Noulard eric.noulard at gmail.com
Tue Jul 10 02:53:21 EDT 2012


2012/7/10 jupiter <jupiter.hce at gmail.com>:
> Hi,
>
> I need to run shell script to do following check and to install
> configure files during RPM installation:
>
> if config files installed in /etc/myconfig, rename files in
> /etc/myconfig and copy new config files to /etc/myconfig;
> else copy config files to /etc/myconfig
>
> Is there a simple way to do it?

If you flag your config file with %config, then RPM should do just that.
If you use %config,(noreplace) then the old config file will be kept
and the new installed
with extra .rpmnew extension.

for that you can do:
set(CPACK_RPM_USER_FILELIST "%config /etc/myconfig")

if you use component packaging then
set(CPACK_RPM_<COMPONENT>_USER_FILELIST  "%config /etc/myconfig")

see:
cpack --help-variable CPACK_RPM_USER_FILELIST

> I am not clear if the install(SCRIPT
> ...) can be used, I guess the cmake script can be invoked during
> installation to call execute_process() for bash shell commands, but
> where I can copy my configuration source files from?

Invoking cmake at package install time (when rpm runs) may fail because cmake
is not there. Usually rpm post/pre [un]install script are bare shell script.

You can insert such scripts with CPackRPM using
CPACK_RPM_POST_INSTALL_SCRIPT_FILE
CPACK_RPM_PRE_INSTALL_SCRIPT_FILE

cpack --help-variable CPACK_RPM_POST_INSTALL_SCRIPT_FILE
cpack --help-variable CPACK_RPM_PRE_INSTALL_SCRIPT_FILE


The general solution for "portable" pre/post install script is an open issue:
http://www.cmake.org/pipermail/cmake/2012-April/050045.html
-- 
Erk
Le gouvernement représentatif n'est pas la démocratie --
http://www.le-message.org


More information about the CMake mailing list