#!/usr/bin/env bash # Install windows in KVM # Use the user "User" # Name the machine "RDPWindows" in "About" # Allow remote desktop # # virsh autostart RDPWindows # For 20.04: # sudo ln -s /etc/apparmor.d/usr.sbin.libvirtd /etc/apparmor.d/disable/ # Windows Registry Editor Version 5.00 # [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Terminal Server\TSAppAllowList] # "fDisabledAllowList"=dword:00000001 # [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa] # "LimitBlankPasswordUse"=dword:00000000 DIR="$(dirname "$(readlink -f "$0")")" if [ -f /tmp/winapps ]; then LAST_RAN=$(stat -t -c %Y /tmp/winapps) touch /tmp/winapps THIS_RUN=$(stat -t -c %Y /tmp/winapps) if (( $THIS_RUN - $LAST_RAN < 2 )); then exit fi else touch /tmp/winapps fi if [ -z "$(which xfreerdp)" ]; then echo "You need xfreerdp!" echo " sudo apt-get install -y freerdp2-x11" exit fi if [ ! -f "${HOME}/.config/winapps/winapps.conf" ] && [ ! -f "${HOME}/.winapps" ]; then echo "You need to create a ~/.config/winapps/winapps.conf configuration. Exiting..." exit fi if [ -f "${HOME}/.config/winapps/winapps.conf" ]; then . "${HOME}/.config/winapps/winapps.conf" else . "${HOME}/.winapps" fi if [ -z "${RDP_IP}" ]; then if [ -z "$(groups |grep libvirt)" ]; then echo "You are not a member of the libvirt group. Run the below then reboot." echo ' sudo usermod -a -G libvirt $(whoami)' echo ' sudo usermod -a -G kvm $(whoami)' exit fi if [ -z "$(virsh list |grep RDPWindows)" ]; then echo "RDPWindows is not running, run:" echo " virsh start RDPWindows" exit fi RDP_IP=$(virsh net-dhcp-leases default |grep RDPWindows |awk '{print $5}') RDP_IP=${RDP_IP%%\/*} fi if [ "${1}" = "windows" ]; then xfreerdp /u:"${RDP_USER}" /p:"${RDP_PASS}" /v:${RDP_IP} /dynamic-resolution +auto-reconnect +home-drive /wm-class:"Microsoft Windows" 1> /dev/null 2>&1 & elif [ "${1}" != "install" ]; then . "${DIR}/../apps/${1}/info" if [ -n "${2}" ]; then FILE=$(echo "${2}" | sed 's|'"${HOME}"'|\\\\tsclient\\home|;s|/|\\|g;s|\\|\\\\|g') xfreerdp /u:"${RDP_USER}" /p:"${RDP_PASS}" /v:${RDP_IP} +auto-reconnect +home-drive -wallpaper /span /wm-class:"${FULL_NAME}" /app:"${WIN_EXECUTABLE}" /app-icon:"${DIR}/../apps/${1}/icon.svg" /app-cmd:"\"${FILE}\"" 1> /dev/null 2>&1 & else xfreerdp /u:"${RDP_USER}" /p:"${RDP_PASS}" /v:${RDP_IP} +auto-reconnect +home-drive -wallpaper /span /wm-class:"${FULL_NAME}" /app:"${WIN_EXECUTABLE}" /app-icon:"${DIR}/../apps/${1}/icon.svg" 1> /dev/null 2>&1 & fi fi