blob: c7a83642999be1b05779ab102da7652af4f24a7e (
plain)
- #!/bin/bash
- SCRIPT=$(basename $0)
- usage() {
- echo "Usage: $SCRIPT [--x] [--verbose] [[su] [{user}@]{host}] [-- command...]"
- }
- termwrapper() {
- PRG=$@
- if [ "$V" = 1 ]; then
- echo $PRG
- sleep 4
- fi
- if [ -n "$PRG" ]; then
- # x-terminal-emulator +sb -sl 500 -e $PRG &
- x-terminal-emulator $opts -e $PRG &
- # exec x-terminal-emulator $opts -e $PRG &
- else
- # exec x-terminal-emulator +sb -sl 500 &
- x-terminal-emulator $opts &
- # exec x-terminal-emulator $opts &
- fi
- }
- # Initial setup
- SU=''
- X=''
- V=''
- HOST=''
- ssh_opts="-t"
- while [ $# -gt 0 ]; do
- case $1 in
- 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";;
- --port|-p) ssh_opts="$ssh_opts -p $2"; shift;;
- --) shift; break;;
- -*) usage; exit 1;;
- *) [ -z "$HOST" ] && HOST=$1 || break;;
- esac
- shift
- done
- # Split program name from its options
- if [ $# -gt 0 ]; then
- prg_base=$1
- shift
- prg_opts=$@
- fi
- case `readlink /etc/alternatives/x-terminal-emulator | xargs basename` in
- # rxvt*) opts="+sb -sl 500";;
- rxvt*) opts="+sb -sl 500 -ls";;
- urxvt*) opts="+sb -sl 500 -ls";;
- *xterm) opts="+sb -sl 500 +wc";;
- gnome-terminal) opts="";;
- gnome-terminal.wrapper) opts="";;
- konsole*) opts="--notoolbar";;
- *) opts="";;
- esac
- # Pause for a moment if verbose
- if [ "$V" = 1 ]; then
- prg_opts="$prg_opts; sleep 4"
- fi
- if [ -z "$prg_base" ]; then
- prg_base='/bin/bash'
- fi
- prg="$prg_base $prg_opts"
- prg_su="echo -n 'Changing to root...: '; su -c \"cd; $prg\""
- case "$HOST" in
- '')
- if [ -n "$SU" ]; then
- termwrapper $prg_su
- else
- termwrapper $prg
- fi
- ;;
- *)
- if [ -n "$SU" ]; then
- termwrapper ssh $ssh_opts $HOST $prg_su
- else
- termwrapper ssh $ssh_opts $HOST $prg
- fi
- ;;
- esac
|