#!/bin/bash # Start up xterm (or any other X command) on the specified host # Adapted from various versions of xon prog=`echo $0 | sed 's/^.*\///'` longhost=`hostname -f 2>/dev/null` if [ $? -ne 0 ]; then echo $prog: Sorry, $prog only works on Linux/GNU systems. >&2 exit 1 fi shorthost=`echo $longhost | sed 's/\..*$//'` function checkrhosts() { cat <&2 $prog: The rsh connection to remote host failed. $prog: Check the following: $prog: - the hostname of the remote machine is correct, $prog: - the userid on the remote machine is correct, $prog: - the .rhosts file lists `$longhost`, $prog: - the permissions on the .rhosts are 0600 (accessible to you only), $prog: - the program to be invoked exists on the remote machine. EOF } function usage() { cat < to set the userid on the remote machine. For -permit to work, you must name this machine ($longhost) in your .rhosts on the remote machine. You may also need to set the permissions on the .rhosts using chmod 600 .rhosts. -nols changes the default command from 'xterm -ls' to 'xterm'. EOF exit 0 } # Parse the argument list if [ $# -eq 0 ]; then usage >&2; exit 1; fi redirect="&0 2>&0 3>&- 4>&- 5>&- 6>&- 7>&- 8>&- &" ls=-ls; continue=:; permit=no; user=; remotehost= while $continue; do case $1 in -user) shift if [ $# -eq 0 ]; then echo "$prog: Expected username after -user" exit 1; fi user="-l $1"; shift ;; -debug) shift; redirect= ;; -access|-permit) shift; permit=yes ;; -ls) shift; ls=-ls ;; -nols) shift; ls= ;; -help|--help) showhelp ;; *) if [ -z "$remotehost" ]; then remotehost=$1; shift else continue=false fi ;; esac done # Have compulsory arguments been set? if [ -z "$remotehost" ]; then echo "$prog: You must specify a remote host" >&2 usage >&2 exit 1 fi if [ -z "$DISPLAY" ]; then echo "$prog: \$DISPLAY should be set for xcmd to work properly." >&2 exit 1; fi # Is this a local or a remote connection? remote=yes; case $DISPLAY in unix:*) DISPLAY=`echo $DISPLAY | sed 's/unix//'` ;; esac case $DISPLAY in :*) DISPLAY=${longhost}$DISPLAY ;; esac if [ $remotehost = $shorthost -o $remotehost = $longhost \ -o $remotehost = localhost ]; then remote=no fi # Copy the authority across if necessary rcmd="sh -c" if [ $remote = yes ]; then rcmd="rsh $remotehost $user" if [ "$permit" = yes ]; then xauth extract - $DISPLAY | $rcmd \ PATH=\$PATH:/usr/bin/X11 xauth merge - && \ echo "$prog: permitted $remotehost access to $DISPLAY" if [ $? -ne 0 ]; then checkrhosts; exit 1 fi fi fi # Run the command vars=DISPLAY=$DISPLAY if [ $# -eq 0 ]; then set - xterm $ls; fi $rcmd "sh -c '$vars $* $redirect'" xcmd_exit=$? if [ "$xcmd_exit" -ne 0 ]; then if [ $remote = "yes" ]; then checkrhosts else echo "$prog: Unable to run $*" >&2 fi fi exit $xcmd_exit