blob: c655c5718f3996d4e80c189b4c366dceb827cc44 (
plain)
- #!/bin/bash
- SCRIPT=$(basename $0)
- usage() {
- echo "Usage: $SCRIPT [--x] [--verbose] [su|sudo] [[{user}]@{host}] [[--] command...]"
- }
- # origin: http://stackoverflow.com/a/34515468
- quote_args() {
- local sq="'"
- local dq='"'
- local space=""
- local arg
- for arg; do
- echo -n "$space'${arg//$sq/$sq$dq$sq$dq$sq}'"
- space=" "
- done
- }
- # Initial setup
- SU=''
- SUDO=''
- X=''
- V=''
- HOST=''
- PORT=''
- while [ $# -gt 0 ]; do
- case $1 in
- su) SU=1; SUDO=;;
- sudo) SUDO=1; SU=;;
- --x|-x|x) X=1;;
- --verbose|-v) V=1;;
- --port|-p) PORT="$2"; shift;;
- --) shift; break;;
- -*) usage; exit 1;;
- @*) HOST=${1#@};;
- *@*) HOST=$1;;
- *) break;;
- esac
- shift
- done
- [ $# -gt 0 ] || set -- /bin/bash
- [ -z "$SU" ] || set -- su -c "cd; $(quote_args "$@")"
- [ -z "$SU" ] || set -- sh -c "echo -n 'Changing to root...: '; $(quote_args "$@")"
- [ -z "$SUDO" ] || set -- sudo -i -- "$@"
- # Pause for a moment if verbose
- [ -z "$V" ] || set -- sh -c "$(quote_args "$@"); sleep 4"
- [ -z "$HOST" ] || set -- ssh -t${X:+ -X}${V:+ -v}${PORT:+ -p "$PORT"} $HOST "$(quote_args "$@")"
- [ -z "$V" ] || echo "$@"
- [ -z "$V" ] || sleep 4
- if [ $# -gt 0 ]; then
- x-terminal-emulator -e "$@" &
- else
- x-terminal-emulator &
- fi
|