Forcing actions at login

Robert Claeson prc at erbe.se
Wed Jan 16 00:06:32 AEST 1991


In article <449 at minya.UUCP>, jc at minya.UUCP (John Chambers) writes:

|> Not really.  The benefit to making .login and .logout local to each
|> user's home directory, and using no global files at all, is that you
|> can give each new user a default version that does nice things like
|> "cat /etc/motd" and "mail -e" and so on, but they can be emptied or
|> deleted for users that need (or want) other behavior.  It's true that
|> using a single global file is an initial convenience for administrators, 
|> but only until they stumble across the problems it causes with packages
|> that use pseudo-users for some purpose.  Then the convenience evaporates.

Tell me about it. We have been using /etc/profile for common setups
for quite some time now and find it a major convenience. We have several
software packages that needs special pseudo users, and haven't had any
problems with them. Exactly what problems could one expect, and for what
packages?

|> It's a bit of a task initially, but it's not hard to write a little
|> program that generates the names of the .login files of all "real"
|> users, and feeds this list to a for loop that appends a new line.
|> In my experience, users don't often complain about the admin doing
|> such a thing, at least if the new action is generally useful, and
|> they can delete it if they're unhappy.

Here, all "default" setup is done in /etc/profile. The files .profile and
.kshrc are never touched by the administrators. They are solely for the
user's own private use, to add definitions or override setup done by the
administrator. If a user wants a shell other than ksh (Korn shell), he can
easily add an "exec /bin/csh" to his/her .profile.

Here's a sample /etc/profile:

-------- snippety-snap ----------
#!/bin/sh

#
# Name:
#	/etc/profile
#
# Description:
#	Common, system-wide user login initialization file for
#	Bourne and Korn shell users.
#

#
# Defaults.
#

DEFAULT_TERMTYPE=vt320

#
# Function:
#	select_termtype
#
# Purpose:
#	Select the terminal type.
#
# Returns:
#	The terminal type in the TERM variable.
#

select_termtype()
{
	if [ "$TERM" = "" -a -x /usr/bin/tput ]; then
		if [ -f $HOME/.defaults/defterm ]; then
			chmod u+r $HOME/.defaults/defterm
			defterm=`cat $HOME/.defaults/defterm`
		else
			defterm="$DEFAULT_TERMTYPE"
		fi

		found=0
		badtry=1

		while [ $found -ne 1 ]; do
			if [ $badtry -ne 1 ]; then
				echo "The terminal type does not exist."
				echo "Please try again."
			fi
			badtry=0

			echo "Terminal type (${defterm}): \c"
			read selection junk

			if [ -n "$selection" ]; then
				TERM=$selection; export TERM
			else
				TERM=$defterm; export TERM
			fi

			tput gn >/dev/null 2>&1
			test $? != 3 && found=1
		done

		unset defterm selection junk found badtry
	fi

	if [ -f $HOME/.defaults/defterm ]; then
		chmod u=rw $HOME/.defaults/defterm
	fi

	echo "$TERM" > $HOME/.defaults/defterm

	chmod u=r,go-rwx $HOME/.defaults/defterm
}


#
# Function:
#	init_terminal
#
# Purpose:
#	Initialize the line characteristics and the terminal.
#

init_terminal()
{
	stty -parenb cs8 -istrip echo echoe echok kill '^u' intr '^c' erase "^h"

	if [ -x /usr/bin/tput ]; then
		/usr/bin/tput init
		/usr/bin/tput kbs >/dev/null 2>&1
		if [ $? = 0 ]; then
			stty erase "`/usr/bin/tput kbs`"
		fi
	fi
}


#
# Function:
#	init_mnls
#
# Purpose:
#	Initialize language and character set variables.
#
# Preconditions:
#	The terminal type must be initialized.
#

init_mnls()
{
	#
	#	In lack of other ways to do it, set language and
	#	character set based on the terminal type.
	#

	case "$TERM" in
	vt2??*|vt3??*|vdu2??*|wy185*|wyse185*|xterm*)
		LANGUAGE=swedish.8859; export LANGUAGE
		CHRCLASS=iso_8859_1; export CHRCLASS
		LC_CTYPE=iso_8859_1; export LC_CTYPE
		;;
	*)
		LANGUAGE=swedish.646; export LANGUAGE
		CHRCLASS=iso_646_se; export CHRCLASS
		LC_CTYPE=iso_646_se; export LC_CTYPE
		;;
	esac
}


#
# Function:
#	init_packages
#
# Purpose:
#	Initialize software packages variables and the search path.
#

