Merge pull request #144 from KernelGhost/main

Fixed #141, #143 and #145
This commit is contained in:
Oskar Manhart 2024-07-17 19:49:52 +02:00 committed by GitHub
commit 3a46548224
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 230 additions and 49 deletions

View File

@ -121,6 +121,7 @@ RDP_USER="MyWindowsUser"
RDP_PASS="MyWindowsPassword" RDP_PASS="MyWindowsPassword"
#RDP_DOMAIN="MYDOMAIN" #RDP_DOMAIN="MYDOMAIN"
#RDP_IP="192.168.123.111" #RDP_IP="192.168.123.111"
#WAFLAVOR="docker"
#RDP_SCALE=100 #RDP_SCALE=100
#RDP_FLAGS="" #RDP_FLAGS=""
#MULTIMON="true" #MULTIMON="true"
@ -128,7 +129,11 @@ RDP_PASS="MyWindowsPassword"
#FREERDP_COMMAND="xfreerdp" #FREERDP_COMMAND="xfreerdp"
``` ```
`RDP_USER` and `RDP_PASS` must correspond to a complete Windows user account and password, such as those created during Windows setup or for a domain user. User/PIN combinations are not valid for RDP access. > [!NOTE]
> `RDP_USER` and `RDP_PASS` must correspond to a complete Windows user account and password, such as those created during Windows setup or for a domain user. User/PIN combinations are not valid for RDP access.
> [!NOTE]
> If you wish to use the older (deprecated) `virt-manager` method, uncomment and change `WAFLAVOR="docker"` to `WAFLAVOR="libvirt"`.
#### Configuration Options Explained #### Configuration Options Explained
- When using a pre-existing non-KVM RDP server, you must use `RDP_IP` to specify the location of the Windows server. - When using a pre-existing non-KVM RDP server, you must use `RDP_IP` to specify the location of the Windows server.

View File

