#!/bin/bash SCRIPT=$(basename $0) usage() { echo "Usage: $SCRIPT [--x] [--verbose] [su|sudo] [[{user}]@{host}] [[--] command...]" } termwrapper() { PRG=$@ if [ "$V" = 1 ]; then echo $PRG sleep 4 fi if [ -n "$PRG" ]; then x-terminal-emulator -e $PRG & else x-terminal-emulator & fi } # Initial setup SU='' SUDO='' X='' V='' HOST='' ssh_opts="-t" while [ $# -gt 0 ]; do case $1 in su) SU=1; SUDO=;; sudo) SUDO=1; SU=;; --x|-x|x) X=1; ssh_opts="$ssh_opts -X";; --verbose|-v) V=1; ssh_opts="$ssh_opts -v";; --port|-p) ssh_opts="$ssh_opts -p $2"; shift;; --) shift; break;; -*) usage; exit 1;; @*) HOST=${1#@};; *@*) HOST=$1;; *) break;; esac shift done [ $# -gt 0 ] || set -- /bin/bash # FIXME: needs shell wrapper (provided by SSH but not in local use) [ -z "$SU" ] || set -- "echo -n 'Changing to root...: '; su -c \"cd; "$@"\"" [ -z "$SUDO" ] || set -- sudo -i -- "$@" # Split program name from its options if [ $# -gt 0 ]; then prg_base=$1 shift prg_opts=$@ fi # Pause for a moment if verbose if [ "$V" = 1 ]; then prg_opts="$prg_opts; sleep 4" fi prg="$prg_base $prg_opts" case "$HOST" in '') termwrapper $prg ;; *) termwrapper ssh $ssh_opts $HOST $prg ;; esac