#!/bin/sh
: '20231228 PeterG shell user startup -*- ksh -*- vim:set ft=sh noet sw=2 ts=8:'

if test "$#" -eq 0 -a -t 1
then echo 1>&2 "$$: Running 'profile'"
  : 'This obviously must not be exported'
  INTERACTIVE=yes
fi

: '
  Copyright (C) 1991 PeterG. This program is free software: you
  can redistribute it and/or modify it under the terms of the
  GNU General Public License as published by the Free Software
  Foundation, either version 2 of the License, or (at your
  option) any later version. This program is distributed in the
  hope that it will be useful, but WITHOUT ANY WARRANTY; without
  even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  PARTICULAR PURPOSE.
'

trap "echo '.profile: interrupted'" 1 2 3 4 5 12 14 15

case "$OSTYPE" in NetBSD) typeset() { :; };; esac

setpath() { test -e "$3" && eval "$1=\"$2$3$4\""; }
sxfspath() { test -e "$3/app-defaults" && eval "$1=\"$2$3/%T/%N%S$4\""; }

isrdir() { test \! -L "$1" -a -d "$1"; }

setrdir() { 
  isrdir "$3" && \
    setpath "$1"	"$2"	"$3"			"$4"
}

searchfor()
{
  typeset NAME TEST VALUE ITEM

  NAME="$1"; TEST="$2"; shift; shift
  eval VALUE="\"\$$NAME\""
  case "$VALUE" in '')
    for ITEM in ${1+"$@"}
    do
      if test "$TEST" "$ITEM"
      then
	eval "$NAME"="'$ITEM'"
	return 0
      fi
    done
    ;;
  esac
  return 1
}

: 'This PATH is temporary'

PATHOLD="$PATH"
PATH='/bin:/usr/bin:/sbin:/usr/sbin'

export LOCAL SHARE
: ${SHARE:="$LOCAL"}

: 'For the list of "updatedb" hierarchies'

: ${DBDIRS:='/etc/updatedb.dirs'}

: '
  Because of the way the path setting functions work, the 
  first hierarchies, twigs and subhierarchies will end up
  last in the constructed path.
'

export HULL SITE NODE

for P in '/etc/' "$LOCAL/etc/" "$SHARE/etc/" "$HOME/."
do
  for F in env-SITE env-HULL env-NODE env-boot
  do test -e "$P$F" && . "$P$F"
  done
done

: 'Hierachies are tested in reverse order '

case "`uname -m`" in
'x86_64')	HSUF="32 64 $HSUF";;
'i'[3456]'86')	HSUF="32 $HSUF";;
esac

if false
then
  case "$LOCAL" in
  '/'|'/usr'|'/usr/local')			unset LOCAL;;
  esac

  case "$SHARE" in
  "$LOCAL")					unset SHARE;;
  '/share'|'/usr/share'|'/usr/local/share')	unset SHARE;;
  esac
fi

: 'Outer HSUF and inner HPRE is intentional'
for S in $HSUF
do
  for P in $HPRE
  do HIERS="$HIERS $P$S/"
  done
done

TWIGS='/X11 /netpbm /ncurses /pthread'
SUBHIERS='games/ mh/ openwin/ dt/ interviews/ andrew/ grass/ khoros/ TeX/ emacs/ gnome/ gnome2/ kde/ kde2/ kde3/'
SUBXHIERS='X11R6/ X11/ openwin/ lpp/X11/ X11R5/ X386/ X/'

export PS PS0 PS1 PS2 PS3 PS4
export SHELL HOME TMPDIR
export USER LOGNAME HOST DOMAIN
export EDITOR VISUAL PAGER
export TERMCAP TERMINFO
export RSH CVS_RSH RSYNC_RSH

export DBUS_SESSION_BUS_ADDRESS DBUS_SESSION_BUS_PID
export DISPLAY XAUTHORITY
export SSH_AUTH_SOCK SSH_AGENT_PID
export SSH_TTY SSH_CLIENT SSH_CONNECTION

export cso_proxy finger_proxy ftp_proxy gopher_proxy http_proxy https_proxy
export news_proxy nntp_proxy no_proxy snews_proxy wais_proxy

unset MAIL

case "$USER;$USERNAME" in
  ';'?*)				USER="$USERNAME";;
esac

