sysuser-tools/sysusers2shadow.sh
Marcus Meissner ac43675b41 Accepting request 528932 from home:dimstar:Factory
Any thoughts about this change? currently we simply hide all errors deep into zypp's log files and somehow hope the system would be working in the end

OBS-URL: https://build.opensuse.org/request/show/528932
OBS-URL: https://build.opensuse.org/package/show/Base:System/sysuser-tools?expand=0&rev=11
2017-10-07 10:06:56 +00:00

49 lines
1.3 KiB
Bash

#!/bin/bash
while read LINE
do
case "$LINE" in
\#*|"")
;;
g*)
eval arr=( $LINE )
ARGUMENTS="${arr[1]}"
if [ ! -z "${arr[2]}" -a "${arr[2]}" != "-" ]; then
ARGUMENTS="-g ${arr[2]} $ARGUMENTS"
fi
echo "groupadd -r $ARGUMENTS"
/usr/bin/getent group "${arr[1]}" >> /dev/null || /usr/sbin/groupadd -r $ARGUMENTS || exit $?
;;
u*)
eval arr=( $LINE )
ARGUMENTS="${arr[1]}"
if [ ! -z "${arr[2]}" -a "${arr[2]}" != "-" ]; then
ARGUMENTS="-u ${arr[2]} $ARGUMENTS"
fi
if [ ! -z "${arr[4]}" -a "${arr[4]}" != "-" ]; then
ARGUMENTS="-d ${arr[4]} $ARGUMENTS"
fi
/usr/bin/getent group ${arr[1]} >> /dev/null
if [ $? -eq 0 ]; then
ARGUMENTS="-g ${arr[1]} $ARGUMENTS"
else
ARGUMENTS="-U $ARGUMENTS"
fi
echo "useradd -r -s /sbin/nologin -c \"${arr[3]}\" $ARGUMENTS"
/usr/bin/getent passwd ${arr[1]} >> /dev/null || /usr/sbin/useradd -r -s /sbin/nologin -c "${arr[3]}" $ARGUMENTS || exit $?
;;
m*)
eval arr=( $LINE )
echo "usermod -a -G ${arr[2]} ${arr[1]}"
/usr/sbin/usermod -a -G ${arr[2]} ${arr[1]} || exit $?
;;
r*)
echo "range option ignored: \"$LINE\""
;;
*)
echo "Syntax Error: \"$LINE\""
exit 1
;;
esac
done