Search code examples
linuxcmakeyumcpack

using cmake to install files to /usr/sbin


I'm having some issues installing a script into /usr/sbin from a cmake script. In my packaging.cmake I have

install(FILES "${CMAKE_SOURCE_DIR}/kpcmdctrl" DESTINATION /usr/sbin COMPONENT kptester
            PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ)

and in the generated spec file:

%files                       
%defattr(-,root,root,-)      
%dir "/opt/mycomp"      
%dir "/opt/mycomp/kptester_prog"
%dir "/opt/mycomp/kptester_prog/bin"
"/opt/mycomp/kptester_prog/bin/kptester"
%dir "/opt/mycomp/kptester_prog/etc"
%dir "/usr/sbin"

%config "/usr/sbin/kpcmdctrl"

when I run yum localinstall kptester-0.0.1-1.x86_64.rpm I get the following error:

Error: Transaction test error:
  file /usr/sbin from install of kptester-0.0.1-1.x86_64 conflicts with file from package filesystem-3.8-6.el8.x86_64

I've tried installing the script in other places such as /usr/bin and it works without issue. I've checked the package listing for filesystem-3.8-6.el8.x86_6 here and I can't see any reason for it to complain?

Am I missing something obvious or is /usr/sbin a special directory?


Solution

  • Posting my own solution in case anyone else comes across this problem. The problem was that the RPM was trying to own the system folder e.g. /usr/sbin. You can see this from the spec file I posted in the question: %dir "/usr/sbin"

    There is an option in cmake to tell it not do to this:

    set(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION "/usr/sbin")
    

    or if you have more than one system folder:

    list(APPEND CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION "/usr/sbin")
    

    The new spec file doesn't have the system folder listed as a directory and install works as expected.