diff --git a/sysuser-tools.changes b/sysuser-tools.changes index 86b90d3..e40311e 100644 --- a/sysuser-tools.changes +++ b/sysuser-tools.changes @@ -1,3 +1,9 @@ +------------------------------------------------------------------- +Wed Mar 25 07:53:55 UTC 2020 - Fabian Vogt + +- Fix bug introduced by simplification of check for useradd -g +- Refactor use of sed away + ------------------------------------------------------------------- Tue Mar 24 10:01:39 UTC 2020 - Fabian Vogt diff --git a/sysusers2shadow.sh b/sysusers2shadow.sh index 3c55131..c91c9ac 100644 --- a/sysusers2shadow.sh +++ b/sysusers2shadow.sh @@ -41,26 +41,27 @@ do if [ -n "${2-}" ] && [ "$2" != "-" ]; then ARGUMENTS="-u $2 $ARGUMENTS" fi - if [ -n "${4-}" ] && [ "$4" != "-" ]; then - ARGUMENTS="-d $4 $ARGUMENTS" - else - ARGUMENTS="-d / $ARGUMENTS" + homedir="/" # If null, empty or '-' + if [ "${4:--}" != "-" ]; then + homedir="$4" fi if [ -x /usr/sbin/useradd ]; then if ! /usr/bin/getent passwd "$1" >> /dev/null; then # this is useradd/shadow specific - ARGUMENTS="-g $1 $ARGUMENTS" - /usr/bin/getent group "$1" >> /dev/null || ARGUMENTS="-U $ARGUMENTS" + if /usr/bin/getent group "$1" >> /dev/null; then + ARGUMENTS="-g $1 $ARGUMENTS" + else + ARGUMENTS="-U $ARGUMENTS" + fi - run /usr/sbin/useradd -r -s /sbin/nologin -c "$3" $ARGUMENTS + run /usr/sbin/useradd -r -s /sbin/nologin -c "$3" -d "${homedir}" $ARGUMENTS fi elif [ -x "$busybox" ]; then /usr/bin/getent group "$1" >> /dev/null || $busybox addgroup "$1" - if ! /usr/bin/getent passwd $1 >> /dev/null; then - ARGUMENTS="$(echo -G $1 $ARGUMENTS | sed -e 's|-d|-h|g' -e 's|-g|-G|g')" - run $busybox adduser -S -H -s /sbin/nologin -g "$3" $ARGUMENTS + if ! /usr/bin/getent passwd "$1" >> /dev/null; then + run $busybox adduser -S -H -s /sbin/nologin -g "$3" -G "$1" -h "${homedir}" $ARGUMENTS fi else echo "ERROR: neither useradd nor busybox found!"