<commit_before>#!/bin/sh
#
# Copyright (c) 2002 <NAME> Makonnen. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
# 3. The name of the author may not be used to endorse or promote products
#    derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
#       Email: <NAME> <<EMAIL>>
#
# $FreeBSD$
#

# err msg
#       Display $msg on stderr, unless we're being quiet.
# 
err() {
	if [ -z "$quietflag" ]; then
        	echo 1>&2 ${THISCMD}: ERROR: $*
	fi
}

# info msg
#       Display $msg on stdout, unless we're being quiet.
# 
info() {
	if [ -z "$quietflag" ]; then
        	echo ${THISCMD}: INFO: $*
	fi
}

# get_nextuid
#	Output the value of $_uid if it is available for use. If it
#	is not, output the value of the next higher uid that is available.
#	If a uid is not specified, output the first available uid, as indicated
#	by pw(8).
# 
get_nextuid () {
	_uid=$1
	_nextuid=

	if [ -z "$_uid" ]; then
		_nextuid="`${PWCMD} usernext | cut -f1 -d:`"
	else
		while : ; do
			${PWCMD} usershow $_uid > /dev/null 2>&1
			if [ ! "$?" -eq 0 ]; then
				_nextuid=$_uid
				break
			fi
			_uid=$(($_uid + 1))
		done
	fi
	echo $_nextuid
}

# show_usage
#	Display usage information for this utility.
#
show_usage() {
	echo "usage: ${THISCMD} [options]"
	echo "  options may include:"
	echo "  -C		save to the configuration file only"
	echo "  -E		disable this account after creation"
	echo "  -G		additional groups to add accounts to"
	echo "  -L		login class of the user"
	echo "  -N		do not read configuration file"
	echo "  -d		home directory"
	echo "  -f		file from which input will be received"
	echo "  -h		display this usage message"
	echo "  -k		path to skeleton home directory"
	echo "  -m		user welcome message file"
	echo "  -q		absolute minimal user feedback"
	echo "  -s		shell"
	echo "  -u		uid to start at"
	echo "  -w		password type: no, none, yes or random"
}

# valid_shells
#	Outputs a list of valid shells from /etc/shells. Only the
#	basename of the shell is output.
#
valid_shells() {
	_prefix=
	cat ${ETCSHELLS} |
	while read _path _junk ; do
		case $_path in
		\#*|'')
			;;
		*)
			echo -n "${_prefix}`basename $_path`"
			_prefix=' '
			;;
		esac
	done
}

# fullpath_from_shell shell
#	Given $shell, the basename component of a valid shell, get the
#	full path to the shell from the /etc/shells file.
#
fullpath_from_shell() {
	_shell=$1
	[ -z "$_shell" ] && return 1

	cat ${ETCSHELLS} |
	while read _path _junk ; do
		case "$_path" in
		\#*|'')
			;;
		*)
			if [ "`basename $_path`" = "$_shell" ]; then
				echo $_path
				return 0
			fi
			;;
		esac
	done
	return 1
}

# save_config
#	Save some variables to a configuration file.
#	Note: not all script variables are saved, only those that
#	      it makes sense to save.
#
save_config() {
	echo "# Configuration file for adduser(8)."     >  ${ADDUSERCONF}
	echo "# NOTE: only *some* variables are saved." >> ${ADDUSERCONF}
	echo "# Last Modified on `date`."		      >> ${ADDUSERCONF}
	echo ''				>> ${ADDUSERCONF}
	echo "defaultclass=$uclass"	>> ${ADDUSERCONF}
	echo "defaultgroups=$ugroups"	>> ${ADDUSERCONF}
	echo "passwdtype=$passwdtype" 	>> ${ADDUSERCONF}
	echo "homeprefix=$homeprefix" 	>> ${ADDUSERCONF}
	echo "defaultshell=$ushell"	>> ${ADDUSERCONF}
	echo "udotdir=$udotdir"		>> ${ADDUSERCONF}
	echo "msgfile=$msgfile"		>> ${ADDUSERCONF}
	echo "disableflag=$disableflag" >> ${ADDUSERCONF}
}

