2020-05-27 22:51:02 +02:00
|
|
|
#!/bin/sh
|
2012-10-29 16:15:23 +01:00
|
|
|
#
|
|
|
|
# Here you can add your own stuff, that should be done for every user who
|
|
|
|
# was new created.
|
|
|
|
#
|
|
|
|
# When you create a user with useradd, this script will be called
|
|
|
|
# with the login name as parameter. Optional, UID, GID and the HOME
|
|
|
|
# directory are added.
|
|
|
|
#
|
|
|
|
|
|
|
|
case "$1" in
|
|
|
|
--help|--version)
|
|
|
|
echo Usage: $0 username [uid gid home]
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
# Check for the required argument.
|
|
|
|
if [ $# -lt 1 -o $# -gt 4 ]; then
|
|
|
|
echo Usage: $0 username [uid gid home]
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2020-10-09 15:16:40 +02:00
|
|
|
USER=$1
|
|
|
|
|
2020-11-02 16:56:45 +01:00
|
|
|
if [ $# -eq 4 ]; then
|
|
|
|
GID=$3
|
2020-10-09 15:16:40 +02:00
|
|
|
HOMEDIR=$4
|
2020-11-02 16:56:45 +01:00
|
|
|
else
|
|
|
|
GID=$(id -g $USER)
|
|
|
|
HOMEDIR=$(grep -E "^${USER}:" /etc/passwd| cut -d: -f6,6)
|
2020-10-09 15:16:40 +02:00
|
|
|
fi
|
|
|
|
|
2012-10-29 16:15:23 +01:00
|
|
|
# Update NIS database
|
|
|
|
# make -C /var/yp
|
|
|
|
|
2020-11-02 16:56:45 +01:00
|
|
|
# Main useradd tool creates this if specified on command line
|
|
|
|
[ -d $HOMEDIR ] || exit 0
|
|
|
|
|
|
|
|
#
|
|
|
|
# Copy also skeleton files from /usr/etc/skel (boo#1173321)
|
|
|
|
#
|
|
|
|
USRSKELDIR=/usr/etc/skel
|
|
|
|
if [ -d $USRSKELDIR ] ; then
|
|
|
|
for file in $(ls -A $USRSKELDIR); do
|
|
|
|
# Only copy if not exist yet, i.e. does *not* exist in /etc/skel, which is still
|
|
|
|
# being preferred ...
|
|
|
|
test -e $HOMEDIR/$file && continue
|
|
|
|
cp -a $USRSKELDIR/$file $HOMEDIR
|
|
|
|
chown -R $USER.$GID $HOMEDIR/$file
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
2012-10-29 16:15:23 +01:00
|
|
|
# If SELinux is enabled, we have to run restorecon to assign
|
|
|
|
# appropriate fcontexts to the respective $HOME and files under it
|
|
|
|
if [ -x /usr/sbin/selinuxenabled ] && /usr/sbin/selinuxenabled ; then
|
|
|
|
test -x /sbin/restorecon || exit 2
|
|
|
|
|
2020-11-02 16:56:45 +01:00
|
|
|
/sbin/restorecon -R $HOMEDIR
|
2012-10-29 16:15:23 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
# All done.
|
|
|
|
exit 0
|