RPM package and relocation

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

RPM package and relocation

Kristian
Hi,

I am creating an RPM package, which on a standard installation should
install the file into /opt/ssp-suite directory. But I want to give the
user the opportunity, to install the package into another directory.

I am doing this with these lines:

> set(INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/ssp-suite)
> install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/ssp/" DESTINATION ${INSTALL_DIR})

and by running cmake with

> cmake -DCMAKE_INSTALL_PREFIX=/opt -V --debug .

But I also need to execute a post script, which runs after installation. I added

> set(CPACK_RPM_POST_INSTALL_SCRIPT_FILE "${CMAKE_CURRENT_SOURCE_DIR}/postinstall")

to my CMakeLists.txt and in that script, I am using the RPM variable
$RPM_INSTALL_PREFIX. But during installation, I get this error message

> chmod: cannot access '/usr/usr/bin/startssp': No such file or directory
> warning: %post(ssp-suite-7.1-1.x86_64) scriptlet failed, exit status 1
> Non-fatal POSTIN scriptlet failure in rpm package ssp-suite-7.1-1.x86_64

Can someone give me some hints, how to change / add lines to
CMakeListst.txt and my postinstall script, so that script can be fully
relocatable?
--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: RPM package and relocation

Eric Noulard


2017-05-10 13:26 GMT+02:00 Kristian <[hidden email]>:
Hi,

I am creating an RPM package, which on a standard installation should
install the file into /opt/ssp-suite directory. But I want to give the
user the opportunity, to install the package into another directory.

I am doing this with these lines:

> set(INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/ssp-suite)
> install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/ssp/" DESTINATION ${INSTALL_DIR})

If you want to create relocatable package you should avoid install directive with absolute destination but rather do:

install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/ssp" DESTINATION ssp-suite)

then in our CMakeLists.txt before including CPack 

set(CPACK_RPM_PACKAGE_RELOCATABLE True)

 

and by running cmake with

> cmake -DCMAKE_INSTALL_PREFIX=/opt -V --debug .


CMAKE_INSTALL_PREFIX is not the prefix used by CPack.
You should use CPACK_PACKAGING_INSTALL_PREFIX:
 
Whatever the value you used for CMAKE_INSTALL_PREFIX at CMake runtime you may use another prefix for packaging when invoking CPack:

cpack -DCPACK_PACKAGING_INSTALL_PREFIX=/opt -G RPM

this will work for all files/target/dir installed with a **RELATIVE** path if you installed with an absolute path then the absolute path will be kept
making the package "partially" or "not-at-all" relocatable.

Non relocatable file are commonly placed in /etc/...
 

But I also need to execute a post script, which runs after installation. I added

> set(CPACK_RPM_POST_INSTALL_SCRIPT_FILE "${CMAKE_CURRENT_SOURCE_DIR}/postinstall")

to my CMakeLists.txt and in that script, I am using the RPM variable
$RPM_INSTALL_PREFIX. But during installation, I get this error message

> chmod: cannot access '/usr/usr/bin/startssp': No such file or directory
> warning: %post(ssp-suite-7.1-1.x86_64) scriptlet failed, exit status 1
> Non-fatal POSTIN scriptlet failure in rpm package ssp-suite-7.1-1.x86_64

I'm not quite up-to-date with CPack RPM and I guess Domen will step in for that but 
the specified script will be read and put into the RPM itself by CPackRPM.

However since you currently have absolute destination file the prefix may well be "/usr" even if you installed somewhere else.

Try:
rpm -qi -p <your>.rpm | grep Reloca

you'll get the relocations list unless the package is not relocatable.

If you want to investigate more about what CPack RPM is doing for you you may try:

cpack -D CPACK_RPM_PACKAGE_DEBUG=1 -G RPM

as indicated here:


Can someone give me some hints, how to change / add lines to
CMakeListst.txt and my postinstall script, so that script can be fully
relocatable?

I don't remember what variables may be used in POST/PRE install script files
but you may have a look at the generated spec file which may gives you clue about that.
The spec file generated by CPackRPM should be in:

