sysuser-tools/sysusers2shadow.sh

49 lines
1.3 KiB
Bash
Raw Normal View History

#!/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
;;
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
;;
m*)
eval arr=( $LINE )
echo "usermod -a -G ${arr[2]} ${arr[1]}"
/usr/sbin/usermod -a -G ${arr[2]} ${arr[1]}
;;
r*)
echo "range option ignored: \"$LINE\""
;;
*)
echo "Syntax Error: \"$LINE\""
exit 1
;;
esac
done