[CMake] Create user and group with CPack

Kristian kristianonline28 at gmail.com
Thu Jul 20 06:01:34 EDT 2017


Hi,

thank you for your reply. Yes, I add the script with
> set(CPACK_RPM_POST_INSTALL_SCRIPT_FILE "${CMAKE_CURRENT_SOURCE_DIR}/postinstall")

and it basically works, because this file is changing a settings file
without any problems. Only the add of the group and the user does not
work, somehow.

This is the part in the postinstall script, which should add group and user:

=====
WEB_USER=web1
WEB_GROUP=web1

# create group
groupadd "${WEB_GROUP}" --force --system
# retrieve group id
WEB_GROUP_ID="$(getent group '$WEB_GROUP' | cut -d: -f3)"
echo "Group '${WEB_GROUP}' added with id '${WEB_GROUP_ID}'"
# create user
useradd "$WEB_USER" -g "${WEB_GROUP_ID}" -M -r -s /sbin/nologin -c
"Web user - created during the installation."
echo "User '${WEB_USER}' added."
=====

And this is, what is being printed during installation:
=====
Group 'web1' added with id ''
useradd: group '' does not exist
User 'web1' added.
=====


2017-07-20 11:17 GMT+02:00 Eric Noulard <eric.noulard at gmail.com>:
>
>
>
> 2017-07-20 10:39 GMT+02:00 Kristian <kristianonline28 at gmail.com>:
>>
>> Hi,
>>
>> I create a RPM package with CPack. When installing this package on a
>> target system, it should create an additional user and group.
>>
>> My current solution is a postinstall script, wich runs at the end of
>> the installation. There, I added commands to create a user and a group
>> (groupadd, useradd). But somehow, they aren't created when installing
>> this RPM package.
>
>
> Did you specify this post install script to CPackRPM?
> https://cmake.org/cmake/help/v3.7/module/CPackRPM.html#variable:CPACK_RPM_POST_INSTALL_SCRIPT_FILE
>
> You can check that the generated RPM does include the script with:
>
>  rpm -qp --scripts  <yourpackage>.rpm
>
>>
>> For testing, I install this RPM package in a docker
>> container.
>>
>> I also tried, if these commands (groupadd, useradd) are working on the
>> docker container and they are, so this shouldn't be a problem.
>>
>> So, how can I create a user and a group with CPack / CMake?
>> --
>>
>> 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
>
>
>
>
> --
> Eric


More information about the CMake mailing list