[comp.sources.x] v06i030: xstart, Part01/01

ken@cs.rochester.edu (Ken Yap) (03/11/90)

Posting-number: Volume 6, Issue 30
Archive-name: xstart/part01

Here is a startup shell script and man page I find useful. It should
go well with xplaces.

	Ken

#!/bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #!/bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create the files:
#	xstart
#	xstart.1
# This archive created: Thu Feb  1 01:54:47 1990
# By:	Ken Yap ()
export PATH; PATH=/bin:$PATH
echo shar: extracting "'xstart'" '(943 characters)'
if test -f 'xstart'
then
	echo shar: over-writing existing file "'xstart'"
fi
cat << \SHAR_EOF > 'xstart'
#!/bin/sh

# look for config files
XTOOLSINIT="$HOME/.xtools"
XSTARTINIT="$HOME/.xstart"
case $# in
0)	;;
1)
	XTOOLSINIT=$1
	;;
*)
	XTOOLSINIT=$1
	XSTARTINIT=$2
	;;
esac

if test -r $XSTARTINIT
then
	. $XSTARTINIT
fi

if test ! -r $XTOOLSINIT
then
	1>&2 echo "Cannot open $XTOOLSINIT"
	exit 1
fi

# redirect stdin
<$XTOOLSINIT exec

# skip coment lines
while read line
do
	case "$line" in
	"#"*)	continue ;;
	*)	break ;;
	esac
done

case "$line" in
"")	echo $XTOOLSINIT is empty
	exit 1
	;;
esac

# first child ignores HUP INT QUIT
trap '' 1 2 3
eval "$line &"
XSTARTPID=$!; export XSTARTPID

# restore traps for client programs
trap 1 2 3
pids=""
while read line
do
	case "$line" in
	"#"*)	continue ;;
	esac
	eval "$line &"
	pids="$pids $!"
done

# make parent insensitive to everything except exit
trap "kill $pids; sleep 2; kill -KILL $pids; kbd_mode -a; exit 0" 0
trap '' 1 2 3 15

# and wait for the first child to finish
wait $XSTARTPID
SHAR_EOF
if test 943 -ne "`wc -c 'xstart'`"
then
	echo shar: error transmitting "'xstart'" '(should have been 943 characters)'
fi
chmod +x 'xstart'
echo shar: extracting "'xstart.1'" '(2379 characters)'
if test -f 'xstart.1'
then
	echo shar: over-writing existing file "'xstart.1'"
fi
cat << \SHAR_EOF > 'xstart.1'
.TH XSTART 1 "1 Feb 1988" "X Version 11"
.SH NAME
xstart - start up personal X window configuration
.SH SYNOPSIS
.B xstart
[
.I configfile
[
.I initialfile
] ]
.SH DESCRIPTION
.B Xstart 
starts a personalized X11 window configuration.
.PP
.B Xstart
first sources the
.I initialfile
(default
.BR $HOME/.xstart )
which should contain
.BR sh (1)
commands.
Typically, this file sets environment variables and
executes transient commands like
.BR xset .
Next,
.B xstart
reads
.I configfile
(default
.BR $HOME/.xtools )
and runs the programs specified in parallel.
Each line of the file specifies one program to be started.
Lines beginning with # are comments.
.PP
.B Xstart
places the pid of the first command started from
.I configfile
in the environment variable
.BR XSTARTPID .
This child is also protected from
.BR SIGHUP ,
.B SIGINT
and
.BR SIGQUIT,
but not
.BR SIGTERM ,
and definitely not
.BR SIGKILL .
You will probably want to make the first command
a stable program such as
.BR xclock .
When
.B xstart
detects that this child has exited,
it will send
.B SIGTERM
to each of its child programs.
After a couple of seconds, it repeats with
.BR SIGKILL .
Lastly,
.B xstart
will reset the keyboard to a sane state.
Thus you can exit X at once by ``\fBkill $XSTARTPID\fP''.
This command can also be taught to your favourite window manager.
.SH EXAMPLES
On our local Sun machines, the usual way of invoking
.B xstart
is with
.sp
xinit /usr/grads/bin/xstart
.sp
As the manual page for
.BR xinit (1)
explains, options to the server can go after a double dash.
.PP
Here is an example
.B .xstart
file:
.sp
.nf
DISPLAY=localhost:0; export DISPLAY
2>/tmp/Xerr.$USER exec
xset +fp /usr/grads/lib/snf,/usr/staff/lib/X11/fonts/tex
xrdb $HOME/.Xdefaults
xmodmap $HOME/.xmodmap
.fi
.sp
Here is an example
.B .xtools
file:
.sp
.nf
# this is my setup
xclock -analog -geometry 100x100+467+3 -rv
twm
xload -geometry 125x100+335+3 -rv
xterm -geometry 80x16+3+3 -T csh -n Console -fn 4x6 -C -rv -ls
xterm -geometry 80x24+581+599 -T csh -n csh -rv -ls
xterm -geometry 80x24+581+301 -T csh -n csh -rv -ls
xterm -geometry 80x24+581+3 -T csh -n csh -rv -ls
xterm -geometry 80x65+3+107 -T csh -n csh -rv -ls
xbiff -geometry 48x48+412+3 -rv
.fi
.SH SEE ALSO
xinit(1)
.SH FILES
$HOME/.xstart
.br
$HOME/.xtools
.SH DIAGNOSTICS
Can't find configuration file.
.br
Empty configuration file.
.SH AUTHOR
Ken Yap
SHAR_EOF
if test 2379 -ne "`wc -c 'xstart.1'`"
then
	echo shar: error transmitting "'xstart.1'" '(should have been 2379 characters)'
fi
#	End of shell archive
exit 0


-- 
Kent Landfield                       UUCP:     uunet!ssbell!kent
Sterling Software FSG/IMD            INTERNET: kent@ssbell.IMD.Sterling.COM
1404 Ft. Crook Rd. South             Phone:    (402) 291-8300 
Bellevue, NE. 68005-2969             FAX:      (402) 291-4362
Stupidity, like virtue, is its own reward.

dan
-----------------------------------------------------------
		    O'Reilly && Associates
		argv@sun.com / argv@ora.com
	   632 Petaluma Ave, Sebastopol, CA 95472 
     800-338-NUTS, in CA: 800-533-NUTS, FAX 707-829-0104
    Opinions expressed reflect those of the author only.