@ -13,6 +13,7 @@ readonly EC_VM_NOT_RUNNING=4
readonly EC_VM_NO_IP=5 readonly EC_VM_NO_IP=5
readonly EC_VM_BAD_PORT=6 readonly EC_VM_BAD_PORT=6
readonly EC_UNSUPPORTED_APP=7 readonly EC_UNSUPPORTED_APP=7
readonly EC_INVALID_FLAVOR=8
# PATHS # PATHS
readonly APPDATA_PATH="${HOME}/.local/share/winapps" readonly APPDATA_PATH="${HOME}/.local/share/winapps"
@ -26,6 +27,7 @@ readonly SCRIPT_DIR_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && p
# OTHER # OTHER
readonly VM_NAME="RDPWindows" readonly VM_NAME="RDPWindows"
readonly RDP_PORT=3389 readonly RDP_PORT=3389
readonly DOCKER_IP="127.0.0.1"
# shellcheck disable=SC2155 # Silence warnings regarding masking return values through simultaneous declaration and assignment. # shellcheck disable=SC2155 # Silence warnings regarding masking return values through simultaneous declaration and assignment.
readonly RUN="$(date)-${RANDOM}" readonly RUN="$(date)-${RANDOM}"
@ -35,6 +37,7 @@ RDP_USER=""
RDP_PASS="" RDP_PASS=""
RDP_DOMAIN="" RDP_DOMAIN=""
RDP_IP="" RDP_IP=""
WAFLAVOR="docker"
RDP_FLAGS="" RDP_FLAGS=""
FREERDP_COMMAND="" FREERDP_COMMAND=""
RDP_SCALE=100 RDP_SCALE=100
@ -71,23 +74,28 @@ function waThrowExit() {
"$EC_VM_NOT_RUNNING") "$EC_VM_NOT_RUNNING")
dprint "ERROR: VM NOT RUNNING. EXITING." dprint "ERROR: VM NOT RUNNING. EXITING."
echo -e "${ERROR_TEXT}ERROR: VM NOT RUNNING.${CLEAR_TEXT}" echo -e "${ERROR_TEXT}ERROR: VM NOT RUNNING.${CLEAR_TEXT}"
echo "Please ensure the Windows VM is powered on." echo "Please ensure the Windows container/virtual machine is running."
;; ;;
"$EC_VM_NO_IP") "$EC_VM_NO_IP")
dprint "ERROR: VM UNREACHABLE. EXITING." dprint "ERROR: VM UNREACHABLE. EXITING."
echo -e "${ERROR_TEXT}ERROR: VM UNREACHABLE.${CLEAR_TEXT}" echo -e "${ERROR_TEXT}ERROR: VM UNREACHABLE.${CLEAR_TEXT}"
echo "Please ensure the Windows VM is assigned an IP address." echo "Please ensure the Windows virtual machine is assigned an IP address."
;; ;;
"$EC_VM_BAD_PORT") "$EC_VM_BAD_PORT")
dprint "ERROR: RDP PORT CLOSED. EXITING." dprint "ERROR: RDP PORT CLOSED. EXITING."
echo -e "${ERROR_TEXT}ERROR: RDP PORT CLOSED.${CLEAR_TEXT}" echo -e "${ERROR_TEXT}ERROR: RDP PORT CLOSED.${CLEAR_TEXT}"
echo "Please ensure Remote Desktop is correctly configured on the Windows VM." echo "Please ensure Remote Desktop is correctly configured on the Windows virtual machine."
;; ;;
"$EC_UNSUPPORTED_APP") "$EC_UNSUPPORTED_APP")
dprint "ERROR: APPLICATION NOT FOUND. EXITING." dprint "ERROR: APPLICATION NOT FOUND. EXITING."
echo -e "${ERROR_TEXT}ERROR: APPLICATION NOT FOUND.${CLEAR_TEXT}" echo -e "${ERROR_TEXT}ERROR: APPLICATION NOT FOUND.${CLEAR_TEXT}"
echo "Please ensure the program is correctly configured as an officially supported application." echo "Please ensure the program is correctly configured as an officially supported application."
;; ;;
"$EC_INVALID_FLAVOR")
dprint "ERROR: INVALID FLAVOR. EXITING."
echo -e "${ERROR_TEXT}ERROR: INVALID FLAVOR.${CLEAR_TEXT}"
echo "Please ensure either 'docker' or 'libvirt' are specified as the flavor in the WinApps configuration file."
;;
esac esac
# Provide generic advice. # Provide generic advice.
@ -104,6 +112,34 @@ function dprint() {
[ "$DEBUG" = "true" ] && echo "[$RUN] $1" >>"$LOG_PATH" [ "$DEBUG" = "true" ] && echo "[$RUN] $1" >>"$LOG_PATH"
} }
# Name: 'waFixScale'
# Role: Since FreeRDP only supports '/scale' values of 100, 140 or 180, find the closest supported argument to the user's configuration.
function waFixScale() {
# Define variables.
local USER_CONFIG_SCALE="$1"
local CLOSEST_SCALE=100
local VALID_SCALE_1=100
local VALID_SCALE_2=140
local VALID_SCALE_3=180
# Calculate the absolute differences.
local DIFF_1=$(( USER_CONFIG_SCALE > VALID_SCALE_1 ? USER_CONFIG_SCALE - VALID_SCALE_1 : VALID_SCALE_1 - USER_CONFIG_SCALE ))
local DIFF_2=$(( USER_CONFIG_SCALE > VALID_SCALE_2 ? USER_CONFIG_SCALE - VALID_SCALE_2 : VALID_SCALE_2 - USER_CONFIG_SCALE ))
local DIFF_3=$(( USER_CONFIG_SCALE > VALID_SCALE_3 ? USER_CONFIG_SCALE - VALID_SCALE_3 : VALID_SCALE_3 - USER_CONFIG_SCALE ))
# Set the final scale to the valid scale value with the smallest absolute difference.
if (( DIFF_1 <= DIFF_2 && DIFF_1 <= DIFF_3 )); then
CLOSEST_SCALE="$VALID_SCALE_1"
elif (( DIFF_2 <= DIFF_1 && DIFF_2 <= DIFF_3 )); then
CLOSEST_SCALE="$VALID_SCALE_2"
else
CLOSEST_SCALE="$VALID_SCALE_3"
fi
# Return the final scale value.
echo "$CLOSEST_SCALE"
}
# Name: 'waLoadConfig' # Name: 'waLoadConfig'
# Role: Load the variables within the WinApps configuration file. # Role: Load the variables within the WinApps configuration file.
function waLoadConfig() { function waLoadConfig() {
@ -118,6 +154,9 @@ function waLoadConfig() {
# Update 'MULTI_FLAG' based on 'MULTIMON'. # Update 'MULTI_FLAG' based on 'MULTIMON'.
MULTI_FLAG=$([[ $MULTIMON == "true" ]] && echo "/multimon" || echo "+span") MULTI_FLAG=$([[ $MULTIMON == "true" ]] && echo "/multimon" || echo "+span")
# Update $RDP_SCALE.
RDP_SCALE=$(waFixScale "$RDP_SCALE")
# Append additional flags or parameters to FreeRDP. # Append additional flags or parameters to FreeRDP.
[[ -n $RDP_FLAGS ]] && FREERDP_COMMAND="${FREERDP_COMMAND} ${RDP_FLAGS}" [[ -n $RDP_FLAGS ]] && FREERDP_COMMAND="${FREERDP_COMMAND} ${RDP_FLAGS}"
} }
@ -141,20 +180,25 @@ function waLastRun() {
dprint "THIS_RUN: ${CURR_RUN_UNIX_TIME}" dprint "THIS_RUN: ${CURR_RUN_UNIX_TIME}"
} }
# Name: 'waGetFreeRDPCommand'
# Role: Determine the correct FreeRDP command to use.
function waGetFreeRDPCommand() { function waGetFreeRDPCommand() {
# Declare variables.
local FREERDP_MAJOR_VERSION="" # Stores the major version of the installed copy of FreeRDP.
# Attempt to set a FreeRDP command if the command variable is empty. # Attempt to set a FreeRDP command if the command variable is empty.
if [ -z "$FREERDP_COMMAND" ]; then if [ -z "$FREERDP_COMMAND" ]; then
# Check for 'xfreerdp'. # Check for 'xfreerdp'.
if command -v xfreerdp &>/dev/null; then if command -v xfreerdp &>/dev/null; then
# Check FreeRDP major version is 3 or greater. # Check FreeRDP major version is 3 or greater.
FREERDP_MAJOR_VERSION=$(xfreerdp --version | head -n 1 | grep -o -m 1 '\b[0-9]\S*' | cut -d'.' -f1) FREERDP_MAJOR_VERSION=$(xfreerdp --version | head -n 1 | grep -o -m 1 '\b[0-9]\S*' | head -n 1 | cut -d'.' -f1)
if [[ $FREERDP_MAJOR_VERSION =~ ^[0-9]+$ ]] && ((FREERDP_MAJOR_VERSION >= 3)); then if [[ $FREERDP_MAJOR_VERSION =~ ^[0-9]+$ ]] && ((FREERDP_MAJOR_VERSION >= 3)); then
FREERDP_COMMAND="xfreerdp" FREERDP_COMMAND="xfreerdp"
fi fi
# Check for 'xfreerdp3'. # Check for 'xfreerdp3'.
elif command -v xfreerdp3 &>/dev/null; then elif command -v xfreerdp3 &>/dev/null; then
# Check FreeRDP major version is 3 or greater. # Check FreeRDP major version is 3 or greater.
FREERDP_MAJOR_VERSION=$(xfreerdp3 --version | head -n 1 | grep -o -m 1 '\b[0-9]\S*' | cut -d'.' -f1) FREERDP_MAJOR_VERSION=$(xfreerdp3 --version | head -n 1 | grep -o -m 1 '\b[0-9]\S*' | head -n 1 | cut -d'.' -f1)
if [[ $FREERDP_MAJOR_VERSION =~ ^[0-9]+$ ]] && ((FREERDP_MAJOR_VERSION >= 3)); then if [[ $FREERDP_MAJOR_VERSION =~ ^[0-9]+$ ]] && ((FREERDP_MAJOR_VERSION >= 3)); then
FREERDP_COMMAND="xfreerdp3" FREERDP_COMMAND="xfreerdp3"
fi fi
@ -199,6 +243,21 @@ function waCheckVMRunning() {
! virsh list --state-running --name | grep -q "^${VM_NAME}$" && waThrowExit "$EC_VM_NOT_RUNNING" ! virsh list --state-running --name | grep -q "^${VM_NAME}$" && waThrowExit "$EC_VM_NOT_RUNNING"
} }
# Name: 'waCheckContainerRunning'
# Role: Throw an error if the Docker container is not running.
function waCheckContainerRunning() {
# Declare variables.
local CONTAINER_STATE=""
# Determine container state.
CONTAINER_STATE=$(docker ps --filter name="windows" --format '{{.Status}}')
CONTAINER_STATE=${CONTAINER_STATE,,} # Convert the string to lowercase.
CONTAINER_STATE=${CONTAINER_STATE%% *} # Extract the first word.
# Check container state.
[[ "$CONTAINER_STATE" != "up" ]] && waThrowExit "$EC_VM_NOT_RUNNING"
}
# Name: 'waCheckVMContactable' # Name: 'waCheckVMContactable'
# Role: Assesses whether the Windows VM can be contacted. # Role: Assesses whether the Windows VM can be contacted.
function waCheckVMContactable() { function waCheckVMContactable() {
@ -216,6 +275,8 @@ function waCheckVMContactable() {
timeout 5 nc -z "$RDP_IP" "$RDP_PORT" &>/dev/null || waThrowExit "$EC_VM_BAD_PORT" timeout 5 nc -z "$RDP_IP" "$RDP_PORT" &>/dev/null || waThrowExit "$EC_VM_BAD_PORT"
} }
# Name: 'waRunCommand'
# Role: Run the requested WinApps command.
function waRunCommand() { function waRunCommand() {
# Declare variables. # Declare variables.
local ICON="" local ICON=""
@ -322,8 +383,18 @@ mkdir -p "$APPDATA_PATH"
waLastRun waLastRun
waLoadConfig waLoadConfig
waGetFreeRDPCommand waGetFreeRDPCommand
waCheckGroupMembership
waCheckVMRunning if [ "$WAFLAVOR" = "docker" ]; then
waCheckVMContactable RDP_IP="$DOCKER_IP"
waCheckContainerRunning
elif [ "$WAFLAVOR" = "libvirt" ]; then
waCheckGroupMembership
waCheckVMRunning
waCheckVMContactable
else
waThrowExit "$EC_INVALID_FLAVOR"
fi
waRunCommand "$@" waRunCommand "$@"
dprint "END" dprint "END"

View File

@ -24,10 +24,11 @@ readonly EC_NOT_IN_GROUP="7" # Current user not in group 'libvirt' and/or 'k
readonly EC_VM_OFF="8" # Windows VM powered off. readonly EC_VM_OFF="8" # Windows VM powered off.
readonly EC_VM_PAUSED="9" # Windows VM paused. readonly EC_VM_PAUSED="9" # Windows VM paused.
readonly EC_VM_ABSENT="10" # Windows VM does not exist. readonly EC_VM_ABSENT="10" # Windows VM does not exist.
readonly EC_VM_NO_IP="11" # Windows VM does not have an IP address. readonly EC_CONTAINER_OFF="11" # Docker container is not running.
readonly EC_VM_BAD_PORT="12" # Windows VM is unreachable via RDP_PORT. readonly EC_VM_NO_IP="12" # Windows VM does not have an IP address.
readonly EC_RDP_FAIL="13" # FreeRDP failed to establish a connection with the Windows VM. readonly EC_VM_BAD_PORT="13" # Windows VM is unreachable via RDP_PORT.
readonly EC_APPQUERY_FAIL="14" # Failed to query the Windows VM for installed applications. readonly EC_RDP_FAIL="14" # FreeRDP failed to establish a connection with the Windows VM.
readonly EC_APPQUERY_FAIL="15" # Failed to query the Windows VM for installed applications.
# PATHS # PATHS
# 'BIN' # 'BIN'
@ -66,12 +67,14 @@ readonly CONFIG_PATH="${HOME}/.config/winapps/winapps.conf" # UNIX path to the W
readonly INQUIRER_PATH="./install/inquirer.sh" # UNIX path to the 'inquirer' script, which is used to produce selection menus. readonly INQUIRER_PATH="./install/inquirer.sh" # UNIX path to the 'inquirer' script, which is used to produce selection menus.
# REMOTE DESKTOP CONFIGURATION # REMOTE DESKTOP CONFIGURATION
readonly VM_NAME="RDPWindows" # Name of the Windows VM. readonly VM_NAME="RDPWindows" # Name of the Windows VM.
readonly RDP_PORT=3389 # Port used for RDP on the Windows VM. readonly RDP_PORT=3389 # Port used for RDP on the Windows VM.
readonly DOCKER_IP="127.0.0.1" # Localhost.
readonly WINAPPS_CONFIG='RDP_USER="MyWindowsUser" readonly WINAPPS_CONFIG='RDP_USER="MyWindowsUser"
RDP_PASS="MyWindowsPassword" RDP_PASS="MyWindowsPassword"
#RDP_DOMAIN="MYDOMAIN" #RDP_DOMAIN="MYDOMAIN"
#RDP_IP="192.168.123.111" #RDP_IP="192.168.123.111"
#WAFLAVOR="docker"
#RDP_SCALE=100 #RDP_SCALE=100
#RDP_FLAGS="" #RDP_FLAGS=""
#MULTIMON="true" #MULTIMON="true"
@ -90,6 +93,7 @@ RDP_USER="" # Imported variable.
RDP_PASS="" # Imported variable. RDP_PASS="" # Imported variable.
RDP_DOMAIN="" # Imported variable. RDP_DOMAIN="" # Imported variable.
RDP_IP="" # Imported variable. RDP_IP="" # Imported variable.
WAFLAVOR="docker" # Imported variable.
RDP_SCALE=100 # Imported variable. RDP_SCALE=100 # Imported variable.
RDP_FLAGS="" # Imported variable. RDP_FLAGS="" # Imported variable.
MULTIMON="false" # Imported variable. MULTIMON="false" # Imported variable.
@ -384,6 +388,34 @@ function waCheckExistingInstall() {
echo -e "${DONE_TEXT}Done!${CLEAR_TEXT}" echo -e "${DONE_TEXT}Done!${CLEAR_TEXT}"
} }
# Name: 'waFixScale'
# Role: Since FreeRDP only supports '/scale' values of 100, 140 or 180, find the closest supported argument to the user's configuration.
function waFixScale() {
# Define variables.
local USER_CONFIG_SCALE="$1"
local CLOSEST_SCALE=100
local VALID_SCALE_1=100
local VALID_SCALE_2=140
local VALID_SCALE_3=180
# Calculate the absolute differences.
local DIFF_1=$(( USER_CONFIG_SCALE > VALID_SCALE_1 ? USER_CONFIG_SCALE - VALID_SCALE_1 : VALID_SCALE_1 - USER_CONFIG_SCALE ))
local DIFF_2=$(( USER_CONFIG_SCALE > VALID_SCALE_2 ? USER_CONFIG_SCALE - VALID_SCALE_2 : VALID_SCALE_2 - USER_CONFIG_SCALE ))
local DIFF_3=$(( USER_CONFIG_SCALE > VALID_SCALE_3 ? USER_CONFIG_SCALE - VALID_SCALE_3 : VALID_SCALE_3 - USER_CONFIG_SCALE ))
# Set the final scale to the valid scale value with the smallest absolute difference.
if (( DIFF_1 <= DIFF_2 && DIFF_1 <= DIFF_3 )); then
CLOSEST_SCALE="$VALID_SCALE_1"
elif (( DIFF_2 <= DIFF_1 && DIFF_2 <= DIFF_3 )); then
CLOSEST_SCALE="$VALID_SCALE_2"
else
CLOSEST_SCALE="$VALID_SCALE_3"
fi
# Return the final scale value.
echo "$CLOSEST_SCALE"
}
# Name: 'waLoadConfig' # Name: 'waLoadConfig'
# Role: Loads settings specified within the WinApps configuration file. # Role: Loads settings specified within the WinApps configuration file.
function waLoadConfig() { function waLoadConfig() {
@ -463,13 +495,13 @@ function waCheckDependencies() {
# Check common commands used to launch FreeRDP. # Check common commands used to launch FreeRDP.
if command -v xfreerdp &>/dev/null; then if command -v xfreerdp &>/dev/null; then
# Check FreeRDP major version is 3 or greater. # Check FreeRDP major version is 3 or greater.
FREERDP_MAJOR_VERSION=$(xfreerdp --version | head -n 1 | grep -o -m 1 '\b[0-9]\S*' | cut -d'.' -f1) FREERDP_MAJOR_VERSION=$(xfreerdp --version | head -n 1 | grep -o -m 1 '\b[0-9]\S*' | head -n 1 | cut -d'.' -f1)
if [[ $FREERDP_MAJOR_VERSION =~ ^[0-9]+$ ]] && ((FREERDP_MAJOR_VERSION >= 3)); then if [[ $FREERDP_MAJOR_VERSION =~ ^[0-9]+$ ]] && ((FREERDP_MAJOR_VERSION >= 3)); then
FREERDP_COMMAND="xfreerdp" FREERDP_COMMAND="xfreerdp"
fi fi
elif command -v xfreerdp3 &>/dev/null; then elif command -v xfreerdp3 &>/dev/null; then
# Check FreeRDP major version is 3 or greater. # Check FreeRDP major version is 3 or greater.
FREERDP_MAJOR_VERSION=$(xfreerdp3 --version | head -n 1 | grep -o -m 1 '\b[0-9]\S*' | cut -d'.' -f1) FREERDP_MAJOR_VERSION=$(xfreerdp3 --version | head -n 1 | grep -o -m 1 '\b[0-9]\S*' | head -n 1 | cut -d'.' -f1)
if [[ $FREERDP_MAJOR_VERSION =~ ^[0-9]+$ ]] && ((FREERDP_MAJOR_VERSION >= 3)); then if [[ $FREERDP_MAJOR_VERSION =~ ^[0-9]+$ ]] && ((FREERDP_MAJOR_VERSION >= 3)); then
FREERDP_COMMAND="xfreerdp3" FREERDP_COMMAND="xfreerdp3"
fi fi
@ -521,30 +553,51 @@ function waCheckDependencies() {
fi fi
# 'libvirt' / 'virt-manager'. # 'libvirt' / 'virt-manager'.
if ! command -v virsh &>/dev/null; then if [ "$WAFLAVOR" = "libvirt" ]; then
# Complete the previous line. if ! command -v virsh &>/dev/null; then
echo -e "${FAIL_TEXT}Failed!${CLEAR_TEXT}\n" # Complete the previous line.
echo -e "${FAIL_TEXT}Failed!${CLEAR_TEXT}\n"
# Display the error type. # Display the error type.
echo -e "${ERROR_TEXT}ERROR:${CLEAR_TEXT} ${BOLD_TEXT}MISSING DEPENDENCIES.${CLEAR_TEXT}" echo -e "${ERROR_TEXT}ERROR:${CLEAR_TEXT} ${BOLD_TEXT}MISSING DEPENDENCIES.${CLEAR_TEXT}"
# Display the error details. # Display the error details.
echo -e "${INFO_TEXT}Please install 'Virtual Machine Manager' to proceed.${CLEAR_TEXT}" echo -e "${INFO_TEXT}Please install 'Virtual Machine Manager' to proceed.${CLEAR_TEXT}"
# Display the suggested action(s). # Display the suggested action(s).
echo "--------------------------------------------------------------------------------" echo "--------------------------------------------------------------------------------"
echo "Debian/Ubuntu-based systems:" echo "Debian/Ubuntu-based systems:"
echo -e " ${COMMAND_TEXT}sudo apt install virt-manager${CLEAR_TEXT}" echo -e " ${COMMAND_TEXT}sudo apt install virt-manager${CLEAR_TEXT}"
echo "Red Hat/Fedora-based systems:" echo "Red Hat/Fedora-based systems:"
echo -e " ${COMMAND_TEXT}sudo dnf install virt-manager${CLEAR_TEXT}" echo -e " ${COMMAND_TEXT}sudo dnf install virt-manager${CLEAR_TEXT}"
echo "Arch Linux systems:" echo "Arch Linux systems:"
echo -e " ${COMMAND_TEXT}sudo pacman -S virt-manager${CLEAR_TEXT}" echo -e " ${COMMAND_TEXT}sudo pacman -S virt-manager${CLEAR_TEXT}"
echo "Gentoo Linux systems:" echo "Gentoo Linux systems:"
echo -e " ${COMMAND_TEXT}sudo emerge --ask app-emulation/virt-manager${CLEAR_TEXT}" echo -e " ${COMMAND_TEXT}sudo emerge --ask app-emulation/virt-manager${CLEAR_TEXT}"
echo "--------------------------------------------------------------------------------" echo "--------------------------------------------------------------------------------"
# Terminate the script. # Terminate the script.
return "$EC_MISSING_DEPS" return "$EC_MISSING_DEPS"
fi
elif [ "$WAFLAVOR" = "docker" ]; then
if ! command -v docker &>/dev/null; then
# Complete the previous line.
echo -e "${FAIL_TEXT}Failed!${CLEAR_TEXT}\n"
# Display the error type.
echo -e "${ERROR_TEXT}ERROR:${CLEAR_TEXT} ${BOLD_TEXT}MISSING DEPENDENCIES.${CLEAR_TEXT}"
# Display the error details.
echo -e "${INFO_TEXT}Please install 'Docker Desktop on Linux' to proceed.${CLEAR_TEXT}"
# Display the suggested action(s).
echo "--------------------------------------------------------------------------------"
echo "Please visit https://docs.docker.com/desktop/install/linux-install/ for more information."
echo "--------------------------------------------------------------------------------"
# Terminate the script.
return "$EC_MISSING_DEPS"
fi
fi fi
# Print feedback. # Print feedback.
@ -659,6 +712,45 @@ function waCheckVMRunning() {
echo -e "${DONE_TEXT}Done!${CLEAR_TEXT}" echo -e "${DONE_TEXT}Done!${CLEAR_TEXT}"
} }
# Name: 'waCheckContainerRunning'
# Role: Throw an error if the Docker container is not running.
function waCheckContainerRunning() {
# Print feedback.
echo -n "Checking the status of the Windows Docker container/virtual machine... "
# Declare variables.
local CONTAINER_STATE=""
# Determine container state.
CONTAINER_STATE=$(docker ps --filter name="windows" --format '{{.Status}}')
CONTAINER_STATE=${CONTAINER_STATE,,} # Convert the string to lowercase.
CONTAINER_STATE=${CONTAINER_STATE%% *} # Extract the first word.
# Check container state.
if [[ "$CONTAINER_STATE" != "up" ]]; then
# Complete the previous line.
echo -e "${FAIL_TEXT}Failed!${CLEAR_TEXT}\n"
# Display the error type.
echo -e "${ERROR_TEXT}ERROR:${CLEAR_TEXT} ${BOLD_TEXT}DOCKER VM NOT RUNNING.${CLEAR_TEXT}"
# Display the error details.
echo -e "${INFO_TEXT}The Windows Docker container/virtual machine is not running.${CLEAR_TEXT}"
# Display the suggested action(s).
echo "--------------------------------------------------------------------------------"
echo "Please ensure the Windows Docker container/virtual machine is powered on:"
echo -e "${COMMAND_TEXT}docker compose start${CLEAR_TEXT}"
echo "--------------------------------------------------------------------------------"
# Terminate the script.
return "$EC_CONTAINER_OFF"
fi
# Print feedback.
echo -e "${DONE_TEXT}Done!${CLEAR_TEXT}"
}
# Name: 'waCheckVMContactable' # Name: 'waCheckVMContactable'
# Role: Assesses whether the Windows VM can be contacted (prior to attempting a remote desktop connection). # Role: Assesses whether the Windows VM can be contacted (prior to attempting a remote desktop connection).
function waCheckVMContactable() { function waCheckVMContactable() {
@ -721,7 +813,7 @@ function waCheckVMContactable() {
# Role: Tests if the Windows VM is accessible via remote desktop. # Role: Tests if the Windows VM is accessible via remote desktop.
function waCheckRDPAccess() { function waCheckRDPAccess() {
# Print feedback. # Print feedback.
echo -n "Establishing a Remote Desktop connection with the Windows VM... " echo -n "Attempting to establish a Remote Desktop connection with the Windows VM... "
# Declare variables. # Declare variables.
local FREERDP_LOG="" # Stores the path of the FreeRDP log file. local FREERDP_LOG="" # Stores the path of the FreeRDP log file.
@ -788,7 +880,7 @@ function waCheckRDPAccess() {
echo -e "${ERROR_TEXT}ERROR:${CLEAR_TEXT} ${BOLD_TEXT}REMOTE DESKTOP PROTOCOL FAILURE.${CLEAR_TEXT}" echo -e "${ERROR_TEXT}ERROR:${CLEAR_TEXT} ${BOLD_TEXT}REMOTE DESKTOP PROTOCOL FAILURE.${CLEAR_TEXT}"
# Display the error details. # Display the error details.
echo -e "${INFO_TEXT}FreeRDP failed to establish a connection with the Windows VM '${VM_NAME}'.${CLEAR_TEXT}" echo -e "${INFO_TEXT}FreeRDP failed to establish a connection with the Windows VM.${CLEAR_TEXT}"
# Display the suggested action(s). # Display the suggested action(s).
echo "--------------------------------------------------------------------------------" echo "--------------------------------------------------------------------------------"
@ -796,10 +888,10 @@ function waCheckRDPAccess() {
echo "Troubleshooting Tips:" echo "Troubleshooting Tips:"
echo " - Ensure the user is logged out of the Windows VM prior to initiating the WinApps installation." echo " - Ensure the user is logged out of the Windows VM prior to initiating the WinApps installation."
echo " - Ensure the credentials within the WinApps configuration file are correct." echo " - Ensure the credentials within the WinApps configuration file are correct."
echo " - Ensure the Windows VM is correctly named as specified within the README."
echo " - Ensure 'Remote Desktop' is enabled within the Windows VM."
echo " - Ensure you have merged 'RDPApps.reg' into the Windows VM's registry."
echo -e " - Utilise a new certificate by removing relevant certificate(s) in ${COMMAND_TEXT}${HOME}/.config/freerdp/server${CLEAR_TEXT}." echo -e " - Utilise a new certificate by removing relevant certificate(s) in ${COMMAND_TEXT}${HOME}/.config/freerdp/server${CLEAR_TEXT}."
echo " - If using 'libvirt', ensure the Windows VM is correctly named as specified within the README."
echo " - If using 'libvirt', ensure 'Remote Desktop' is enabled within the Windows VM."
echo " - If using 'libvirt', ensure you have merged 'RDPApps.reg' into the Windows VM's registry."
echo "--------------------------------------------------------------------------------" echo "--------------------------------------------------------------------------------"
# Terminate the script. # Terminate the script.
@ -916,7 +1008,7 @@ function waFindInstalled() {
echo -e "${ERROR_TEXT}ERROR:${CLEAR_TEXT} ${BOLD_TEXT}APPLICATION QUERY FAILURE.${CLEAR_TEXT}" echo -e "${ERROR_TEXT}ERROR:${CLEAR_TEXT} ${BOLD_TEXT}APPLICATION QUERY FAILURE.${CLEAR_TEXT}"
# Display the error details. # Display the error details.
echo -e "${INFO_TEXT}Failed to query Windows VM '${VM_NAME}' for installed applications.${CLEAR_TEXT}" echo -e "${INFO_TEXT}Failed to query Windows VM for installed applications.${CLEAR_TEXT}"
# Display the suggested action(s). # Display the suggested action(s).
echo "--------------------------------------------------------------------------------" echo "--------------------------------------------------------------------------------"
@ -1268,19 +1360,32 @@ function waInstall() {
MULTI_FLAG="+span" MULTI_FLAG="+span"
fi fi
# Update $RDP_SCALE.
RDP_SCALE=$(waFixScale "$RDP_SCALE")
# Append additional FreeRDP flags if required. # Append additional FreeRDP flags if required.
if [[ -n $RDP_FLAGS ]]; then if [[ -n $RDP_FLAGS ]]; then
FREERDP_COMMAND="${FREERDP_COMMAND} ${RDP_FLAGS}" FREERDP_COMMAND="${FREERDP_COMMAND} ${RDP_FLAGS}"
fi fi
# Check the group membership of the current user. if [ "$WAFLAVOR" = "docker" ]; then
waCheckGroupMembership # Set RDP_IP to localhost.
RDP_IP="$DOCKER_IP"
# Check if the Windows VM is powered on. # Check if the Windows Docker container/virtual machine is powered on.
waCheckVMRunning waCheckContainerRunning
elif [ "$WAFLAVOR" = "libvirt" ]; then
# Check the group membership of the current user.
waCheckGroupMembership
# Check if the Windows VM is contactable. # Check if the Windows VM is powered on.
waCheckVMContactable waCheckVMRunning
# Check if the Windows VM is contactable.
waCheckVMContactable
else
waThrowExit "$EC_INVALID_FLAVOR"
fi
# Test RDP access to the Windows VM. # Test RDP access to the Windows VM.
waCheckRDPAccess waCheckRDPAccess