add an existing user to an existing group?
I am writing a SlackBuild script and in the doinst.sh file I need to create a user "someuser" and a group "somegroup" and then add that user to that group.
So far I figured out how to check if the user already exists:
if cat /etc/passwd | cut -f 1 -d : | grep -q someuser; then echo "there is someuser"; fi
whether the group exists:
if cat /etc/group | cut -f 1 -d : | grep -q someuser; then echo "there is somegroup"; fi
and whether the user someuser is a member of the group somegroup:
if groups someuser | grep -q somegroup; then echo "is a member";else echo "is not a member"; fi
The question is in case both the user and the group exist, but the user is not a member of the group, how do I add that user to that group. In short how do I add an existing user to an existing group?
Googling has suggested doing it by:
usermod -aG somegroup someuser
Unfortunately the usermod command on Slackware 12.0 does not support the -a option. I need the latter because I do not want to lose the other groups that someuser is a member of. Is there some other simple way of doing that?
Any suggestions will be appreciated.
PS Let me know if the usermod command in Slackware 12.1 supports the -a option.