File: ncsawrap.sh

package info (click to toggle)
xmcd 2.5pl1-7.1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 3,332 kB
  • ctags: 4,906
  • sloc: ansic: 48,789; sh: 4,012; makefile: 210; pascal: 67
file content (198 lines) | stat: -rw-r--r-- 5,364 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#!/bin/sh
#
# @(#)ncsawrap.sh	6.5 99/02/15
#
# Shell script wrapper to allow xmcd to invoke the NCSA Mosaic browser that
# is located on a remote host.
#
# Usage: ncsawrap.sh [-remote | -direct] [-auth type] host mosaic_path args...
#    where,
#    -remote		Control a running Mosaic session
#    -direct		Start a new Mosaic session (default)
#    -auth type		"xhost", "xhost-xterminal", "xauth", "environment"
#			or "none" (the default is "xhost").
#    host		The remote host where Mosaic is to be run.
#    mosaic_path	the full path to the Mosaic executable
#    args		The URL to go to
#
# The DISPLAY environment variable must be set appropriately for your
# X display.
#
#    xmcd  - Motif(tm) CD Audio Player
#    cda   - Command-line CD Audio Player
#    libdi - CD Audio Player Device Interface Library
#
#    Copyright (C) 1993-1999  Ti Kan
#    E-mail: ti@amb.org
#
#    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.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
#    This file contains some code adapted from the xrsh script originally
#    by James J. Dempsey (Copyright 1991 by James J. Dempsey <jjd@bbn.com>).
#

localhost=`uname -n`

#
# Fix up DISPLAY environment variable if necessary
#
if [ -z "$DISPLAY" ]
then
	echo "The DISPLAY environment variable is not set." >&2
	exit 1
elif [ `expr "$DISPLAY" : ':[0-9]*\.*[0-9]*'` -gt 0 ]
then
       DISPLAY="${localhost}${DISPLAY}"
elif [ `expr "$DISPLAY" : 'unix:[0-9]*\.*[0-9]*'` -gt 0 ]
then
	DISPLAY=`echo $DISPLAY | sed "s/unix/$localhost/"`
elif [ `expr "$DISPLAY" : 'localhost:[0-9]*\.*[0-9]*'` -gt 0 ]
then
	DISPLAY=`echo $DISPLAY | sed "s/localhost/$localhost/"`
fi

# Some platforms have rsh as "restricted shell" and ucb rsh is remsh or rcmd
if [ -r /usr/bin/remsh ]
then
	RSH=remsh
elif [ -f /usr/bin/rcmd ]	# SCO Unix uses "rcmd" instead of rsh
then
	RSH=rcmd
else
	RSH=rsh
fi

default_auth_type=xhost	# sites might want to change this
authenv=
xhostvar=		# used by auth type xhost-xterminal
mode=dir

# process command line arguments
foundarg=
until [ "$foundarg" = "no" ]
do
	foundarg=no
	case $1 in
	-remote)
		mode=rmt; foundarg=yes; shift;
		;;
	-direct)
		mode=dir; foundarg=yes; shift;
		;;
	-auth)
		shift; XRSH_AUTH_TYPE=$1; foundarg=yes; shift;
		;;
	esac
done

clienthost="$1"; shift	# The full remote host name
command=$1
if [ -z "$command" ]	# default command to xterm if none specified
then
	return 1
else
	shift
fi

# Grab the arguments to the command here so that we don't have to worry
# about restoring them
xcmdargs=$@
if [ -n "$xcmdargs" ]
then
	command="$command $xcmdargs"
fi

# Use $XRSH_AUTH_TYPE to determine whether to run xhost, xauth, 
# propagate $XAUTHORITY to the remote host, or do nothing
case ${XRSH_AUTH_TYPE-$default_auth_type} in
xhost)      
	xhost +$clienthost >/dev/null 2>&1
	;;
xhost-xterminal)
	# If run on an X terminal, rsh to the XDMCP host to run xhost
	# if this is the first time, we are on the XDMCP host and 
	# we can just run xhost.
	if [ "$XHOST" = "" ]
	then
		xhostvar="XHOST=$localhost; export XHOST;"
		xhost +$clienthost >/dev/null 2>&1 
	else
		xhostvar="XHOST=$XHOST; export XHOST;"
		xhostcmd="DISPLAY=$DISPLAY; export DISPLAY; \
			exec /usr/bin/X11/xhost +$clienthost"
		$RSH "$XHOST" exec /bin/sh -cf "\"$xhostcmd\"" </dev/null
	fi
;;
xauth)
	# the "xauth remove" is theoretically unnecessary below,
	# but due to a bug in the initial X11R5 (fixed in fix-09) xauth,
	# entries for MIT-MAGIC-COOKIE-1 get lost if
	# you do merge twice without the remove.  The remove
	# command can be removed when xauth gets fixed.
	xauth extract - $DISPLAY | \
	$RSH $clienthost xauth remove $DISPLAY \;xauth merge - >/dev/null 2>&1
	;;
environment)
	authenv="XAUTHORITY=$XAUTHORITY; export XAUTHORITY;"
	;;
none)
	;;
*)
	return 1
	;;
esac

#
# Run Mosaic on the remote host
#
if [ $mode = rmt ]
then
	# Who am i?
	WHOAMI=`id | sed -e 's/^uid=[0-9]*(//' -e 's/).*$//'`

	# Determine if a Mosaic process owned by me is running on the system

	# Try BSD-style ps
	mpid=`$RSH $clienthost /bin/ps x 2>/dev/null | \
		grep Mosaic | grep -v grep | head -1 | awk '{ print $1 }'`

	if [ -z "$mpid" ]
	then
		# Try SysV-style ps
		mpid=`$RSH $clienthost /bin/ps -fu $WHOAMI 2>/dev/null | \
			grep Mosaic | grep -v grep | \
			head -1 | awk '{ print $2 }'`
	fi

	if [ -z "$mpid" ]
	then
		# Not found
		exit 1
	fi

	# Remote control Mosaic
	$RSH $clienthost /bin/rm -f /tmp/Mosaic.$mpid
	$RSH $clienthost "(echo goto; echo $xcmdargs) >/tmp/Mosaic.$mpid" \
		2>/dev/null
	$RSH $clienthost "kill -USR1 $mpid" 2>/dev/null
	sleep 5
	$RSH $clienthost /bin/rm -f /tmp/Mosaic.$mpid
	exit 0
fi

echo "DISPLAY=$DISPLAY; export DISPLAY; $authenv $xhostvar $command" ' >/dev/null 2>&1 </dev/null &' | $RSH $clienthost /bin/sh &

exit $?