# add_user
#	Add a user to the user database. If the user chose to send a welcome
#	message or lock the account, do so.
#
add_user() {

	# Is this a configuration run? If so, don't modify user database.
	#
	if [ -n "$configflag" ]; then
		save_config
		return
	fi

	_uid=
	_name=
	_comment=
	_gecos=
	_home=
	_group=
	_grouplist=
	_shell=
	_class=
	_dotdir=
	_expire=
	_pwexpire=
	_passwd=
	_upasswd=
	_passwdmethod=

	_name="-n $username"
	[ -n "$uuid" ] && _uid="-u $uuid"
	[ -n "$ulogingroup" ] && _group="-g $ulogingroup"
	[ -n "$ugroups" ] && _grouplist="-G $ugroups"
	[ -n "$ushell" ] && _shell="-s $ushell"
	[ -n "$uhome" ] && _home="-m -d $uhome"
	[ -n "$uclass" ] && _class="-L $uclass"
	[ -n "$ugecos" ] && _comment="-c '$ugecos'"
	[ -n "$udotdir" ] && _dotdir="-k $udotdir"
	[ -n "$uexpire" ] && _expire="-e '$uexpire'"
	[ -n "$upwexpire" ] && _pwexpire="-p '$upwexpire'"
	case $passwdtype in
	no)
		_passwdmethod="-w no"
		_passwd="-h -"
		;;
	yes)
		_passwdmethod="-w yes"
		_passwd="-<PASSWORD>"
		_upasswd="echo '$upass' |"
		;;
	none)
		_passwdmethod="-w none"
		;;
	random)
		_passwdmethod="-w random"
		;;
	esac
<commit_msg>*blush* While I'm here properly quote all the other input I neglected to quote.<commit_after>#!/bin/sh
#
# Copyright (c) 2002 <NAME> Makonnen. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
# 3. The name of the author may not be used to endorse or promote products
#    derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
#       Email: <NAME> <<EMAIL>>
#
# $FreeBSD$
#

# err msg
#       Display $msg on stderr, unless we're being quiet.
# 
err() {
	if [ -z "$quietflag" ]; then
        	echo 1>&2 ${THISCMD}: ERROR: $*
	fi
}

# info msg
#       Display $msg on stdout, unless we're being quiet.
# 
info() {
	if [ -z "$quietflag" ]; then
        	echo ${THISCMD}: INFO: $*
	fi
}

# get_nextuid
#	Output the value of $_uid if it is available for use. If it
#	is not, output the value of the next higher uid that is available.
#	If a uid is not specified, output the first available uid, as indicated
#	by pw(8).
# 
get_nextuid () {
	_uid=$1
	_nextuid=

	if [ -z "$_uid" ]; then
		_nextuid="`${PWCMD} usernext | cut -f1 -d:`"
	else
		while : ; do
			${PWCMD} usershow $_uid > /dev/null 2>&1
			if [ ! "$?" -eq 0 ]; then
				_nextuid=$_uid
				break
			fi
			_uid=$(($_uid + 1))
		done
	fi
	echo $_nextuid
}

# show_usage
#	Display usage information for this utility.
#
show_usage() {
	echo "usage: ${THISCMD} [options]"
	echo "  options may include:"
	echo "  -C		save to the configuration file only"
	echo "  -E		disable this account after creation"
	echo "  -G		additional groups to add accounts to"
	echo "  -L		login class of the user"
	echo "  -N		do not read configuration file"
	echo "  -d		home directory"
	echo "  -f		file from which input will be received"
	echo "  -h		display this usage message"
	echo "  -k		path to skeleton home directory"
	echo "  -m		user welcome message file"
	echo "  -q		absolute minimal user feedback"
	echo "  -s		shell"
	echo "  -u		uid to start at"
	echo "  -w		password type: no, none, yes or random"
}

