#!/bin/sh
#
# killuser 1.0.0 configure file
#

VERSION="1.0.0"
DEFAULT="%l (%t:%H) was terminated by %V"
MAN_DIR=/usr/man/man1
BIN_DIR=/usr/bin

cat << CRAP

	There are some variables that you can
	add to you default kill message, to
	'personalize' the message for each user.
	some examples of these are as follows:

		%l  (for the users login name)
		%r  (for the users real name)
		%g  (for the group id)
		%G  (for the group name)
		%h  (for the home directory)
		%H  (for the host)
		%p  (for the pid)
		%s  (for the shell)
		%t  (for the tty)
		%V  (for program name and version)

	Example for a default kill message:
	'%l your real name is %r and your shell is %s'

CRAP
echo " "
echo "Enter your default kill message"
echo "Or ENTER for default '$DEFAULT'"
echo " "
echo -n "kill message: "
eval read DKILL

echo " "
echo "Would you like to have this header:"
echo " "
echo "USER     TERM     LOGIN TIME     IDLE      FROM"
echo " "
echo -n "added when ku is run with no options [y/n]? "
read HEADER

if [ "$HEADER" = "y" ] || [ "$HEADER" = "Y" ]; then
	DHEADER="#define HEADER"
else
	DHEADER="#undef HEADER"
fi

#echo " "
#echo -n "Install binaries to [$BIN_DIR]: "
#read RBIN

#if [ "$RBIN" != "" ]; then
#	BIN_DIR=$RBIN
#fi

#echo " "
#echo -n "Install man pages to [$MAN_DIR]: "
#read RMAN

#if [ "$RMAN" != "" ]; then
#	MAN_DIR=$RMAN
#fi

if [ "$DKILL" != "" ]; then
	echo " "
        echo "Using kill message: '$DKILL'"
        echo "Makefiles, and configuration files made please run 'make install' now"
        echo " "
else
        echo " "
        echo "Using default kill message"
        echo "Makefiles, and configuration files made please run 'make install' now"
        echo " "
        DKILL="%l (%t:%H) was terminated by %V"
fi

cat << EOF > include/ku.h

/* defines */

#ifndef TRUE
	#define TRUE 1
	#define FALSE 0
#endif

#ifndef S_IGRWP
	#define S_IGRWP 00020
#endif

#define VERSION "killuser version $VERSION"
#define DKILL	"$DKILL"
$DHEADER

/* prototypes */

int		TermUser();			/* terminates the user */
int		CheckSanity();			/* check for a goofy command line */
int		PrintVerbose();			/* tells you who was terminated */
int		Process_Type();			/* make sure it's a valid login */
int		ProveIdleTime();		/* gets users idle times */
int		ProveCommandLine();		/* prove command line options */

const   char	*idleTime();			/* gets users idle times */
char		KillMessage();			/* printing kill messages */
char		usageMoron(char *argv[]);	/* help please */

/* structures */

struct	CLopt			/* command line options */
{
	int	opt_a;		/* --all	*/
	int	opt_b;		/* --beep	*/
	int	opt_g;		/* --group	*/
	int	opt_G;		/* --group	*/
	int	opt_h;		/* --header	*/
	int	opt_H;		/* --help	*/
	int	opt_i;		/* --idle	*/
	int	opt_s;		/* --string	*/
	int	opt_m;		/* --message	*/
	int	opt_p;		/* --prompt	*/
	int	opt_t;		/* --telnet	*/
	int	opt_T;		/* --tty	*/
	int	opt_u;		/* --user	*/
	int	opt_x;		/* --xterm	*/
	int	opt_v;		/* --verbose	*/
	int	opt_V;		/* --version	*/

	int	opt_msg;	/* use DKILL?	*/
};

struct	CLargs			/* command line arguments */
{
	int	i_arg;		/* --idle arg	*/
	int	G_arg;		/* --idle arg	*/
	char	*g_arg;		/* --group arg	*/
	char	*m_arg;		/* --message arg*/
	char	*T_arg;		/* --tty arg	*/
	char	*s_arg;		/* --string arg	*/
	char	*u_arg;		/* --user arg	*/
	char	str[256];	/* used for storing stuph */
	char	tmp_arg[256];	/* used for storing other args */
};

struct  passwd  *p;             /* checking UID's and user names */
struct  utmp    *u;             /* pointer to utmp file entry */
struct  CLopt   opt;            /* command line options */
struct  CLargs  args;           /* command line arguments */
struct  utmp    *getutent();    /* returns next utmp file entry */
EOF

cat bin/Makefile.in \
	| sed /--VERSION--/s//$VERSION/g > bin/Makefile