case "$USER;$LOGNAME" in ';')
  if test -e '/usr/ucb/whoami';		then USER=`/usr/ucb/whoami`
  elif test -e '/usr/bin/id';		then LOGNAME="`expr \`id\` : '(\([^)]*\))'`"
  fi
esac

case "$USER;$LOGNAME" in
  ';'?*)				USER="$LOGNAME";;
  ?*';')				LOGNAME="$USER";;
esac

case "$HOST" in '')
  if test -e '/bin/hostname';		then HOST="`/bin/hostname`"
  elif test -e '/usr/bin/hostname';	then HOST="`/usr/bin/hostname`"
  elif test -e '/bin/uname';		then HOST="`/bin/uname -n`"
  elif test -e '/usr/bin/uname';	then HOST="`/usr/bin/uname -n`"
  fi;;
esac

case "$DOMAIN" in '')
  if test -e '/bin/dnsdomainname' \
    -o -e '/usr/bin/dnsdomainname';	then DOMAIN="`dnsdomainname`"
  elif test -e '/bin/domainname' \
    -o -e '/usr/bin/domainname';	then DOMAIN="`domainname`"
  fi;;
esac

case "$no_proxy" in '')			no_proxy="$DOMAIN";; esac

case "$HOST" in *'.'*)
  eval `echo "$HOST" | sed 's/\([^.]*\)\.\(.*\)/HOST="\1"; DOMAIN="\2"/'`;;
esac

searchfor TERMCAP	-f "$HOME/.termcap" "$LOCAL/etc/termcap" "$SHARE/etc/termcap" /usr/share/misc/termcap
searchfor TERMINFO	-f "$HOME/.terminfo" "$LOCAL/etc/terminfo" "$SHARE/etc/terminfo"
if test -e /usr/share/X11/rgb.txt
then XWINHOME=/usr
else
  for SXDIR in $SUBXHIERS
  do searchfor XWINHOME	-d /usr/"$SXDIR"; done
fi
searchfor OPENWINHOME	-d /usr/openwin/ "$LOCAL/openwin/"

searchfor RSH		-x /bin/ssh /usr/bin/ssh "$LOCAL/bin/ssh"
CVS_RSH="$RSH"
RSYNC_RSH="$RSH"


: 'BSD vs. System V vs. AIX...'

unset ECHON
unset ECHOC

false && unset PATH
unset FPATH
unset CDPATH
unset MANPATH
unset INFOPATH
unset LD_LIBRARY_PATH
unset EMACSLOADPATH
unset ELPATH
unset XELPATH
unset XFILESEARCHPATH
unset CCPATH
unset LDPATH

export ECHON ECHOC

export PATH FPATH CDPATH MANPATH INFOPATH
export LD_LIBRARY_PATH ELPATH XELPATH XFILESEARCHPATH
export CCPATH LDPATH
export XWINHOME OPENWINHOME

: 'Korn/Bourne Again shell vs. Bourne shell'

: 'This is duplicated in "env"'

export SHELL_VERSION
SHELL_VERSION='sh'

case "$KSH_VERSION" in
			*PD*)	SHELL_VERSION="pdksh $KSH_VERSION";;
			?*)	SHELL_VERSION="ksh $KSH_VERSION";;
esac
case "$BASH_VERSION" in ?*)	SHELL_VERSION="bash $BASH_VERSION";;	esac
case "$ZSH_VERSION" in ?*)	SHELL_VERSION="zsh $ZSH_VERSION";;	esac
case "$SHELL_VERSION;$OSTYPE" in
  		'sh;'*BSD)	SHELL_VERSION="bsdsh";;
esac

case "`echo -n`" in '-n') ECHOC='\c';; '') ECHON='-n';; esac

case "$MAILCHECK" in '') PS1="${PS1-\$ }"; PS2="${PS2-> }";; esac

export HISTSIZE HISTSAVE SAVEHIST HISTFILESIZE HISTCONTROL

HISTSIZE=500
HISTSAVE=300; SAVEHIST="$HISTSAVE"; HISTFILESIZE="$HISTSAVE"
HISTCONTROL=ignoreboth

: 'for "zsh" we need to set some options, so check "env"'

case "$RANDOM" in ?*)
  export PS3 PS4 COLS FCEDIT
  if false
  then : 'This only applies to some buggy BASH versions'
    if test -e "$HOME/.env";		then export ENV="$HOME/.env"
    elif test -e '/etc/env';		then export ENV='/etc/env'
    fi
  fi;;
