Last active
December 8, 2015 17:15
-
-
Save nod0n/8b6d853ff5dc4cbf2502 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 | |
# this script should (when completly written) | |
# - list hosts | |
# - provide some information about hosts | |
# - connect to hosts | |
# - get credentials from config file | |
# - get information about hosts from a provided textfile | |
# config file has to have 3 lines, lines beginning with '#' are ignored. | |
# missing information will be asked if not found in file | |
# - domain=your_domain | |
# - user=your_user | |
# - pw=your_pw | |
RESOLUTION='1865x1150' # this is up to you | |
CLIPBOARD_SYNC=true #default: true | |
MENU_ANIMATION=false #default: false | |
CHECK_CERT=false #default: false | |
#just taking the freerdp direcotry, could be changed to a proper one | |
CONFIG_DIR=~/.freerdp/ #default: ~/.freerdp/ | |
# config file should be named like: "rdp-${domain}.conf" | |
CONFIG_DIR_PATTERN="rdp-*.conf" #default: "rdp-*.conf" | |
SEARCH_RDP_COMMAND=search_rdp | |
declare config domain hostname e_wrong_usage=1 | |
declare -a options | |
declare -A lines credentials | |
scan () { | |
which "$SEARCH_RDP_COMMAND" && "$SEARCH_RDP_COMMAND" | |
} | |
while getopts hs option | |
do | |
case "$option" in | |
h) | |
usage | |
exit 0 | |
;; | |
s) | |
scan | |
exit 0 | |
;; | |
*) | |
: | |
;; | |
esac | |
done | |
# if only one argument assuming it's the hostname | |
if (( $# == 1 )); then | |
hostname=$1 | |
elif (( $# == 2 )); then | |
domain=$1 | |
hostname=$2 | |
else | |
read -p 'enter Hostname:' hostname | |
fi | |
usage () { | |
printf '\nusage:\n' | |
printf "$0"' $domain $hostname\n\n' | |
printf '$domain stand for a part of the config file name.\n' | |
printf 'Config file name pattern:\t%s\n' "$CONFIG_DIR_PATTERN" | |
printf 'Config file directory:\t\t%s\n\n' "$CONFIG_DIR" | |
} | |
# source the global variables from the given domain | |
# only lines which don't beginn with '#' and aren't empty | |
config=$( | |
file="${CONFIG_DIR%/}/${CONFIG_DIR_PATTERN/\*/$domain}" | |
[[ -f $file ]] && grep -v -e '^[[:space:]]#' -e '^[[:space:]]*$' "$file" | |
) | |
for key in domain user pw | |
do | |
# passwords or usernames with spaces are not allowed, but should not be a problem | |
lines[$key]=$(grep -o $key='[^[:space:]]*' <<< "$config") | |
credentials[$key]=${lines[$key]#$key=} | |
printf "%s:\t%s\n" $key "${credentials[$key]}" | |
done | |
printf "$hostname\n" | |
# generating xfreerdp params | |
k="${credentials[domain]}"; [[ -n $k ]] && options+=("-d" "$k") | |
k="${credentials[user]}"; [[ -n $k ]] && options+=("-u" "$k") | |
k="${credentials[pw]}"; [[ -n $k ]] && options+=("-p" "$k") | |
k="$RESOLUTION"; [[ -n $k ]] && options+=("-g" "$k") | |
[[ $CLIPBOARD_SYNC = true ]] && options+=("--plugin" "cliprdr") | |
[[ $MENU_ANIMATION = false ]] && options+=("--disable-menu-animations") | |
[[ $CHECK_CERT = false ]] && options+=("--ignore-certificate") | |
# print what it will do first, just for testing feel free to remove | |
[[ -n $hostname ]] && echo xfreerdp "${options[@]}" "$hostname" | |
[[ -n $hostname ]] && xfreerdp "${options[@]}" "$hostname" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment