[CMake] Create user and group with CPack
Kristian
kristianonline28 at gmail.com
Thu Jul 20 07:48:30 EDT 2017
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 <eric.noulard at gmail.com>:
>
>
> 2017-07-20 12:01 GMT+02:00 Kristian <kristianonline28 at gmail.com>:
>>
>> 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
More information about the CMake
mailing list