#!/bin/sh
#
# adduser(8) - add a user to the system
#

VERSION="#VERSION#"

usage(){
echo "Usage: adduser [USERNAME]... [OPTION]..."
echo "Add a user to the system using the standard bash shell and"
echo "install some default settings for the user."
echo
echo "  -h, --help              print this help and exit"
echo "  -v, --version           output version information and exit"
echo
echo "Report bugs to <johne@rootlinux.org>."
exit 0
}

displayversion(){
echo "adduser (rltools) $VERSION"
exit 0
}

if [ ! "$UID" = 0 ]; then
  echo "adduser: you must be root to add users."
  exit 1
fi

if [ "$1" = "-h" -o "$1" = "--help" ]; then
  usage
fi

if [ "$1" = "-v" -o "$1" = "--version" ]; then
  displayversion
fi

if [ "$1" = "" ]; then
    echo -n "New user's name: "
    read user
  else
    user=$1
fi

if [ -z "$user" ]; then
    echo "adduser: no username specificed."
    exit 1
  else
    mkdir -p /home/$user 2>/dev/null >/dev/null
    useradd -g users -s /bin/bash -d /home/$user $user
fi

cp -r /etc/skel/.???* /home/$user

# Set permissions
chmod 644 /home/$user -R
if [ -d /home/$user/.kde ]; then
chmod 700 /home/$user/.kde -R
fi
chown $user.users /home/$user -R
chmod 700 /home/$user

# End of file