<buildroot>/_CPack_Packages/<your_system_arch>/RPM/SPECS 

running CPack RPM with DEBUG var set to 1 will give you all file locaton.

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: RPM package and relocation

Craig Scott-3
In reply to this post by Kristian
You probably need to show us the postinstall script for us to be able to see the problem. Also, in case you haven't found it already, the MaximumRPM manual may be helpful (although it seems you've already found the essentials and that document could be getting a bit dated by now):


specifically chapter 15: Making A Relocatable Package and chapter 13: Scripts: RPM's Workhorse. You might also want to check you are not having the problem described in this stackoverflow answer regarding when variables get substituted.



On Wed, May 10, 2017 at 9:26 PM, Kristian <[hidden email]> wrote:
Hi,

I am creating an RPM package, which on a standard installation should
install the file into /opt/ssp-suite directory. But I want to give the
user the opportunity, to install the package into another directory.

I am doing this with these lines:

> set(INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/ssp-suite)
> install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/ssp/" DESTINATION ${INSTALL_DIR})

and by running cmake with

> cmake -DCMAKE_INSTALL_PREFIX=/opt -V --debug .

But I also need to execute a post script, which runs after installation. I added

> set(CPACK_RPM_POST_INSTALL_SCRIPT_FILE "${CMAKE_CURRENT_SOURCE_DIR}/postinstall")

to my CMakeLists.txt and in that script, I am using the RPM variable
$RPM_INSTALL_PREFIX. But during installation, I get this error message

> chmod: cannot access '/usr/usr/bin/startssp': No such file or directory
> warning: %post(ssp-suite-7.1-1.x86_64) scriptlet failed, exit status 1
> Non-fatal POSTIN scriptlet failure in rpm package ssp-suite-7.1-1.x86_64

Can someone give me some hints, how to change / add lines to
CMakeListst.txt and my postinstall script, so that script can be fully
relocatable?
--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake



--
Craig Scott
Melbourne, Australia

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: RPM package and relocation

Domen Vrankar
In reply to this post by Kristian
> set(INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/ssp-suite)
> install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/ssp/" DESTINATION ${INSTALL_DIR})

Eric already covered this part - use relative paths instead ( no / at the beginning).
 
But I also need to execute a post script, which runs after installation. I added

> set(CPACK_RPM_POST_INSTALL_SCRIPT_FILE "${CMAKE_CURRENT_SOURCE_DIR}/postinstall")

to my CMakeLists.txt and in that script, I am using the RPM variable
$RPM_INSTALL_PREFIX. But during installation, I get this error message

> chmod: cannot access '/usr/usr/bin/startssp': No such file or directory
> warning: %post(ssp-suite-7.1-1.x86_64) scriptlet failed, exit status 1
> Non-fatal POSTIN scriptlet failure in rpm package ssp-suite-7.1-1.x86_64


Pre/postinstall scripts are outside what CPackRPM is handling automatically but you can still use the relocation paths as supported by RPM.

Example for single relocation path:
set(CPACK_PACKAGING_INSTALL_PREFIX "/usr") # this will become the relocation path - becomes first relocation path

Example for multiple relocation paths:
set(CPACK_RPM_RELOCATION_PATHS "etc/foo" "opt/bar") # two paths that will be relocatable - etc will become first relocation path and opt the second one
set(CPACK_RPM_NO_INSTALL_PREFIX_RELOCATION ON) # this will remove the default /usr from relocation paths
set(CPACK_PACKAGING_INSTALL_PREFIX "/a") # relative paths will be prefixed with /a - there is a bug that prevents you from using "/" only for relocation paths so you might decide to patch CPackRPM.cmake yourself [1]


Now for the postinstall script each relocation path becomes a variable in RPM (RPM_INSTALL_PREFIX0 for first relocation path, RPM_INSTALL_PREFIX1 for the second and so on) so what you have to do in your script is instead of writing something like this:

chown someone:somegroup /etc/some_non_relocatable_path/some_file

you should write:

chown someone:somegroup ${RPM_INSTALL_PREFIX0}/some_non_relocatable_path/some_file

Regards,
Domen

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake