Last active
August 22, 2019 18:02
-
-
Save tchamberlin/ed67f70ec5837b36a8ac2b025cad6700 to your computer and use it in GitHub Desktop.
Convenience function for using RDP transparently across RHEL versions
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 | |
# Returns current screen size in format 'XxY'. Assumes all monitors are same resolution, if >1 | |
function getres() { | |
xrandr --current | grep '\*' | uniq | awk '{print $1}' | |
} | |
# Returns the RHEL major version of the current host (e.g. '6' or '7') | |
function get_rhel_version() { | |
lsb_release -i -r | grep Release | awk '{print $2}' | awk -F . '{print $1}' | |
} | |
# Shortcut to open up an rdesktop session | |
function rdesk() { | |
local host | |
if [ -n "$1" ]; then | |
host="$1" | |
shift | |
else | |
host="gbtsb" | |
fi | |
local x | |
local x_scaled | |
local x_scale_factor | |
x_scale_factor="1" | |
y_scale_factor=".95" | |
x=$(getres | cut -d 'x' -f1) | |
x_scaled=$(python -c "print(int(${x} * $x_scale_factor))") | |
local y | |
local y_scaled | |
y=$(getres | cut -d 'x' -f2) | |
y_scaled=$(python -c "print(int(${y} * $y_scale_factor))") | |
echo "Connecting to $host as $USER, scaled to: ${x_scaled}x${y_scaled} from current (single-monitor) resolution of: ${x}x${y}" | |
if [ "$(get_rhel_version)" == "6" ]; then | |
echo rdesktop -u "AD\\${USER}" -p - -g "${x_scaled}x${y_scaled}" "$host" "$@" | |
rdesktop -u "AD\\${USER}" -p - -g "${x_scaled}x${y_scaled}" "$host" "$@" | |
else | |
echo xfreerdp "/size:${x_scaled}x${y_scaled}" /bpp:16 /d:"AD" /v:"$host" /u:"$USER" "$@" | |
xfreerdp "/size:${x_scaled}x${y_scaled}" /bpp:16 /d:"AD" /v:"$host" /u:"$USER" "$@" | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage is pretty simply. Put the above in your
.bash_profile
, and:$ rdesk
Or, for a specific host:
$ rdesk foohost