summaryrefslogtreecommitdiff
path: root/xsh
blob: 31608c3d684abc9042b0e1006e357d40ff1fe29f (plain)
  1. #!/bin/bash
  2. SCRIPT=$(basename $0)
  3. usage() {
  4. echo "Usage: $SCRIPT [--x] [--verbose] [su|sudo] [[{user}]@{host}] [[--] command...]"
  5. }
  6. termwrapper() {
  7. PRG=$@
  8. if [ "$V" = 1 ]; then
  9. echo $PRG
  10. sleep 4
  11. fi
  12. if [ -n "$PRG" ]; then
  13. x-terminal-emulator -e $PRG &
  14. else
  15. x-terminal-emulator &
  16. fi
  17. }
  18. # Initial setup
  19. SU=''
  20. SUDO=''
  21. X=''
  22. V=''
  23. HOST=''
  24. ssh_opts="-t"
  25. while [ $# -gt 0 ]; do
  26. case $1 in
  27. su) SU=1; SUDO=;;
  28. sudo) SUDO=1; SU=;;
  29. --x|-x|x) X=1; ssh_opts="$ssh_opts -X";;
  30. --verbose|-v) V=1; ssh_opts="$ssh_opts -v";;
  31. --port|-p) ssh_opts="$ssh_opts -p $2"; shift;;
  32. --) shift; break;;
  33. -*) usage; exit 1;;
  34. @*) HOST=${1#@};;
  35. *@*) HOST=$1;;
  36. *) break;;
  37. esac
  38. shift
  39. done
  40. [ $# -gt 0 ] || set -- /bin/bash
  41. [ -z "$SUDO" ] || set -- sudo -i -- "$@"
  42. # Split program name from its options
  43. if [ $# -gt 0 ]; then
  44. prg_base=$1
  45. shift
  46. prg_opts=$@
  47. fi
  48. # Pause for a moment if verbose
  49. if [ "$V" = 1 ]; then
  50. prg_opts="$prg_opts; sleep 4"
  51. fi
  52. prg="$prg_base $prg_opts"
  53. prg_su="echo -n 'Changing to root...: '; su -c \"cd; $prg\""
  54. case "$HOST" in
  55. '')
  56. if [ -n "$SU" ]; then
  57. termwrapper $prg_su
  58. else
  59. termwrapper $prg
  60. fi
  61. ;;
  62. *)
  63. if [ -n "$SU" ]; then
  64. termwrapper ssh $ssh_opts $HOST $prg_su
  65. else
  66. termwrapper ssh $ssh_opts $HOST $prg
  67. fi
  68. ;;
  69. esac