init_packages()
{
	#
	#	Standard directories and features.
	#

	PATH=.:/bin:/usr/bin:/usr/lbin:/usr/ucb; export PATH
	EDITOR=/usr/bin/vi; export EDITOR
	MAILCHECK=30; export MAILCHECK
	MAILPATH=/usr/mail/"$LOGNAME"?"E-mail has arrived."; export MAILPATH
	ENV=$HOME/.kshrc; export ENV

	#
	#	Local utilities.
	#

	PATH=$PATH:/usr/local/bin

	#
	#	X11:
	#

	PATH=$PATH:/usr/bin/X11:/usr/local/bin/X11
	
	#
	#	Verdix VADS.
	#

	PATH=$PATH:/usr/local/vads/bin

	#
	#	INFORMIX.
	#

	PATH=$PATH:/usr/local/informix/bin
	INFORMIXDIR=/usr/local/informix; export INFORMIXDIR
	DBDATE=Y4MD-; export DBDATE
	DBEDIT=$EDITOR; export DBEDIT
	DBMONEY=", kr"; export DBMONEY
	DBPATH=$INFORMIXDIR/db/address; export DBPATH

	#
	#	Micro Focus COBOL.
	#

	PATH=$PATH:/usr/local/cobol/bin
	COBDIR=/usr/local/cobol/lib; export COBDIR

	#
	#	Adobe Transcript.
	#

	PATH=$PATH:/usr/local/transcript/bin

	#
	#	FrameMaker 1.3X.
	#

	PATH=$PATH:/usr/local/frame1.3/bin
	FMHOME=/usr/local/frame1.3; export FMHOME

	#
	#	News.
	#

	NEWSBOX=$HOME/News; export NEWSBOX
	NEWSARCHIVE=$NEWSBOX/sent; export NEWSARCHIVE
	AUTHORCOPY=$NEWSARCHIVE; export AUTHORCOPY
	
	#
	#	Rn.
	#

	SAVENAME="%C"; export SAVENAME
	SAVEDIR="%p"; export SAVEDIR
	MBOXSAVER='%X/mbox.saver %A %P %c %a %B %C "%b" "From %T `LANGUAGE= date`"'; export MBOXSAVER

	#
	#	WordPerfec 4.2.
	#

	PATH=$PATH:/usr/local/wp/bin

	#
	#	Ingres.
	#

	II_SYSTEM=/usr/local; export II_SYSTEM
	PATH=$PATH:$II_SYSTEM/ingres/bin
	VEC=$II_SYSTEM/ingres/vec; export VEC

	#
	#	FACE.
	#

	VMSYS=/usr/vmsys; export VMSYS
	OASYS=/usr/oasys; export OASYS
	PATH=$PATH:$VMSYS
}


#
# Function:
#	display_messages
#
# Purpose:
#	Display common login messages.
#

display_messages()
{
	#
	#	Display the message-of-the-day.
	#

	if [ "$LOGNAME" != "root" ]; then
		case "$0" in
		-*)	if [ -f /etc/motd -a -r /etc/motd -a ! -f $HOME/.hushlogin ]
			then
				cat -s /etc/motd
			else
				echo "\033#6No system messages."
			fi
			;;
		esac
	fi

	#
	#	Check for mail.
	#

	if [ -x /usr/local/bin/messages ]; then
		/usr/local/bin/messages > /dev/null 2>&1
		MSGS=$?
		if [ $MSGS -gt 0 ]; then
			echo "\033#6\033[1mYou have $MSGS messages.\033[m"
		fi
	elif [ n16 -a -x /bin/SYSVmail ]; then			# UMAX V
		/bin/SYSVmail -e && echo "\033#6\033[1mYou have mail.\033[m"
	elif [ `uname` = dgux -a -x /usr/bin/mail ]; then	# DG/UX
		/usr/bin/mail -e && echo "\033#6\033[1mYou have mail.\033[m"
	elif [ -x /bin/mail ]; then				# Others
		/bin/mail -e && echo "\033#6\033[1mYou have mail.\033[m"
	fi
}


#
# Function:
#	main
#
# Purpose:
#	Main routine.
#

#
#	Disable signals.
#

trap "" 2 3

#
#	Set current timezone.
#

if [ -f /etc/TIMEZONE ]; then
	. /etc/TIMEZONE
fi

#
#	Put username into environment.
#

export LOGNAME

#
#	Set default file protection mask (umask).
#

umask 022

#
#	Create directory for user defaults.
#
#	Note: this seemingly rude approach was implemented on user requests.
#

if [ ! -d $HOME/.defaults ]; then
	mkdir $HOME/.defaults > /dev/null 2>&1
fi

chmod u=rwx,go-rwx $HOME/.defaults > /dev/null 2>&1

#
#	Set terminal type. We do this early since the init may destroy the
#	contents of the screen.
#

TERMINFO=/usr/share/local/lib/terminfo; export TERMINFO

select_termtype

#
#	Initialize the terminal.
#

init_terminal

#
#	Select language and character set.
#

init_mnls

#
#	Initialize packages and set search path.
#

init_packages

#
#	Display messages to the user.
#

display_messages

#
#	Enable signals.
#

trap 2 3
----------------------------

-- 
Robert Claeson                  |Reasonable mailers: rclaeson at erbe.se
ERBE DATA AB                    |      Dumb mailers: rclaeson%erbe.se at sunet.se
Jakobsberg, Sweden              |  Perverse mailers: rclaeson%erbe.se at encore.com
Any opinions expressed herein definitely belongs to me and not to my employer.



More information about the Comp.unix.admin mailing list