summaryrefslogtreecommitdiff
path: root/xsh
diff options
context:
space:
mode:
authorJonas Smedegaard <dr@jones.dk>2002-02-28 14:09:04 +0000
committerJonas Smedegaard <dr@jones.dk>2002-02-28 14:09:04 +0000
commitcafcd5d4368e57f162a641ed3f4835ecb5a6d391 (patch)
tree56166fbf16289d8b388cf0f1f9b51e28c3c4bdf9 /xsh
Initial revision
Diffstat (limited to 'xsh')
-rwxr-xr-xxsh137
1 files changed, 137 insertions, 0 deletions
diff --git a/xsh b/xsh
new file mode 100755
index 0000000..0c28280
--- /dev/null
+++ b/xsh
@@ -0,0 +1,137 @@
+#!/bin/bash
+
+SCRIPT=$(basename $0)
+
+function usage () {
+ echo "Usage: $SCRIPT [--x] [--verbose] [[--su |{user}@]{host}]"
+}
+
+function termwrapper () {
+ PRG=$@
+ title="$title $titleopt"
+ [ $V ] && echo $PRG
+
+ # mc seem to have a bug separating upper- and lowercase with danish locale
+# case $LANG in
+# da_*) LANG=da;;
+# esac
+
+ if [ "x$PRG" != "x" ]; then
+# if [ -z $PRG ]; then
+# rxvt +sb -sl 500 -n "$title" -title "$title" -e $PRG &
+ exec rxvt +sb -sl 500 -n "$title" -title "$title" -e $PRG
+ else
+# rxvt +sb -sl 500 -n "$title" -title "$title" &
+ exec rxvt +sb -sl 500 -n "$title" -title "$title"
+ fi
+}
+
+# Initial setup
+SU=''
+X=''
+V=''
+SUHACK=''
+HOST=''
+USER=''
+ssh_opts="-t"
+
+args=''
+while [ $# -gt 0 ]; do
+ case $1 in
+ -su|su) SU=1;;
+ -suu|suu) SU=1; SUU=1;; # Become root indirectly through a regular user (same as local user if -u not used)
+ --user|-u) USER=$2; shift;; # Remote user allowed to switch to root
+ --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";;
+ --port|-p) ssh_opts="$ssh_opts -p $2"; shift;;
+ --host|-h) HOST=$1;;
+ -) HOST="localhost";;
+ -*) usage; exit 1;;
+ root@*) HOST="$1"; SU=1; SUHACK=1;;
+ *) args="$args$1 ";;
+ esac
+ shift
+done
+set -- $args
+
+if [ -z $HOST ]; then
+ HOST=$1
+ shift
+fi
+if [ -z $HOST ]; then
+ usage
+ exit 1
+fi
+
+prg_base=$1
+shift
+prg_opts=$@
+
+if [ "$X" -a "$SU" -a ! "$SUHACK" ]; then
+ args="root@$args"
+ SUHACK=1
+fi
+
+titleopt="[$HOST]"
+if [ $HOST != "localhost" ]; then
+ ssh_opts="-C $ssh_opts"
+fi
+
+[ $V ] && prg_opts="$prg_opts; sleep 4"
+
+## Don't open 2 shells if no program is run - Disabled for now (something wrong with the test...)
+#if [ -z $prg_base -a -z $prg_opts -a -z $SUU ]; then
+# title="$SCRIPT"
+# prg_local=''
+# prg_remote=''
+#else
+ if [ -z $prg_base ]; then
+ title="$SCRIPT"
+ prg_base='/bin/bash'
+ else
+ title="$prg_base"
+ prg_opts_local="$prg_opts"
+ prg_opts_remote="$prg_opts"
+ fi
+
+ # Special cases for specific programs
+ case $prg_base in
+ mc) prg_opts_remote="-s -c $prg_opts_remote" # Midnight Commander has an option for slow connections
+ ;;
+ esac
+
+ prg_local="$prg_base $prg_opts_local"
+ if [ $SUU ]; then
+ prg_remote="echo -n 'Changing to root...: '; su $su_opts -c \"cd; $prg_base $prg_opts_remote\""
+ else
+# prg_remote="bash -i -c \"$prg_base $prg_opts_remote\""
+# prg_remote="bash -i -c \"test -e /etc/debian_version || export TERM=xterm; $prg_base $prg_opts_remote\""
+ prg_remote="bash --login -i -c \"test -e /etc/debian_version || export TERM=xterm; $prg_base $prg_opts_remote\""
+# prg_remote="bash -i -c \"test -e /etc/debian_version || export TERM=xterm; $prg_base $prg_opts_remote\""
+ fi
+#fi
+
+if [ ! $SU ]; then
+ if [ $HOST = "localhost" ]; then
+ termwrapper $prg_local
+ else
+ termwrapper ssh $ssh_opts $HOST $prg_remote
+ fi
+else
+ if [ "$SUHACK" ]; then
+# termwrapper ssh $ssh_opts $HOST su $su_opts -c \"$prg_remote\"
+ termwrapper ssh $ssh_opts $HOST $prg_remote
+ else
+ titleopt="[$HOST root]"
+ if [ $SUU ]; then
+ if [ "x$USER" = "x" ]; then
+ termwrapper ssh $ssh_opts $HOST $prg_remote
+ else
+ termwrapper ssh $ssh_opts $USER@$HOST $prg_remote
+ fi
+ else
+ termwrapper ssh $ssh_opts root@$HOST $prg_remote
+ fi
+ fi
+fi