#! /bin/sh
# .xinitrc start-up file

PATH=$HOME/bin:/opt/local/bin:/usr/local/bin:/usr/ucb:/usr/bsd:/usr/5bin:/usr/xpg4/bin:/bin:/usr/bin:/usr/local/bin/X11:/usr/local/X11/bin:/usr/X11/bin:/usr/bin/X11:/usr/openwin/bin:/usr/openwin/demo:/opt/local/kde/bin:/usr/local/kde/bin:/usr/dt/bin:/usr/ccs/bin:/acs/peri/local/bin:/acs/peri/local/ar/bin:/opt/apps/frame/bin:/opt/apps/2.0_SUNWwabi/bin
export PATH

# set where to look for mail (mostly for xbuffy)
for m in /var/mail /usr/mail /var/spool/mail /usr/spool/mail
do
    if test -d $m; then
	MAILPATH=$m/`whoami`
	export MAILPATH
	break
    fi
done
if [ -f ${HOME}/Mail/personal ]; then
    MAILPATH="${MAILPATH}:${HOME}/Mail/personal"
fi
if [ -f ${HOME}/Mail/lists ]; then
    MAILPATH="${MAILPATH}:${HOME}/Mail/lists"
fi
if [ -f ${HOME}/Mail/wks-lists ]; then
    MAILPATH="${MAILPATH}:${HOME}/Mail/wks-lists"
fi
export MAILPATH
#NEWSPATH=osu.sys.sun:osu.sys.linux ; export NEWSPATH

# tell ghostscript where we have some fonts
GS_FONTPATH=/usr/openwin/lib/X11/fonts/Type1/outline:/usr/lib/X11/fonts/Type1:/usr/lib/X11/fonts/Type1Adobe:/usr/lib/X11/fonts/type1.st/typefaces:/usr/lib/DPS/outline/base:/usr/lib/DPS/outline/decwin:/NextLibrary/Fonts/outline
export GS_FONTPATH

# vxtreme plugin for netscape
VXTREME_HOME=/usr/local/vxtreme;export VXTREME_HOME
CLASSPATH=/usr/java:/usr/local/java:/usr/local/netscape:/usr/local/lib/netscape:${VXTREME_HOME}/client
export CLASSPATH

VISUAL=emacs
EDITOR=$VISUAL
export VISUAL EDITOR

##########
# Special Functions

# we need to be able to find out if something exists anywhere in the path
_which () {
    notfound=1
    for i in `echo $PATH|tr : \ `
    do
	if [ -x $i/$1 -a ! -d $i/$1 ]; then
	    #echo $i/$1
	    notfound=0
	    break
	fi
    done
    return $notfound
}

if [ -r $HOME/.ssh/identity ] && _which ssh; then
    # this person can use ssh
    remote="ssh -f"
else
    remote="rsh"
fi

# run program on specified machine, only ssh there if we're not there already
_onhost () {
    here=`uname -n`
    there=$1
    shift
    if [ $here = $there ]; then
	sh -c "$@" &
	#echo "$@"
    else
	$remote $there "$@"
	#echo $remote $there "$@"
    fi
}

#
###########

HOST=`hostname`;export HOST
if [ -f /etc/printcap ]; then
  PRINTER=nyssa; export PRINTER
fi
#CTWM_WELCOME_FILE=xpm:/usr/local/lib/ctwm/images/welcome.xpm
CTWM_WELCOME_FILE=/no/file/that/exists
export CTWM_WELCOME_FILE

TERM=xterm; export TERM
eval `xwininfo -root | \
	sed -n  -e 's/Height: /XHEIGHT=/p' \
		-e 's/Width: /XWIDTH=/p' \
		-e 's/Depth: /XDEPTH=/p' \
		-e 's/Visual Class: /XCLASS=/p'
`
case "$XCLASS" in
    *Color) COLOR=1; export COLOR;;
esac
export XHEIGHT XWIDTH XDEPTH XCLASS
#XDEPTH=`xwininfo -root | grep Depth: | sed -e 's/^.*: //'`
#XWIDTH=`xwininfo -root | grep Width: | sed -e 's/^.*: //'`
#XHEIGHT=`xwininfo -root | grep Height: | sed -e 's/^.*: //'`

xrdb $HOME/.X11defaults

test -f $HOME/.Xmodmap.$HOST && xmodmap .Xmodmap.$HOST