# valid_shells
#	Outputs a list of valid shells from /etc/shells. Only the
#	basename of the shell is output.
#
valid_shells() {
	_prefix=
	cat ${ETCSHELLS} |
	while read _path _junk ; do
		case $_path in
		\#*|'')
			;;
		*)
			echo -n "${_prefix}`basename $_path`"
			_prefix=' '
			;;
		esac
	done
}

# fullpath_from_shell shell
#	Given $shell, the basename component of a valid shell, get the
#	full path to the shell from the /etc/shells file.
#
fullpath_from_shell() {
	_shell=$1
	[ -z "$_shell" ] && return 1

	cat ${ETCSHELLS} |
	while read _path _junk ; do
		case "$_path" in
		\#*|'')
			;;
		*)
			if [ "`basename $_path`" = "$_shell" ]; then
				echo $_path
				return 0
			fi
			;;
		esac
	done
	return 1
}

# save_config
#	Save some variables to a configuration file.
#	Note: not all script variables are saved, only those that
#	      it makes sense to save.
#
save_config() {
	echo "# Configuration file for adduser(8)."     >  ${ADDUSERCONF}
	echo "# NOTE: only *some* variables are saved." >> ${ADDUSERCONF}
	echo "# Last Modified on `date`."		      >> ${ADDUSERCONF}
	echo ''				>> ${ADDUSERCONF}
	echo "defaultclass=$uclass"	>> ${ADDUSERCONF}
	echo "defaultgroups=$ugroups"	>> ${ADDUSERCONF}
	echo "passwdtype=$passwdtype" 	>> ${ADDUSERCONF}
	echo "homeprefix=$homeprefix" 	>> ${ADDUSERCONF}
	echo "defaultshell=$ushell"	>> ${ADDUSERCONF}
	echo "udotdir=$udotdir"		>> ${ADDUSERCONF}
	echo "msgfile=$msgfile"		>> ${ADDUSERCONF}
	echo "disableflag=$disableflag" >> ${ADDUSERCONF}
}

# add_user
#	Add a user to the user database. If the user chose to send a welcome
#	message or lock the account, do so.
#
add_user() {

	# Is this a configuration run? If so, don't modify user database.
	#
	if [ -n "$configflag" ]; then
		save_config
		return
	fi

	_uid=
	_name=
	_comment=
	_gecos=
	_home=
	_group=
	_grouplist=
	_shell=
	_class=
	_dotdir=
	_expire=
	_pwexpire=
	_passwd=
	_upasswd=
	_passwdmethod=

	_name="-n '$username'"
	[ -n "$uuid" ] && _uid="-u '$uuid'"
	[ -n "$ulogingroup" ] && _group="-g '$ulogingroup'"
	[ -n "$ugroups" ] && _grouplist="-G '$ugroups'"
	[ -n "$ushell" ] && _shell="-s '$ushell'"
	[ -n "$uhome" ] && _home="-m -d '$uhome'"
	[ -n "$uclass" ] && _class="-L '$uclass'"
	[ -n "$ugecos" ] && _comment="-c '$ugecos'"
	[ -n "$udotdir" ] && _dotdir="-k '$udotdir'"
	[ -n "$uexpire" ] && _expire="-e '$uexpire'"
	[ -n "$upwexpire" ] && _pwexpire="-p '$upwexpire'"
	case $passwdtype in
	no)
		_passwdmethod="-w no"
		_passwd="-h -"
		;;
	yes)
		_passwdmethod="-w yes"
		_passwd="-<PASSWORD>"
		_upasswd="echo '$upass' |"
		;;
	none)
		_passwdmethod="-w none"
		;;
	random)
		_passwdmethod="-w random"
		;;
	esac

{'fraction_non_alphanumeric': 0.1286802909594735, 'fraction_numerical': 0.0036369934187738136, 'mean_word_length': 3.4402153018069974, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 65, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1977288', 'n_tokens_mistral': 4316, 'n_tokens_neox': 4019, 'n_words': 1447}