[PATCH app/scripts] Add ssh support to 'xon'

Egbert Eich eich at freedesktop.org
Fri Feb 7 04:17:32 PST 2014


'xon' has been around for ages, it's a small script that can be used
to start any xclient remotely.
It did so by opening a shell connection using 'rsh' or 'rcmd' to
connect to the remote system. Today (hopefully) nobody has rsh
installed any more for security reasons.
'ssh' has become the remote login tool of chioce which also allows
to tunnel the X protocol over a secure channel.
This patch adds ssh support to xon to make it useful again.

Signed-off-by: Egbert Eich <eich at freedesktop.org>
---

I could be talked into nuking the rsh, rcmd support completely which
would greatly simlify things.


 xon | 61 ++++++++++++++++++++++++++++++++++++++++++++++++-------------
 1 file changed, 48 insertions(+), 13 deletions(-)

diff --git a/xon b/xon
index 772b357..959e0e7 100644
--- a/xon
+++ b/xon
@@ -32,20 +32,27 @@ target=$1
 shift
 label=$target
 resource=xterm-$label
-if [ -f /usr/bin/remsh ]; then
+if [ -x /usr/bin/ssh ]; then
+    rsh=/usr/bin/ssh
+elif [ -f /usr/bin/remsh ]; then
     rsh=/usr/bin/remsh
 elif [ -f /usr/bin/rcmd ]; then
     rsh=/usr/bin/rcmd
 else
     rsh=rsh
 fi
-rcmd="$rsh $target -n"
-case $DISPLAY in
+case $rsh in
+    *ssh) rcmd_args="-Y $target" ;;
+    *) rcmd_args="$target -n" ;;
+esac
+
+display=$DISPLAY
+case $display in
 unix:*)
-	DISPLAY=`echo $DISPLAY | sed 's/unix//'`
+	display=`echo $display | sed 's/unix//'`
 	;;
 esac
-case $DISPLAY in
+case $display in
 :*)
 	case `uname` in
 	Linux*)
@@ -61,10 +68,10 @@ case $DISPLAY in
 	esac
 	hostname=`echo $fullname | sed 's/\..*$//'`
 	if [ $hostname = $target ] || [ $fullname = $target ]; then
-		DISPLAY=$DISPLAY
+		display=$display
 		rcmd="sh -c"
 	else
-		DISPLAY=$fullname$DISPLAY
+		display=$fullname$display
 	fi
 	;;
 esac
@@ -79,17 +86,23 @@ x)
 	xpath='HOME=${HOME-`pwd`} XUSERFILESEARCHPATH=${XUSERFILESEARCHPATH-"'"$XUSERFILESEARCHPATH"'"} '
 	;;
 esac
-redirect=" < /dev/null > /dev/null 2>&1 &"
+debug=n
 command=
 ls=-ls
 continue=:
+remote_background=
+rcmd_background_arg=
+
 while $continue; do
 	case $1 in
 	-remote)
 		shift
 		if [ $rsh != "sh" ]; then
 			rsh="$1"
-			rcmd="$rsh $target -n"
+			case $rsh in
+			    *ssh) rcmd_args="-fY $target" ;;
+			    *) rcmd_args="$target -n" ;;
+			esac
 		fi
 		shift;;
 	-user)
@@ -102,7 +115,10 @@ while $continue; do
 
 		username="-l $1"
 		label="$target $1"
-		rcmd="$rsh $target $username -n"
+		case $rsh in
+		    *ssh) rcmd_args="-Y ${username}@${target}" ;;
+		    *) rcmd_args="$rsh $target $username -n" ;;
+		esac
 		shift
 		case x$XAUTHORITY in
 		x)
@@ -139,7 +155,7 @@ while $continue; do
 		;;
 	-debug)
 		shift
-		redirect=
+		debug=y
 		;;
 	-screen)
 		shift
@@ -149,7 +165,7 @@ while $continue; do
 			usage "-screen option requires an argument"
 		fi
 
-		DISPLAY=`echo $DISPLAY | sed 's/:\\([0-9][0-9]*\\)\\.[0-9]/:\1/'`.$1
+		display=`echo $display | sed 's/:\\([0-9][0-9]*\\)\\.[0-9]/:\1/'`.$1
 		shift
 		;;
 	*)
@@ -171,7 +187,26 @@ x*)
 	sess_mangr="SESSION_MANAGER=$SESSION_MANAGER "
 	;;
 esac
-vars='PATH=${PATH:+$PATH:}/usr/X11R6/bin '"$xpath$xauth$sess_mangr"DISPLAY="$DISPLAY"
+vars='PATH=${PATH:+$PATH:}/usr/X11R6/bin '"$xpath$xauth$sess_mangr"
+case $rsh in
+    *ssh) 
+	rcmd_background_arg="-f "
+	;;
+    *) 
+	remote_background="&";
+	DISPLAY=$display
+	vars=${vars}DISPLAY="$DISPLAY" 
+	;;
+esac
+
+if [ "$debug" = "n" ]
+then
+    rcmd_args=$rcmd_background_arg$rcmd_args
+    redirect=" < /dev/null > /dev/null 2>&1 $remote_background"
+fi
+
+[ "z" = "z$rcmd" ] && rcmd="$rsh $rcmd_args"
+
 case $# in
 0)
 	$rcmd 'sh -c '"'$vars"' xterm '$ls' -name "'"$resource"'" -T "'"$label"'" -n "'"$label"'" '"$redirect'"
-- 
1.8.1.4



More information about the xorg-devel mailing list