xsetroot -gray
# if [ ! -z "${OPENWINHOME}" ] ; then
#   xsetroot -bitmap /usr/openwin/include/X11/bitmaps/root_weave -fg '#112121'
# else
#   xsetroot -bitmap /usr/local/X11/include/bitmaps/root_weave -fg '#112121'
# fi
#xterm -T 'Console' -n 'Console' -rv -rw -sl 500 -sf -C -geometry 80x12-0+50 &
#sleep 1
xconsole -fn fixed -geometry -0-0 &
#xclock -digital -update 1 -geometry +200+0 -fg black -bg white -font fixed &

XLOAD1=lennier
XLOAD2=borusa
XLOAD3=tardis
XLOAD4=susan
XLOAD5=gallifrey
#XLOAD6=peri
_onhost $XLOAD1 "cd / ; xload -geometry 80x70-400-0"
sleep 1
_onhost $XLOAD2 "cd / ; xload -geometry 80x70-480-0"
sleep 1
_onhost $XLOAD3 "cd / ; xload -geometry 80x70-560-0"
sleep 1
_onhost $XLOAD4 "cd / ; xload -geometry 80x70-640-0"
sleep 1
_onhost $XLOAD5 "cd / ; xload -geometry 80x70-720-0"
sleep 1
#_onhost $XLOAD6 "cd / ; xload -geometry 80x70-800-0"
#sleep 1

emacs -name EmacsMain -geometry +0+130 &
sleep 1
if _which toolchest
then
    toolchest -geometry +0-60 &
    sleep 1
fi

# find a CD player
found=0
for cdplayer in xmcd workman xplaycd
do
    if _which $cdplayer; then
	found=1
	break
    fi
done
if [ $found -eq 1 ]; then
    XMCD_LIBDIR=/usr/local/lib/xmcd ; export XMCD_LIBDIR
    $cdplayer -geometry -0+0 &
    found=0
    sleep 1
fi

if _which nscal
then
    nscal &
fi

# java needs geometry specification...
if _which ICQ
then
    #ICQ &
    sleep 1
fi

for ELM in mutt elmme+ elm
do
    if _which $ELM; then
	export ELM
	break
    fi
done

for xterm in rxvt ansi_xterm color-xterm color_xterm xterm
do
    if _which $xterm; then
	XTERM=$xterm; export xterm XTERM
	# xterm itself is the only non-color one of this group
	if [ "$xterm" != "xterm" -a "$XDEPTH" -gt 2 ]; then
	    # it's color
	    COLORTERM=true; export COLORTERM
	fi
	break
    fi
done
$xterm -ls -geometry 80x25+0+100 &
$xterm -geometry 80x25-0-70 &

if _which xbuffy
then
    xbuffy -shortnames -fill -geometry +93-0 \
	-command "LINES=50;export LINES;$xterm -ut -geometry 80x50 -T $ELM -n $ELM -e $ELM -f %s &"
	#-command "LINES=48;export LINES;box=%s;echo $box|grep \^/ > /dev/null && ($xterm -ut -geometry 80x48 -e $ELM -f \$box &) || (trn -qs \$box)"
else
    xbiff -geometry +822+0 &
    xbiff -file ${HOME}/Mail/personal -volume 0 -geometry +870+0 &
    xbiff -file ${HOME}/Mail/lists -volume 0 -geometry +870+48 &
    xbiff -file ${HOME}/Mail/wks-lists -volume 0 -geometry +822+48 &
fi

# get a clock
oclock -transparent -geometry 70x70+200+0 &

if _which aruser
then
    [ -x $HOME/bin/ar-fix ] && ar-fix
    aruser -I >/dev/null 2>&1 &
    sleep 1
fi


found=0
for netscape in communicator netscape
do
    if _which $netscape; then
	found=1
	break
    fi
done
if [ $found -eq 1 ]; then
    nice $netscape -install -geometry 711x753+99+48 &
    found=0
    sleep 1
fi

# Turn off screen saver
xset s off

# Find a window manager
#
for wm in ctwm tvtwm vtwm twm fvwm fvwm2 4Dwm mwm olvwm olwm
do
    if _which $wm; then
	exec $wm
    fi
done
# Shouldn't get this far
echo "CAN'T FIND A WINDOW MANAGER, ABORTING!"
