sysusers/generate: bridge 'm' entries to usermod

This tweaks the sysusers.d handling logic so that 'm' entries are
now translated to a series of groupadd + useradd + usermod call.
The last usermod call is the notable change, effectively affecting
the list of secondary groups now.
This commit is contained in:
Luca BRUNO 2022-09-01 12:51:38 +00:00 committed by zbyszek
parent 7665e1796f
commit f27d461663

View File

@ -38,6 +38,7 @@ EOF
group() {
group="$1"
gid="$2"
if [ "$gid" = '-' ]; then
cat <<-EOF
getent group '$group' >/dev/null || groupadd -r '$group' || :
@ -49,6 +50,17 @@ group() {
fi
}
usermod() {
user="$1"
group="$2"
cat <<-EOF
if getent group '$group' >/dev/null; then
usermod -a -G '$group' '$user' || :
fi
EOF
}
parse() {
while read -r line || [ -n "$line" ] ; do
{ [ "${line:0:1}" = '#' ] || [ "${line:0:1}" = ';' ]; } && continue
@ -66,7 +78,8 @@ parse() {
;;
('m')
group "${arr[2]}" "-"
user "${arr[1]}" "-" "" "${arr[2]}"
user "${arr[1]}" "-" "" "${arr[1]}" "" ""
usermod "${arr[1]}" "${arr[2]}"
;;
esac
done