From f27d461663bec17ad64422682f260f0020ccc7f7 Mon Sep 17 00:00:00 2001 From: Luca BRUNO Date: Sep 30 2022 15:31:34 +0000 Subject: 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. --- diff --git a/sysusers.generate-pre.sh b/sysusers.generate-pre.sh index 5e56179..829d11e 100755 --- a/sysusers.generate-pre.sh +++ b/sysusers.generate-pre.sh @@ -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