Finish functionality+docs for guacctl. Add guacget symbolic link.

This commit is contained in:
Michael Jumper 2013-10-28 14:28:37 -07:00
parent 1ba575d3aa
commit 93a7576312
2 changed files with 40 additions and 7 deletions

View File

@ -44,7 +44,14 @@
# * Downloading files # * Downloading files
# * Setting the destination directory for uploads # * Setting the destination directory for uploads
# #
# 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
# downloaded.
#
# Given the name of a file, which may be a relative path, produce the full,
# real, non-relative path for that same file.
fullpath() { fullpath() {
FILENAME="$1" FILENAME="$1"
DIR=`dirname "$FILENAME"` DIR=`dirname "$FILENAME"`
@ -52,32 +59,44 @@ fullpath() {
(cd "$DIR" && echo "$PWD/$FILE") (cd "$DIR" && echo "$PWD/$FILE")
} }
# Sends the Guacamole-specific console code for initiating a download.
send_download_file() { send_download_file() {
FILENAME="$1" FILENAME="$1"
printf "\033]482200;%s\007" "$FILENAME" printf "\033]482200;%s\007" "$FILENAME"
} }
# Sends the Guacamole-specific console code for setting the upload directory.
send_set_directory() { send_set_directory() {
FILENAME="$1" FILENAME="$1"
printf "\033]482201;%s\007" "$FILENAME" printf "\033]482201;%s\007" "$FILENAME"
} }
# Prints the given error text to STDERR.
error() { error() {
echo "$NAME:" "$@" >&2 echo "$NAME:" "$@" >&2
} }
# Prints usage documentation for this script.
usage() { usage() {
cat >&2 <<END cat >&2 <<END
Usage: guacctl 0.8.0, Guacamole SSH session control utility.
Usage: guacctl [OPTION] [FILE]...
guacctl --download FILENAME
guacctl --set-directory FILENAME
-d, --download download each of the files listed.
-s, --set-directory set the destination directory for future uploaded
files.
END END
} }
# Initiates a download for each of the specified files
download_files() { download_files() {
# Validate arguments
if [ $# -lt 1 ]; then
error "No files specified."
return;
fi
for FILENAME in "$@"; do for FILENAME in "$@"; do
if [ -e "$FILENAME" ]; then if [ -e "$FILENAME" ]; then
send_download_file `fullpath $FILENAME` send_download_file `fullpath $FILENAME`
@ -88,10 +107,22 @@ download_files() {
} }
# Changes the upload path for future uploads to the given directory
set_directory() { set_directory() {
# Validate arguments
if [ $# -lt 1 ]; then
error "No destination directory specified."
return;
fi
if [ $# -gt 1 ]; then
error "Only one destination directory may be given."
return;
fi
FILENAME="$1" FILENAME="$1"
if [ -e "$FILENAME" ]; then if [ -d "$FILENAME" ]; then
send_set_directory `fullpath "$FILENAME"` send_set_directory `fullpath "$FILENAME"`
else else
error "$FILENAME: File does not exist or is not a directory." error "$FILENAME: File does not exist or is not a directory."
@ -99,15 +130,16 @@ set_directory() {
} }
# Get script name
NAME=`basename "$0"` NAME=`basename "$0"`
# Parse options # Parse options
if [ "x$NAME" = "xguacget" ]; then if [ "x$NAME" = "xguacget" ]; then
download_files "$@" download_files "$@"
elif [ "x$1" = "x--download" ]; then elif [ "x$1" = "x--download" -o "x$1" = "x-d" ]; then
shift shift
download_files "$@" download_files "$@"
elif [ "x$1" = "x--set-directory" ]; then elif [ "x$1" = "x--set-directory" -o "x$1" = "x-s" ]; then
shift shift
set_directory "$@" set_directory "$@"
else else

1
bin/guacget Symbolic link
View File

@ -0,0 +1 @@
guacctl