esac

unset ENV

: 'Various types of system'

CDPATH=":..:$HOME"

if test -e /bin/cygwin1.dll
then
  : 'Cygwin, so not quite like UNIX'
  PATH="$PATHOLD"
  STTYARGS='crt'
elif test -e /usr/ucb -o -e /usr/libdata
then
  if test \! -e /etc/saf
  then
    : 'More or less pure BSD, or AIX'
    PATH=''
  else
    : 'SVR4'
    PATH=''
    setpath PATH ''		'/usr/ccs/bin'		':$PATH'
    for HIER in /usr "$LOCAL"
    do
      setpath PATH '$PATH'	"$HIER/dbin"		':'
      setpath PATH '$PATH'	"$HIER/msdos/bin"	':'
    done
    setpath MANPATH ''		'/usr/share/manx' 	':$MANPATH'
    STTYARGS='echoe echok echoctl echoke'
  fi
elif test -e /proc/net -o -e /usr/src/linux
then
  : 'Linux, a mixed breed'
  PATH=''
  STTYARGS='crt'
  test -e /etc/TIMEZONE	&& . /etc/TIMEZONE
  export KR
  if test -e /proc/version
  then read < /proc/version DUMMY$$ DUMMY$$ KR DUMMY$$; unset DUMMY$$
  elif test -e /bin/uname
  then KR="`/bin/uname -r`"
  fi
elif test -e /usr/bin/cut
then
  : 'Probably some SVR3 variant'
  PATH=''
  MANPATH='.'
  STTYARGS="echoe echok swtch ^T"
  test -e "$HOME" -a -e "$HOME/.hushlogin" || {
    test -e /etc/motd	&& /bin/cat /etc/motd
    test -e /bin/mail	&& /bin/mail -e && echo 'You have mail.'
  }
elif test -e /usr/spool -o -e /usr/mail -o -e	 /lib/libc.a
then
  : 'Version 7 or vanilla UNIX'
  PATH=''
  ECHON=''; ECHOC=''
else
  : 'Unknown'
  PATHOLD="$PATH"
  ECHON=''; ECHOC=''
fi

setpaths_both () {
  typeset HIER TWIG

  for HIER in "${1}"
  do
    isrdir "${HIER}" || continue

    for TWIG in $TWIGS ''
    do
      setpath PATH	''	"${HIER}bin${TWIG}"	':$PATH'
      setpath CCPATH	'-I'	"${HIER}include${TWIG}"	' $CCPATH'
      setpath INFOPATH	''	"${HIER}einfo${TWIG}"	':$INFOPATH'
      setpath INFOPATH	''	"${HIER}info${TWIG}"	':$INFOPATH'
      setpath MANPATH	''	"${HIER}man${TWIG}"	':$MANPATH'
    done
    setpath PATH	''	"${HIER}sbin"		':$PATH'

    isrdir "${HIER}lib" || continue

    setpath FPATH	''	"${HIER}lib/sh"		':$FPATH'

    sxfspath XFILESEARCHPATH ''	"${HIER}X11"		':$XFILESEARCHPATH'
    sxfspath XFILESEARCHPATH ''	"${HIER}lib"		':$XFILESEARCHPATH'

    setpath ELPATH	''	"${HIER}lib/emacs/site-lisp"    ':$ELPATH'
    setpath ELPATH	''	"${HIER}lib/elisp"	        ':$ELPATH'
    setpath ELPATH	''	"${HIER}elisp"			':$ELPATH'

    setpath XELPATH	''	"${HIER}lib/xemacs/site-lisp"   ':$XELPATH'
    setpath XELPATH	''	"${HIER}lib/xelisp"	        ':$XELPATH'
    setpath XELPATH	''	"${HIER}xelisp"			':$XELPATH'
  done
}

setpaths_bin () {
  typeset HIER

  for HIER in "${1}"
  do
    isrdir "${HIER}" || continue

    setpath LIBGL_DRIVERS_PATH '' "${HIER}lib/dri"	':$LIBGL_DRIVERS_PATH'
  done

  test -e /etc/ld.so.cache || for HIER in "${1}"
  do
    if isrdir "${HIER}lib/elf"
    then
      setpath LD_LIBRARY_PATH '' "${HIER}lib/elf"	':$LD_LIBRARY_PATH'
      setpath LDPATH	'-L'	"${HIER}lib/elf"	' $LDPATH'
    elif isrdir "${HIER}lib/aout"
    then
      setpath LD_LIBRARY_PATH '' "${HIER}lib/aout"	':$LD_LIBRARY_PATH'
      setpath LDPATH	'-L'	"${HIER}lib/aout"	' $LDPATH'
    else
      setpath LD_LIBRARY_PATH '' "${HIER}lib"		':$LD_LIBRARY_PATH'
      setpath LDPATH	'-L'	"${HIER}lib"		' $LDPATH'
    fi
  done
}

