Avoid failing in passwd if groups the user should be added to do not (yet) exist.
authorDaniel Baumann <daniel@debian.org>
Fri, 18 Jan 2013 19:32:23 +0000 (20:32 +0100)
committerDaniel Baumann <daniel@debian.org>
Fri, 18 Jan 2013 19:32:23 +0000 (20:32 +0100)
scripts/debconfig/0010-passwd

index 0158460..f7eaf60 100755 (executable)
@@ -380,7 +380,17 @@ then
 
        if [ -n "${_USER_DEFAULT_GROUPS}" ]
        then
-               _USER_OPTIONS="${_USER_OPTIONS} --groups $(echo ${_USER_DEFAULT_GROUPS} | sed -e 's| |,|g')"
+               _GROUPS=""
+
+               for _GROUP in ${_USER_DEFAULT_GROUPS}
+               do
+                       if getent group "${_GROUP}" > /dev/null 2>&1
+                       then
+                               _GROUPS="${_GROUPS} ${_GROUP}"
+                       fi
+               done
+
+               _USER_OPTIONS="${_USER_OPTIONS} --groups $(echo ${_GROUPS} | sed -e 's| |,|g')"
        fi
 
        if [ "${_USER_SYSTEM_USER}" = "true" ]
@@ -465,7 +475,17 @@ do
 
        if [ -n "${_DEFAULT_GROUPS}" ]
        then
-               _OPTIONS="${_OPTIONS} --groups $(echo ${_DEFAULT_GROUPS} | sed -e 's| |,|g')"
+               _GROUPS=""
+
+               for _GROUP in ${_DEFAULT_GROUPS}
+               do
+                       if getent group "${_GROUP}" > /dev/null 2>&1
+                       then
+                               _GROUPS="${_GROUPS} ${_GROUP}"
+                       fi
+               done
+
+               _OPTIONS="${_OPTIONS} --groups $(echo ${_GROUPS} | sed -e 's| |,|g')"
        fi
 
        if [ "${_SYSTEM_USER}" = "true" ]