#!/bin/sh

PROG="${0##*/}" #program name

print_version()
{
	cat <<EOF
$PROG version @VERSION@

Written by Stanislav Ievlev

Copyright (C) 2003-2004 ALT Linux Team
EOF
	exit
}

print_usage()
{
	[ "$1" = 0 ] || exec >&2
	cat <<EOF
Usage: $PROG [options] 

utility to manipulate system users: add, delete, modify

Valid options are:
  -h, --help	display help screen
  -v, --version	display version information
  -l, --list	get list of available users
  -d, --delete	delete some user
  -r, --read	read user information

Report bugs to <inger@altlinux.org>
EOF
	[ -n "$1" ] && exit "$1" || exit
}

field()
{
    echo $1|cut -f$2 -d:
}

TEMP=`getopt -n $PROG -o h,v,l,d:,r: -l help,version,list,delete:,read: -- "$@"` || print_usage
eval set -- "$TEMP"

while :; do
	case "$1" in
		-h|--help) print_usage 0
			;;
		-v|--version) print_version
			;;
		-l|--list)
			cut -f1 -d: /etc/passwd
			;;
		-d|--delete)
			shift;username=$1;
			/usr/sbin/userdel $1
			;;
		-r|--read)
			shift;username=$1;
			line=$(egrep "^$username:" /etc/passwd)
			echo "uid:$(field $line "3")"
			echo "gid:$(field $line "4")"
			echo "gecos:$(field $line "5")"
			echo "home:$(field $line "6")"
			echo "shell:$(field $line "7")"
			;;
		--) shift; break
			;;
		*) Fatal "unrecognized option: $1"
			;;
	esac
	shift
done

