2017-06-19 08:26:55 +02:00
|
|
|
#!/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"
|
2017-10-07 12:06:56 +02:00
|
|
|
/usr/bin/getent group "${arr[1]}" >> /dev/null || /usr/sbin/groupadd -r $ARGUMENTS || exit $?
|
2017-06-19 08:26:55 +02:00
|
|
|
;;
|
|
|
|
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"
|
2017-10-07 12:06:56 +02:00
|
|
|
/usr/bin/getent passwd ${arr[1]} >> /dev/null || /usr/sbin/useradd -r -s /sbin/nologin -c "${arr[3]}" $ARGUMENTS || exit $?
|
2017-06-19 08:26:55 +02:00
|
|
|
;;
|
|
|
|
m*)
|
|
|
|
eval arr=( $LINE )
|
|
|
|
echo "usermod -a -G ${arr[2]} ${arr[1]}"
|
2017-10-07 12:06:56 +02:00
|
|
|
/usr/sbin/usermod -a -G ${arr[2]} ${arr[1]} || exit $?
|
2017-06-19 08:26:55 +02:00
|
|
|
;;
|
|
|
|
r*)
|
|
|
|
echo "range option ignored: \"$LINE\""
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Syntax Error: \"$LINE\""
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|