pkgsrc-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[pkgsrc/trunk]: pkgsrc/mk/pkginstall Try to work around the mess called usera...



details:   https://anonhg.NetBSD.org/pkgsrc/rev/3ceffb72a484
branches:  trunk
changeset: 555774:3ceffb72a484
user:      joerg <joerg%pkgsrc.org@localhost>
date:      Sun Mar 08 19:39:03 2009 +0000

description:
Try to work around the mess called useradd on Linux. On Red Hat derived
distributions, useradd will create the home directory by default and
there is support for an option to disable that. Other Linux
distrubutions either lack the option in login.defs or the support for
-M. As workaround look for the option and if it is set, force -M.
Tested by Jens Rehsack. Addresses PR 40737.

diffstat:

 mk/pkginstall/usergroupfuncs.Linux |  43 ++++++++++++++++++++++++++-----------
 1 files changed, 30 insertions(+), 13 deletions(-)

diffs (64 lines):

diff -r ab4a66bb8238 -r 3ceffb72a484 mk/pkginstall/usergroupfuncs.Linux
--- a/mk/pkginstall/usergroupfuncs.Linux        Sun Mar 08 19:17:51 2009 +0000
+++ b/mk/pkginstall/usergroupfuncs.Linux        Sun Mar 08 19:39:03 2009 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: usergroupfuncs.Linux,v 1.4 2009/02/02 19:54:22 joerg Exp $
+# $NetBSD: usergroupfuncs.Linux,v 1.5 2009/03/08 19:39:03 joerg Exp $
 #
 # Platform-specific adduser and addgroup functionality
 # on top of shadow-utils.  (Not libuser)
@@ -83,6 +83,30 @@
        ${RM} -fr $_tmpdir; return 3
 }
 
+# The useradd command on Linux is a complete mess.
+# At least Red Hat derivatives want to create home directories
+# by default. They have support for -M, but no --help.
+# Other Linux distributions lack -M support, some at least have
+# --help.
+# LSB just wants useradd, but doesn't specify any behavior, so
+# it is useless for writing portable scripts.
+
+call_useradd()
+{
+       case $userid in
+       "")
+               ${USERADD}                                      \
+                       -c "$descr" -d "$home" -s "$shell"      \
+                       -g $group $user "$@"
+               ;;
+       *)
+               ${USERADD}                                      \
+                       -c "$descr" -d "$home" -s "$shell"      \
+                       -g $group -u $userid $user "$@"
+               ;;
+       esac
+}
+
 # adduser user group [userid] [descr] [home] [shell]
 adduser()
 {
@@ -104,18 +128,11 @@
 
        if ${TEST} -n "${USERADD}" -a -x "${USERADD}"; then
                ${ECHO} "${PKGNAME}: Creating user \`\`$user''"
-               case $userid in
-               "")
-                       ${USERADD}                                      \
-                               -c "$descr" -d "$home" -s "$shell"      \
-                               -g $group $user -M
-                       ;;
-               *)
-                       ${USERADD}                                      \
-                               -c "$descr" -d "$home" -s "$shell"      \
-                               -g $group -u $userid $user -M
-                       ;;
-               esac
+               if grep -i -- "^CREATE_HOME.*yes" /etc/login.defs > /dev/null; then
+                       call_useradd -M
+               else
+                       call_useradd
+               fi
        fi
        return 0
 }



Home | Main Index | Thread Index | Old Index