guacamole-spice-protocol/bin/guacctl

82 lines
1.3 KiB
Plaintext
Raw Normal View History

2013-10-28 02:36:19 +00:00
#!/bin/sh
#
# guacctl
#
# Utility for sending Guacamole-specific console codes for controlling the SSH
# session, such as:
#
# * Downloading files
# * Setting the destination directory for uploads
#
2013-10-28 16:28:23 +00:00
fullpath() {
FILENAME="$1"
DIR=`dirname "$FILENAME"`
FILE=`basename "$FILENAME"`
(cd "$DIR" && echo "$PWD/$FILE")
}
2013-10-28 02:36:19 +00:00
send_download_file() {
FILENAME="$1"
printf "\033]482200;%s\007" "$FILENAME"
}
send_set_directory() {
FILENAME="$1"
printf "\033]482201;%s\007" "$FILENAME"
}
error() {
echo "$NAME:" "$@" >&2
}
usage() {
cat >&2 <<END
Usage:
guacctl --download FILENAME
guacctl --set-directory FILENAME
END
}
download_files() {
for FILENAME in "$@"; do
if [ -e "$FILENAME" ]; then
2013-10-28 16:28:23 +00:00
send_download_file `fullpath $FILENAME`
2013-10-28 02:36:19 +00:00
else
error "$FILENAME: File does not exist."
fi
done
}
set_directory() {
FILENAME="$1"
if [ -e "$FILENAME" ]; then
2013-10-28 16:28:23 +00:00
send_set_directory `fullpath "$FILENAME"`
2013-10-28 02:36:19 +00:00
else
error "$FILENAME: File does not exist or is not a directory."
fi
}
NAME=`basename "$0"`
# Parse options
if [ "x$NAME" = "xguacget" ]; then
download_files "$@"
elif [ "x$1" = "x--download" ]; then
shift
download_files "$@"
elif [ "x$1" = "x--set-directory" ]; then
shift
set_directory "$@"
else
usage
exit 1
fi