#!/bin/bash
#makeusr [-u uid] [-g gid] [-i info] [-h homedir] [-s shell] username
	function usage
	{
			echo ‘usage: makeusr [-u uid] [-g gid] [-i info] [-h homedir] ‘
			echo ‘[-s shell] username
			exit 1
	}

	function helpmessage
	{
			echo "makeusr is a script ... "
			echo "blablabla"
	}

	while getopts "u:g:i:h:s:" opt; do
			case $opt in
				u ) uid=$OPTARG ;;
				g ) gid=$OPTARG ;;
				i ) info=$OPTARG ;;
				h ) home=$OPTARG ;;
				s ) shell=$OPTARG ;;
				? ) helpmessage ;;
				* ) usage ;;
			esac
	shift $(($OPTIND -1))
	done

	if [ -z "$1" ]; then
			usage
	fi

	if [ -n "$2" ]; then
			usage
	fi

	if [ -z "$uid" ]; then
			uid=500
			while cut -d : -f3 /etc/passwd | grep -x $uid
			do
				uid=$((uid+1)) > /dev/null
			done
	fi

	if [ -z "$gid" ]; then
			gid=$(grep users /etc/group | cut -d: -f3)
	fi

	if [ -z "$info" ]; then
			echo Provide information about the user.
			read info
	fi

	if [ -z "$home" ]; then
			home=/home/$1
	fi

	if [ -z "$shell" ]; then
			shell=/bin/bash
	fi

	echo $1:x:$uid:$gid:$info:$home:$shell >> /etc/passwd
	echo $1:::::::: >> /etc/shadow
	mkdir -p $home
	chmod 660 $home
	chown $1:users $home
	passwd $1
