Created
October 13, 2015 14:00
-
-
Save nod0n/c32a911972ca8b739c4b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
declare -A data | |
data[host]='' | |
data[port]='' | |
data[user]='' | |
data[pw]='' | |
data[domain]='' | |
function usage { | |
printf -- "options:\n" | |
printf -- "-H Host " | |
printf -- "[-P port] " | |
printf -- "[-u user] " | |
printf -- "-p password " | |
printf -- "[-D domain]" | |
printf -- "\n\n" | |
} | |
while getopts H:P:u:p:D:h option | |
do | |
case "$option" in | |
H) | |
data[host]=$OPTARG | |
;; | |
P) | |
data[port]=$OPTARG | |
;; | |
u) | |
data[user]=$OPTARG | |
;; | |
p) | |
data[pw]=$OPTARG | |
;; | |
D) | |
data[domain]=$OPTARG | |
;; | |
h) | |
usage | |
exit 0 | |
;; | |
*) | |
usage >&2 | |
exit 1 | |
;; | |
esac | |
done | |
for key in "${!data[@]}" | |
do | |
if [[ "$key" = 'host' || "$key" = 'pw' && -z "${data[$key]}" ]] | |
then | |
echo "$key must be given!" >&2 | |
usage >&2 | |
exit 1 | |
fi | |
if [[ "$key" = 'user' && -z "${data[$key]}" ]] | |
then | |
data["$key"]="$USER" | |
fi | |
done | |
rdesktop -u "${data[user]}" -p "${data[pw]}""$( | |
if [[ -z "${data[domain]}" ]] | |
then | |
printf " -d %s" "${data[domain]}" | |
fi | |
)" "${data[host]}$( | |
if [[ -z "${data[port]}" ]] | |
then | |
printf ":%s" "${data[port]}" | |
fi | |
)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment