From 521f599f0fc47d42c401f182e4bf9240ed300de7 Mon Sep 17 00:00:00 2001 From: Jonas Smedegaard Date: Fri, 21 Oct 2016 23:07:49 +0200 Subject: Change option su to literally call su (replacing and dropping ill-named option -suu|suu, and rely on ssh syntax for direct-to-root access). --- xsh | 38 ++++++++++++++------------------------ 1 file changed, 14 insertions(+), 24 deletions(-) (limited to 'xsh') diff --git a/xsh b/xsh index 4656214..35c00c7 100755 --- a/xsh +++ b/xsh @@ -3,7 +3,7 @@ SCRIPT=$(basename $0) usage() { - echo "Usage: $SCRIPT [--x] [--verbose] [[--su] [{user}@]{host}] [--] [remote command...]" + echo "Usage: $SCRIPT [--x] [--verbose] [[su] [{user}@]{host}] [--] [remote command...]" } termwrapper() { @@ -28,16 +28,13 @@ termwrapper() { SU='' X='' V='' -SUHACK='' HOST='' ssh_opts="-t" args='' while [ $# -gt 0 ]; do case $1 in - -su|su) SU=1;; - # Become root indirectly through a regular user (same as local user if -u not used) - -suu|suu) SU=1; SUU=1;; + su) SU=1;; --x|-x|x) X=1; ssh_opts="$ssh_opts -X";; --ssh2|-2) ssh_opts="$ssh_opts -2";; --verbose|-v) V=1; ssh_opts="$ssh_opts -v";; @@ -46,7 +43,6 @@ while [ $# -gt 0 ]; do -) HOST="localhost";; --) shift; args="$args$@ "; break;; -*) usage; exit 1;; - root@*) HOST="$1"; SU=1; SUHACK=1;; *) args="$args$1 ";; esac shift @@ -70,11 +66,6 @@ if [ $# -gt 0 ]; then prg_opts=$@ fi -if [ "$X" = 1 -a "$SU" = 1 -a "$SUHACK" != 1 ]; then - args="root@$args" - SUHACK=1 -fi - if [ $HOST != "localhost" ]; then ssh_opts="-C $ssh_opts" fi @@ -102,20 +93,19 @@ fi prg="$prg_base $prg_opts" prg_su="echo -n 'Changing to root...: '; su -c \"cd; $prg\"" -if [ "$SU" != 1 ]; then - if [ $HOST = "localhost" ]; then - termwrapper $prg +case "$HOST" in + *@localhost|localhost) + if [ -n "$SU" ]; then + termwrapper $prg_su else - termwrapper ssh $ssh_opts $HOST $prg + termwrapper $prg fi -else - if [ "$SUHACK" = 1 ]; then - termwrapper ssh $ssh_opts $HOST $prg + ;; + *) + if [ -n "$SU" ]; then + termwrapper ssh $ssh_opts $HOST $prg_su else - if [ "$SUU" = 1 ]; then - termwrapper ssh $ssh_opts $HOST $prg_su - else - termwrapper ssh $ssh_opts root@$HOST $prg - fi + termwrapper ssh $ssh_opts $HOST $prg fi -fi + ;; +esac -- cgit v1.2.3