setXsubpaths_both () {
  typeset HIER

  for HIER in "${1}"
  do
    setrdir PATH	''	"${HIER}bin/X11"	':$PATH'
    setrdir CCPATH	'-I'	"${HIER}include/X11"	' $CCPATH'
    setrdir MANPATH	''	"${HIER}man/X11"	':$MANPATH'
    sxfspath XFILESEARCHPATH ''	"${HIER}lib/X11"	':$XFILESEARCHPATH'
  done
}

setXsubpaths_bin () {
  typeset HIER

  test -e /etc/ld.so.cache || for HIER in "${1}"
  do
    if isrdir "${HIER}lib/X11/elf"
    then
      setpath LD_LIBRARY_PATH '' "${HIER}lib/X11/elf"	':$LD_LIBRARY_PATH'
      setpath LDPATH	'-L'	"${HIER}lib/X11/elf"	' $LDPATH'
    elif isrdir "${HIER}lib/X11/aout"
    then
      setpath LD_LIBRARY_PATH '' "${HIER}lib/X11/aout"	':$LD_LIBRARY_PATH'
      setpath LDPATH	'-L'	"${HIER}lib/X11/aout"	' $LDPATH'
    else
      setpath LD_LIBRARY_PATH '' "${HIER}lib/X11"	':$LD_LIBRARY_PATH'
      setpath LDPATH	'-L'	"${HIER}lib/X11"	' $LDPATH'
    fi
  done
}

setXpaths() {
  typeset HIER

  for HIER in $SUBXHIERS
  do isrdir "${1}$HIER" || continue
    case "$XWINHOME" in '') XWINHOME="${1}$HIER";; esac
	if false
	then case "${1}$HIER" in "$XWINHOME"|"$OPENWINHOME") break;; esac
	fi

    setpaths_bin "${1}$HIER"
    setpaths_both "${1}$HIER"
    break
  done
}

setallpaths() {
  typeset HIER SDIR

  for HIER
  do isrdir "$HIER/." || continue

    setpaths_bin "$HIER"
    setpaths_both "$HIER"

    setXsubpaths_bin "$HIER"
    setXsubpaths_both "$HIER"

    setXpaths "$HIER"

    for SDIR in $SUBHIERS
    do isrdir "${HIER}$SDIR" || continue
      setpaths_bin "${HIER}$SDIR"
      setpaths_both "${HIER}$SDIR"

      setXpaths "${HIER}$SDIR"
    done
  done
}

: '
  This allows setting up a "..." directory in the home
  directory that contains links to directories one wants
  to be able to 'cd' directly to.
'

setpath		CDPATH		'$CDPATH:'	"$HOME/..."	''

false && case "$XWINHOME" in ?*)	setpaths "$XWINHOME";;		esac
false && case "$OPENWINHOME" in ?*)	setpaths "$OPENWINHOME";;	esac

HIERU='/usr/share/ /usr/ / /usr/local/share/ /usr/local/ /opt/ /loc/share/ /loc/ /com/share/ /com/'

case "$LOCAL;$SHARE" in
?*';'"$LOCAL")	setallpaths	$HIERU "$LOCAL/";;
?*';')		setallpaths	$HIERU "$LOCAL/";;
"$SHARE"';'?*)	setallpaths	$HIERU "$SHARE/";;
';'?*)		setallpaths	$HIERU "$SHARE/";;
?*';'?*)	setallpaths	$HIERU "$SHARE/" "$LOCAL/";;
';')		setallpaths	$HIERU;;
esac

setpath		PATH		''		"/usr/ucb"	':$PATH'
setpath		PATH		'$PATH:'	"/usr/games"	''

setallpaths	$HIERS

setpath		ELPATH		''	"/etc/elisp"	':$ELPATH'
setpath		XELPATH		''	"/etc/xelisp"	':$XELPATH'
sxfspath	XFILESEARCHPATH '' 	"/etc/X11"	':$XFILESEARCHPATH'
sxfspath	XFILESEARCHPATH '' 	"/etc"		':$XFILESEARCHPATH'

