Create user and group with CPack

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Create user and group with CPack

Kristian
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. 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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Create user and group with CPack

Eric Noulard



2017-07-20 10:39 GMT+02:00 Kristian <[hidden email]>:
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?

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

--

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
|  
Report Content as Inappropriate

Re: Create user and group with CPack

Kristian
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 <[hidden email]>:

>
>
>
> 2017-07-20 10:39 GMT+02:00 Kristian <[hidden email]>:
>>
>> 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
--

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
|  
Report Content as Inappropriate

Re: Create user and group with CPack

Eric Noulard


2017-07-20 12:01 GMT+02:00 Kristian <[hidden email]>:
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.
=====

What is the shebang your ar using at the top of this script?

this syntax:
WEB_GROUP_ID="$(getent group '$WEB_GROUP' | cut -d: -f3)"

may be bash only.

not sure it makes a difference but you could try:

WEB_GROUP_ID="$(getent group '${WEB_GROUP}' | cut -d: -f3)"

note that getting the numeric group id seems unecessary.

useradd "$WEB_USER" -g "${WEB_GROUP}" -M -r -s /sbin/nologin -c

should work, useradd should work equally well with numeric or symbolic id of a group.


--
Eric

--

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
|  
Report Content as Inappropriate

Re: Create user and group with CPack

Kristian
Ok, I changed the postinstall script based on your suggestions:

i.e. I changed these two lines:
> WEB_GROUP_ID="$(getent group "${WEB_GROUP}" | cut -d: -f3)"
and
> useradd "$WEB_USER" -g "${WEB_GROUP}" -M -r -s /sbin/nologin -c

And it worked now. Thank you for your help. :)



2017-07-20 12:35 GMT+02:00 Eric Noulard <[hidden email]>:

>
>
> 2017-07-20 12:01 GMT+02:00 Kristian <[hidden email]>:
>>
>> 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.
>> =====
>
>
> What is the shebang your ar using at the top of this script?
>
> this syntax:
> WEB_GROUP_ID="$(getent group '$WEB_GROUP' | cut -d: -f3)"
>
> may be bash only.
>
> not sure it makes a difference but you could try:
>
> WEB_GROUP_ID="$(getent group '${WEB_GROUP}' | cut -d: -f3)"
>
> note that getting the numeric group id seems unecessary.
>
> useradd "$WEB_USER" -g "${WEB_GROUP}" -M -r -s /sbin/nologin -c
>
> should work, useradd should work equally well with numeric or symbolic id of
> a group.
>
>
> --
> Eric
--

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
|  
Report Content as Inappropriate

Re: Create user and group with CPack

Eric Noulard


2017-07-20 13:48 GMT+02:00 Kristian <[hidden email]>:
Ok, I changed the postinstall script based on your suggestions:

i.e. I changed these two lines:
> WEB_GROUP_ID="$(getent group "${WEB_GROUP}" | cut -d: -f3)"
and
> useradd "$WEB_USER" -g "${WEB_GROUP}" -M -r -s /sbin/nologin -c

And it worked now. Thank you for your help. :)

You are welcome.

As you may have guessed the first line 
WEB_GROUP_ID="$(getent group "${WEB_GROUP}" | cut -d: -f3)"

may be suppressed if 
useradd "$WEB_USER" -g "${WEB_GROUP}" -M -r -s /sbin/nologin -c

is OK.
--
Eric

--

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
Loading...