#!/usr/bin/env bash # rdp --- Remote Desktop Protocol client wrapper # Author: Noah Friedman # Created: 2005-08-10 # Public domain # $Id: rdp,v 1.15 2019/01/26 02:38:07 friedman Exp $ # Commentary: # The arg "-fs" will create a full-screen client. # When a client connects to a windows 2000/2003 terminal server and has no # permanent client access license associated with it, the server will issue # a temporary license. This license will eventually expire and the client # will no longer be able to connect. This script adds a "generation # number" to the client name (normally the host name) periodically to avoid # using an expired temporary license. The generation number is determined # from the current date and time. # # This cruft does not seem to be necessary for ordinary remote desktop. # Code: apush() { eval "$1=(\"\${$1[@]}\" \"\${@:2}\")"; } # append aunshift() { eval "$1=(\"\${@:2}\" \"\${$1[@]}\")"; } # prepend setup() { hostname=${HOSTNAME-`uname -n`} host=${hostname%%.*} sec_per_day=86400 days_per_license=60 # might be 90? play it safe epoch=1117584000 # 2005-06-01 00:00:00 UTC now=`date -u +%s` gen=$(( (now - epoch) / (sec_per_day * (days_per_license - 1)) )) client=$host'$'$gen'$' #declare -A xrdba #eval xrdb=\( `xrdb -symbols | # sed -e 's/^-D//' \ # -e '/=/!s/$/=/' \ # -e 's/^\([^=]*\)=/[\1]=/'` \) # #depth=${xrdb[PLANES]} #case $depth in 24 ) depth=32 ;; esac depth=32 } run_rdesktop() { declare -a args=( #-n ${RDP_CLIENT-$client} #-u ${RDP_USER-${LOGNAME-$USER}} #-a ${RDP_DEPTH-$depth} -K -P -z ) case $1 in -fs ) shift; apush args -f -T notitle ;; esac ${RDP_PROG-rdesktop} "${args[@]}" "$@" & } run_xfreerdp() { declare -a args=( #/client-hostname:${RDP_CLIENT-$client} #/bpp:${RDP_DEPTH-$depth} #/u:${RDP_USER-${LOGNAME-$USER}} /dynamic-resolution /geometry /disp /echo /compression-level:1 /clipboard -grab-keyboard #/sound:sys:pulse +fonts +auto-reconnect #+print-reconnect-cookie #-toggle-fullscreen +multitransport -sec-nla /cert-ignore /log-level:ERROR ) case $1 in -fs ) shift; apush args /f -decorations ;; #* ) apush args size=/size:${RDP_GEOM-$geom} ;; esac aunshift args /v:$1 # rhost shift ${RDP_PROG-xfreerdp} "${args[@]}" "$@" & } main() { setup "$@" case ${RDP_PROG-freerdp} in *rdesktop* ) run_rdesktop "$@" ;; *freerdp* ) run_xfreerdp "$@" ;; esac } main "$@" # eof