false && login ()	{ exec login; }
false && logout ()	{ kill -1 $$; }

case "$TMP;$TMPDIR" in
';'?*)	TMP="$TMPDIR";;
';')	TMP="/tmp/$USER";;
esac

if ! test -e "$TMP"
then mkdir -p "$TMP" && chmod og= "$TMP"
fi
: 'It could be a trap'
case "`stat --printf='%U;%a' \"$TMP\"`" in
"$USER"';'*'00')	: 'It is good';;
?*)			TMP='/tmp';;
esac
TMPDIR="$TMP"

ask () {
  typeset NAME VALUE ALIAS DEFAULT ACTION

  NAME="$1"; VALUE="$2"; ALIAS="$3"; DEFAULT="$4"; ACTION="$5"
  {
    typeset QUERY DOQUERY

    case "$VALUE" in '') : ;; *) DEFAULT="$VALUE";; esac

    QUERY="$NAME[$DEFAULT]=";
    DOQUERY="echo $ECHON '$QUERY$ECHOC' && read 'VALUE'"

    until
      eval "$DOQUERY"
      case "$VALUE" in '') VALUE="$DEFAULT";; esac;

      eval "$ALIAS"="'$VALUE'"
      case "$VALUE" in '.') : ;; ?*) "$ACTION";; esac
    do :
    done
  }
}

if test -t 0
then
  case "$DISPLAY" in '')
    : 'Initialize X windows.'

    : '
      $DISPLAY logic:

      If $DISPLAY is set, use that as default.
      If $DISPLAY is not set, use "." as default.

      If $DISPLAY is not ".":
    	If "xdpyinfo" is present check it.
    	If the check fails, prompt again and repeat.
    '

    searchfor XDPYI -f \
      /usr/X11/bin/xdpyinfo /usr/bin/X11/xdpyinfo \
      /usr/bin/xdpyinfo /usr/local/X11/bin/xdpyinfo

    inidisp() { 
      case "$DISP;$XDPYI" in
      '.;'*)		: 'unset, xpydinfo does not matter';;
      *':'*';')		: 'good, no xpydinfo, accept it' ;;
      *':'*';'?*)	"$XDPYI" -display "$DISP" >/dev/null 2>&1;;
      *';'?*)		DISP=":0.0"; "$XDPYI" -display "$DISP" >/dev/null 2>&1;;
      esac
    }

    if test -t 0 \
      -a '(' -n "$XWINHOME" -o -n "$OPENWINHOME" -o -d /usr/lib/X11 ')'
    then
      case "$DISPLAY" in
      ?*) INITIAL="$DISPLAY";;
      '') INITIAL='.';;
      esac

      if false
      then ask DISPLAY "$DISPLAY" DISP "$INITIAL" 'inidisp'
      fi
    fi

    case "$DISP" in
    '')	: ;;
    '.')	unset DISPLAY;;
    ?*)		export DISPLAY; DISPLAY="$DISP";;
    esac

    unset inidisp
    unset INITIAL
    unset DISP
    unset XDPY;;
  esac

  case "$TERM" in '')
    : 'Initialize the terminal'

    if test -e /usr/ucb/tset \
      -o -e /usr/bin/tset \
      -o -e "$LOCAL/bin/tset" \
      && tset -Q dumb >/dev/null;	then INIT='tset -Q -m ":$TTYPE"'
    elif test -e /bin/tput \
	-o -e /usr/bin/tput \
	-o -e /usr/ccs/bin/tput \
       && tput -Tdumb init >/dev/null;	then INIT='tput -T "$TTYPE" init'
    fi

    unset TINFO

    case "$INIT" in '') INIT=':';; esac

    if false
    then
      ask TERM "$TERM" TERM 'vt100' "$INIT"
    else
      searchfor STTY -f /bin/stty /usr/bin/stty /usr/ucb/stty
      STTYA="$STTYARGS"

      initerm() \
      {
	: 'some versions of bash cannot do "echo a b c | read A B C"'

	echo "$TTYPE" | while read TTYPE TLINES TCOLUMNS
	do
	  case "$TTYPE" in [,=]) TTYPE="$DEFAULT";; esac

	  eval "$INIT" && {
	    case "$TLINES" in ?*)     export LINES; LINES="$TLINES"
				      STTYA="$STTYA rows $TLINES";;
	    esac
	    case "$TCOLUMNS" in ?*)   export COLUMNS; COLUMNS="$COLUMNS"
				      STTYA="$STTYA cols $TCOLUMNS";;
	    esac
	    case "$STTY;$STTYA" in ?*';'?*)
				      test -t 0 -a -e /dev/tty \
					&& eval "$STTY" < /dev/tty "$STTYA";;
	    esac
	  }
	  unset TLINES
	  unset TCOLUMNS

	  : 'this "break" is needed by some versions os BASH'
	  break
	done

	: 'putting an "unset" here breaks the return code'
      }

      ask TERM "$TERM" TTYPE 'vt100' 'initerm'

      case "$TTYPE" in
      '')   : ;;
      '.')  unset TERM;;
      ?*)   export TERM; TERM="$TTYPE";;
      esac

      unset initerm
      unset TTYPE
      unset STTYA
      unset STTY
    fi;;
  esac

  case "$COMSPEC" in
  '') stty erase '^?' kill '^U' intr '^C';;
  ?*) stty erase '^H' kill '^U' intr '^C';;
  esac

  unset INIT
