forked from pool/sysuser-tools
54305a4169
- Clean up sysusers2shadow and make it use only /bin/sh - Don't let busybox adduser create the home directory, it breaks permissions of e.g. /sbin (home of daemon) - Use only /bin/sh in sysusers-generate-pre and the generated code OBS-URL: https://build.opensuse.org/request/show/786819 OBS-URL: https://build.opensuse.org/package/show/Base:System/sysuser-tools?expand=0&rev=23
84 lines
2.0 KiB
Bash
84 lines
2.0 KiB
Bash
#!/bin/sh
|
|
set -eu
|
|
|
|
# Print the command and run it
|
|
run() {
|
|
echo "$@"
|
|
"$@"
|
|
}
|
|
|
|
# Absolute path to busybox, if found
|
|
busybox=
|
|
for i in /bin/busybox /usr/bin/busybox; do [ -x "$i" ] && busybox=$i; done
|
|
|
|
while read arg0 arg1 arg2 arg3 arg4
|
|
do
|
|
case "$arg0" in
|
|
g)
|
|
ARGUMENTS="${arg1}"
|
|
if [ -n "${arg2}" -a "${arg2}" != "-" ]; then
|
|
ARGUMENTS="-g ${arg2} $ARGUMENTS"
|
|
fi
|
|
|
|
if ! /usr/bin/getent group "${arg1}" >> /dev/null; then
|
|
if [ -x "/usr/sbin/groupadd" ]; then
|
|
run /usr/sbin/groupadd -r $ARGUMENTS
|
|
elif [ -x "$busybox" ]; then
|
|
run $busybox addgroup -S $ARGUMENTS
|
|
else
|
|
echo "ERROR: neither groupadd nor busybox found!"
|
|
exit 1
|
|
fi
|
|
fi
|
|
;;
|
|
u)
|
|
ARGUMENTS="${arg1}"
|
|
if [ -n "${arg2}" ] && [ "${arg2}" != "-" ]; then
|
|
ARGUMENTS="-u ${arg2} $ARGUMENTS"
|
|
fi
|
|
if [ -n "${arg4}" ] && [ "${arg4}" != "-" ]; then
|
|
ARGUMENTS="-d ${arg4} $ARGUMENTS"
|
|
else
|
|
ARGUMENTS="-d / $ARGUMENTS"
|
|
fi
|
|
|
|
if [ -x /usr/sbin/useradd ]; then
|
|
if ! /usr/bin/getent passwd "${arg1}" >> /dev/null; then
|
|
# this is useradd/shadow specific
|
|
ARGUMENTS="-g ${arg1} $ARGUMENTS"
|
|
/usr/bin/getent group "${arg1}" >> /dev/null || ARGUMENTS="-U $ARGUMENTS"
|
|
|
|
run /usr/sbin/useradd -r -s /sbin/nologin -c "${arg3}" $ARGUMENTS
|
|
fi
|
|
elif [ -x "$busybox" ]; then
|
|
/usr/bin/getent group "${arg1}" >> /dev/null || $busybox addgroup "${arg1}"
|
|
|
|
if ! /usr/bin/getent passwd ${arg1} >> /dev/null; then
|
|
ARGUMENTS="$(echo -G ${arg1} $ARGUMENTS | sed -e 's|-d|-h|g' -e 's|-g|-G|g')"
|
|
run $busybox adduser -S -H -s /sbin/nologin -g "${arg3}" $ARGUMENTS
|
|
fi
|
|
else
|
|
echo "ERROR: neither useradd nor busybox found!"
|
|
exit 1
|
|
fi
|
|
;;
|
|
m)
|
|
if [ -x /usr/sbin/usermod ] ; then
|
|
run /usr/sbin/usermod -a -G ${arg2} ${arg1}
|
|
elif [ -x "$busybox" ]; then
|
|
run $busybox addgroup ${arg1} ${arg2}
|
|
else
|
|
echo "ERROR: neither usermod nor busybox found!"
|
|
exit 1
|
|
fi
|
|
;;
|
|
r)
|
|
echo "range option ignored: \"$arg0 $arg1 $arg2 $arg3\""
|
|
;;
|
|
*)
|
|
echo "Syntax Error: \"$arg0\""
|
|
exit 1
|
|
;;
|
|
esac
|
|
done
|