GUAC-1452: Update guacctl defining the terminal codes for controlling pipe streams.

This commit is contained in:
Michael Jumper 2016-01-08 12:47:02 -08:00
parent 6c0862e82d
commit 6c0cd22b90

View File

@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
# #
# Copyright (C) 2013 Glyptodon LLC # Copyright (C) 2016 Glyptodon LLC
# #
# Permission is hereby granted, free of charge, to any person obtaining a copy # Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal # of this software and associated documentation files (the "Software"), to deal
@ -25,11 +25,12 @@
# guacctl # guacctl
# ------- # -------
# #
# Utility for sending Guacamole-specific console codes for controlling the SSH # Utility for sending Guacamole-specific console codes for controlling a
# session, such as: # terminal session, such as:
# #
# * Downloading files # * Downloading files (SSH only)
# * Setting the destination directory for uploads # * Setting the destination directory for uploads (SSH only)
# * Redirecting output to a named pipe stream (SSH or telnet)
# #
# This script may also be run as "guacget", in which case the script accepts # This script may also be run as "guacget", in which case the script accepts
# no options and assumes anything given on the commandline is a file to be # no options and assumes anything given on the commandline is a file to be
@ -58,6 +59,19 @@ send_set_directory() {
printf "\033]482201;%s\007" "$FILENAME" printf "\033]482201;%s\007" "$FILENAME"
} }
# Sends the Guacamole-specific console code for redirecting output to a named
# pipe stream (instead of the terminal emulator)
send_open_pipe_stream() {
NAME="$1"
printf "\033]482202;%s\007" "$NAME"
}
# Sends the Guacamole-specific console code for redirecting output back to the
# terminal emulator
send_close_pipe_stream() {
printf "\033]482203\007"
}
# Prints the given error text to STDERR. # Prints the given error text to STDERR.
error() { error() {
echo "$NAME:" "$@" >&2 echo "$NAME:" "$@" >&2
@ -66,12 +80,16 @@ error() {
# Prints usage documentation for this script. # Prints usage documentation for this script.
usage() { usage() {
cat >&2 <<END cat >&2 <<END
guacctl 0.8.0, Guacamole SSH session control utility. guacctl 0.9.9, Guacamole terminal session control utility.
Usage: guacctl [OPTION] [FILE]... Usage: guacctl [OPTION] [FILE or NAME]...
-d, --download download each of the files listed. -d, --download download each of the files listed.
-s, --set-directory set the destination directory for future uploaded -s, --set-directory set the destination directory for future uploaded
files. files.
-o, --open-pipe redirect output to a new pipe stream with the given
name.
-c, --close-pipe close any existing pipe stream and redirect output
back to the terminal emulator.
END END
} }
@ -117,6 +135,40 @@ set_directory() {
} }
# Opens a new pipe stream having the given name and redirects terminal output
# to that stream
open_pipe_stream() {
# Validate arguments
if [ $# -lt 1 ]; then
error "No pipe name specified."
return;
fi
if [ $# -gt 1 ]; then
error "Only one pipe name may be given."
return;
fi
NAME="$1"
send_open_pipe_stream "$NAME"
}
# Closes the currently-open pipe stream and redirects terminal output back to
# the terminal emulator
close_pipe_stream() {
# Validate arguments
if [ $# -gt 0 ]; then
error "Closing an open pipe stream does not require any arguments."
return;
fi
send_close_pipe_stream
}
# Get script name # Get script name
NAME=`basename "$0"` NAME=`basename "$0"`
@ -129,6 +181,12 @@ elif [ "x$1" = "x--download" -o "x$1" = "x-d" ]; then
elif [ "x$1" = "x--set-directory" -o "x$1" = "x-s" ]; then elif [ "x$1" = "x--set-directory" -o "x$1" = "x-s" ]; then
shift shift
set_directory "$@" set_directory "$@"
elif [ "x$1" = "x--open-pipe" -o "x$1" = "x-o" ]; then
shift
open_pipe_stream "$@"
elif [ "x$1" = "x--close-pipe" -o "x$1" = "x-c" ]; then
shift
close_pipe_stream "$@"
else else
usage usage
exit 1 exit 1