fi

searchfor PAGER		-f /bin/less /usr/bin/less \
			    /usr/bin/lv /usr/bin/pg \
			    /bin/more /usr/bin/more /usr/ucb/more \
			    sensible-pager
case "$DISPLAY" in
'')
  searchfor EDITOR	-f /usr/bin/exim /usr/bin/ex /usr/ucb/ex /bin/ed \
			    /usr/bin/sensible-editor
  searchfor VISUAL	-f /bin/vim/usr/bin/vim \
			    /bin/vi /usr/bin/vi /usr/ucb/vi \
			    /bin/nano /usr/bin/nano;;
?*)
  searchfor EDITOR	-f /bin/vim /usr/bin/vim \
			    /bin/vi /usr/bin/vi /usr/ucb/vi \
			    /bin/nano /usr/bin/nano \
			    /usr/bin/sensible-editor
  searchfor VISUAL	-f /bin/gvim /usr/bin/gvim \
			    /usr/bin/gedit /usr/bin/jedit \
			    /usr/bin/nedit /usr/bin/xedit;;
esac

case "$VISUAL" in *'gvim') VISUAL="$VISUAL -f";; esac

unset STTYARGS
unset ask

: 'For the list of "updatedb" hierarchies'

DBDIRS='/etc/updatedb.dirs'

if test -e "$DBDIRS"
then
  export LOCATE_PATH

  dbdirspath() {
    DBPATH="$1"; DBDIRS="$2"

    { grep -v '^[ \t]*#\|^[ \t]*$' "$DBDIRS"; echo ''; } \
    | while read DIR DB
    do
      case "$DIR" in
      '') echo "$DBPATH";;
      ?*)
	: ${DB:="$DIR/mlocate.db"}
	case "$DBPATH" in
	'') DBPATH="$DB";;
	?*) DBPATH="$DBPATH:$DB";;
	esac;;
      esac
    done

    unset DBPATH
    unset DIR
    unset DB
  }

  LOCATE_PATH="`dbdirspath \"\" \"$DBDIRS\"`"
fi

: 'This gives bigger cursors, "Adwaita" or "redglass" should be available'
export XCURSOR_THEME
XCURSOR_THEME=redglass

: 'Reset the not yet done message and define a logout script'

trap 1 2 3 4 5 12 13 14 15
trap 'test "$HOME" -a -e "$HOME"/.bye		&& . "$HOME"/.bye;
  echo "Goodbye $USER."; trap 0' 0

: '
  We need to unset all exported env vars which have an empty
  value; they might confuse the NetBSD /bin/sh and programs.
  Pray there are no variables whose name has blanks in them
  -- too hard to fix.
'

test -e /bin/printenv -o -e /usr/bin/printenv \
  && for VAR in `printenv | grep '^[A-Za-z0-9_]*=$' | sed 's/=$//'`
     do unset $VAR; done

: ' This is done for some silly but important reason. Just to make sure...'

cd .

for O in "$HOME"
do
  if test -n "$O" -a -e "$O"
  then
    for U in "$O/.user"
    do
      if test -n "$U" -a -e "$U"
      then . "$U"
      fi
    done
  fi
done

true
