Subject: Re: mk/install/usergroup and FreeBSD and DragonFly
To: None <tech-pkg@NetBSD.org>
From: Jeremy C. Reed <reed@reedmedia.net>
List: tech-pkg
Date: 09/07/2005 10:33:29
On Wed, 7 Sep 2005, Johnny Lam wrote:

> Actually, it's probably not so bad just to have shell functions defined in a 
> file that get directly inserted into the head of the +USERGROUP script.  That 
> would remove the need for the extra helper scripts.  The file defining the 
> shell functions useradd() and groupadd() would be unique to each platform.

An untested idea for NetBSD:

# useradd user group descr home shell [userid]
USERADD_FUNCTION= \
useradd()
{
 	_user=$1
 	_group=$2
 	_descr=$3
 	_home=$4
 	_shell=$5
 	_userid=$6

 	if [ -z "$_user" ]; then
 		echo some error
 		return
 	fi

 	if [ -z "$_userid" ]; then
 		${USERADD} -c "$_descr" -d "$_home" -s "$_shell" \
 			 -g $_group $_user
 	else
 		${USERADD} -c "$_descr" -d "$_home" -s "$_shell" \
 			-g $_group -u $_userid $_user
 	fi

}

Should it gather return value?

Maybe for DragonFly:

USERADD="/usr/sbin/pw"
USERADD_ARGUMENTS="user add"

# useradd user group descr home shell [userid]
USERADD_FUNCTION= \
useradd()
{
 	_user=$1
 	_group=$2
 	_descr=$3
 	_home=$4
 	_shell=$5
 	_userid=$6

 	if [ -z "$_user" ]; then
 		echo some error
 		return
 	fi

 	if [ -z "$_userid" ]; then
 		${USERADD} ${USERADD_ARGUMENTS} $_user -c "$_descr" \
 			 -d "$_home" -s "$_shell"  -g $_group
 	else
 		${USERADD} ${USERADD_ARGUMENTS} $_user -c "$_descr" \
 			-d "$_home" -s "$_shell" -g $_group -u $_userid
 	fi

}

(Need to add backslashes to end of each line?)


  Jeremy C. Reed

  	  	 	 open source, Unix, *BSD, Linux training
 	  	 	 http://www.pugetsoundtechnology.com/