2020-11-07 16:25:05 -05:00
#!/usr/bin/env bash
2024-09-07 18:16:13 +02:00
2024-07-16 23:22:15 +10:00
# shellcheck disable=SC2034 # Silence warnings regarding unused variables globally.
2020-11-07 16:25:05 -05:00
2024-07-14 23:10:10 +10:00
### GLOBAL CONSTANTS ###
# ANSI ESCAPE SEQUENCES
2024-07-15 21:03:11 +00:00
readonly BOLD_TEXT = "\033[1m" # Bold
readonly CLEAR_TEXT = "\033[0m" # Clear
readonly COMMAND_TEXT = "\033[0;37m" # Grey
readonly DONE_TEXT = "\033[0;32m" # Green
readonly ERROR_TEXT = "\033[1;31m" # Bold + Red
readonly EXIT_TEXT = "\033[1;41;37m" # Bold + White + Red Background
readonly FAIL_TEXT = "\033[0;91m" # Bright Red
readonly INFO_TEXT = "\033[0;33m" # Orange/Yellow
readonly SUCCESS_TEXT = "\033[1;42;37m" # Bold + White + Green Background
2024-07-18 07:19:18 +10:00
readonly WARNING_TEXT = "\033[1;33m" # Bold + Orange/Yellow
2024-04-20 22:26:22 +02:00
2024-07-14 23:10:10 +10:00
# ERROR CODES
2024-07-15 21:03:11 +00:00
readonly EC_FAILED_CD = "1" # Failed to change directory to location of script.
readonly EC_BAD_ARGUMENT = "2" # Unsupported argument passed to script.
readonly EC_EXISTING_INSTALL = "3" # Existing conflicting WinApps installation.
readonly EC_NO_CONFIG = "4" # Absence of a valid WinApps configuration file.
readonly EC_MISSING_DEPS = "5" # Missing dependencies.
2025-07-31 12:19:56 +10:00
readonly EC_NO_SUDO = "6" # Insufficient privileges to invoke superuser access.
2024-07-15 21:03:11 +00:00
readonly EC_NOT_IN_GROUP = "7" # Current user not in group 'libvirt' and/or 'kvm'.
2024-07-18 18:27:07 +10:00
readonly EC_VM_OFF = "8" # Windows 'libvirt' VM powered off.
readonly EC_VM_PAUSED = "9" # Windows 'libvirt' VM paused.
readonly EC_VM_ABSENT = "10" # Windows 'libvirt' VM does not exist.
readonly EC_CONTAINER_OFF = "11" # Windows Docker container is not running.
readonly EC_NO_IP = "12" # Windows does not have an IP address.
readonly EC_BAD_PORT = "13" # Windows is unreachable via RDP_PORT.
readonly EC_RDP_FAIL = "14" # FreeRDP failed to establish a connection with Windows.
readonly EC_APPQUERY_FAIL = "15" # Failed to query Windows for installed applications.
2024-07-19 13:13:02 +10:00
readonly EC_INVALID_FLAVOR = "16" # Backend specified is not 'libvirt', 'docker' or 'podman'.
2026-10-27 10:16:40 -04:00
readonly EC_INVALID_SCALE = "17" # A display scale setting is invalid.
2020-11-07 16:25:05 -05:00
2024-07-14 23:10:10 +10:00
# PATHS
# 'BIN'
2024-07-15 21:03:11 +00:00
readonly SYS_BIN_PATH = "/usr/local/bin" # UNIX path to 'bin' directory for a '--system' WinApps installation.
readonly USER_BIN_PATH = " ${ HOME } /.local/bin" # UNIX path to 'bin' directory for a '--user' WinApps installation.
readonly USER_BIN_PATH_WIN = '\\tsclient\home\.local\bin' # WINDOWS path to 'bin' directory for a '--user' WinApps installation.
2024-08-28 16:03:17 +02:00
# 'SOURCE'
2024-09-08 11:27:56 +02:00
readonly SYS_SOURCE_PATH = " ${ SYS_BIN_PATH } /winapps-src" # UNIX path to WinApps source directory for a '--system' WinApps installation.
2025-07-31 12:57:47 +10:00
readonly USER_SOURCE_PATH = " ${ USER_BIN_PATH } /winapps-src" # UNIX path to WinApps source directory for a '--user' WinApps installation.
2024-07-14 23:10:10 +10:00
# 'APP'
2024-07-15 21:03:11 +00:00
readonly SYS_APP_PATH = "/usr/share/applications" # UNIX path to 'applications' directory for a '--system' WinApps installation.
readonly USER_APP_PATH = " ${ HOME } /.local/share/applications" # UNIX path to 'applications' directory for a '--user' WinApps installation.
2024-08-01 21:17:51 +10:00
readonly USER_APP_PATH_WIN = '\\tsclient\home\.local\share\applications' # WINDOWS path to 'applications' directory for a '--user' WinApps installation.
2024-07-14 23:10:10 +10:00
# 'APPDATA'
2024-07-15 21:03:11 +00:00
readonly SYS_APPDATA_PATH = "/usr/local/share/winapps" # UNIX path to 'application data' directory for a '--system' WinApps installation.
readonly USER_APPDATA_PATH = " ${ HOME } /.local/share/winapps" # UNIX path to 'application data' directory for a '--user' WinApps installation.
readonly USER_APPDATA_PATH_WIN = '\\tsclient\home\.local\share\winapps' # WINDOWS path to 'application data' directory for a '--user' WinApps installation.
2024-07-14 23:10:10 +10:00
# 'Installed Batch Script'
2024-07-18 18:27:07 +10:00
readonly BATCH_SCRIPT_PATH = " ${ USER_APPDATA_PATH } /installed.bat" # UNIX path to a batch script used to search Windows for applications.
readonly BATCH_SCRIPT_PATH_WIN = " ${ USER_APPDATA_PATH_WIN } \\installed.bat" # WINDOWS path to a batch script used to search Windows for applications.
2024-07-14 23:10:10 +10:00
# 'Installed File'
2024-07-15 21:03:11 +00:00
readonly TMP_INST_FILE_PATH = " ${ USER_APPDATA_PATH } /installed.tmp" # UNIX path to a temporary file containing the names of detected officially supported applications.
readonly TMP_INST_FILE_PATH_WIN = " ${ USER_APPDATA_PATH_WIN } \\installed.tmp" # WINDOWS path to a temporary file containing the names of detected officially supported applications.
readonly INST_FILE_PATH = " ${ USER_APPDATA_PATH } /installed" # UNIX path to a file containing the names of detected officially supported applications.
readonly INST_FILE_PATH_WIN = " ${ USER_APPDATA_PATH_WIN } \\installed" # WINDOWS path to a file containing the names of detected officially supported applications.
2024-07-14 23:10:10 +10:00
# 'PowerShell Script'
2024-07-15 21:03:11 +00:00
readonly PS_SCRIPT_PATH = "./install/ExtractPrograms.ps1" # UNIX path to a PowerShell script used to store the names, executable paths and icons (base64) of detected applications.
2024-07-18 18:27:07 +10:00
readonly PS_SCRIPT_HOME_PATH = " ${ USER_APPDATA_PATH } /ExtractPrograms.ps1" # UNIX path to a copy of the PowerShell script within the user's home directory to enable access by Windows.
readonly PS_SCRIPT_HOME_PATH_WIN = " ${ USER_APPDATA_PATH_WIN } \\ExtractPrograms.ps1" # WINDOWS path to a copy of the PowerShell script within the user's home directory to enable access by Windows.
2024-07-14 23:10:10 +10:00
# 'Detected File'
2024-07-15 21:03:11 +00:00
readonly DETECTED_FILE_PATH = " ${ USER_APPDATA_PATH } /detected" # UNIX path to a file containing the output generated by the PowerShell script, formatted to define bash arrays.
readonly DETECTED_FILE_PATH_WIN = " ${ USER_APPDATA_PATH_WIN } \\detected" # WINDOWS path to a file containing the output generated by the PowerShell script, formatted to define bash arrays.
2024-07-14 23:10:10 +10:00
# 'FreeRDP Connection Test File'
2024-07-15 21:03:11 +00:00
readonly TEST_PATH = " ${ USER_APPDATA_PATH } /FreeRDP_Connection_Test" # UNIX path to temporary file whose existence is used to confirm a successful RDP connection was established.
readonly TEST_PATH_WIN = " ${ USER_APPDATA_PATH_WIN } \\FreeRDP_Connection_Test" # WINDOWS path to temporary file whose existence is used to confirm a successful RDP connection was established.
2024-07-14 23:10:10 +10:00
# 'WinApps Configuration File'
2024-07-15 21:03:11 +00:00
readonly CONFIG_PATH = " ${ HOME } /.config/winapps/winapps.conf" # UNIX path to the WinApps configuration file.
2024-07-14 23:10:10 +10:00
# 'Inquirer Bash Script'
2024-07-15 21:03:11 +00:00
readonly INQUIRER_PATH = "./install/inquirer.sh" # UNIX path to the 'inquirer' script, which is used to produce selection menus.
2020-11-19 23:05:07 -05:00
2024-07-14 23:10:10 +10:00
# REMOTE DESKTOP CONFIGURATION
2026-05-10 15:59:53 +09:00
RDP_PORT = 3389 # Port used for RDP on Windows.
2024-07-17 18:51:22 +10:00
readonly DOCKER_IP = "127.0.0.1" # Localhost.
2020-11-19 08:17:44 -05:00
2024-07-14 23:10:10 +10:00
### GLOBAL VARIABLES ###
# USER INPUT
2024-07-15 21:03:11 +00:00
OPT_SYSTEM = 0 # Set to '1' if the user specifies '--system'.
OPT_USER = 0 # Set to '1' if the user specifies '--user'.
OPT_UNINSTALL = 0 # Set to '1' if the user specifies '--uninstall'.
OPT_AOSA = 0 # Set to '1' if the user specifies '--setupAllOfficiallySupportedApps'.
2026-01-24 17:03:17 +01:00
OPT_ADD_APPS = 0 # Set to '1' if the user specifies '--add-apps'.
2020-11-19 22:05:52 -05:00
2024-07-14 23:10:10 +10:00
# WINAPPS CONFIGURATION FILE
2025-05-23 20:54:12 -05:00
RDP_USER = "" # Imported variable.
RDP_PASS = "" # Imported variable.
2026-03-16 11:28:32 +10:00
RDP_ASKPASS = "" # Imported variable.
2025-05-23 20:54:12 -05:00
RDP_DOMAIN = "" # Imported variable.
RDP_IP = "" # Imported variable.
VM_NAME = "RDPWindows" # Name of the Windows VM (FOR 'libvirt' ONLY).
WAFLAVOR = "docker" # Imported variable.
RDP_SCALE = 100 # Imported variable.
2026-10-27 10:16:40 -04:00
RDP_DEVICE_SCALE = 100 # Derived from RDP_SCALE.
# Scale for 'winapps windows'; 'inherit' uses RDP_SCALE.
RDP_DESKTOP_SCALE = "inherit"
RDP_DESKTOP_DEVICE_SCALE = 100
2025-05-23 20:54:12 -05:00
RDP_FLAGS = "" # Imported variable.
DEBUG = "true" # Imported variable.
FREERDP_COMMAND = "" # Imported variable.
2024-07-14 23:10:10 +10:00
2025-06-05 10:31:03 +02:00
PORT_TIMEOUT = 5 # Default port check timeout.
RDP_TIMEOUT = 30 # Default RDP connection test timeout.
APP_SCAN_TIMEOUT = 60 # Default application scan timeout.
2024-07-14 23:10:10 +10:00
# PERMISSIONS AND DIRECTORIES
2024-07-15 21:03:11 +00:00
SUDO = "" # Set to "sudo" if the user specifies '--system', or "" if the user specifies '--user'.
BIN_PATH = "" # Set to $SYS_BIN_PATH if the user specifies '--system', or $USER_BIN_PATH if the user specifies '--user'.
APP_PATH = "" # Set to $SYS_APP_PATH if the user specifies '--system', or $USER_APP_PATH if the user specifies '--user'.
APPDATA_PATH = "" # Set to $SYS_APPDATA_PATH if the user specifies '--system', or $USER_APPDATA_PATH if the user specifies '--user'.
2025-07-31 13:06:49 +10:00
SOURCE_PATH = "" # Set to $SYS_SOURCE_PATH if the user specifies '--system', or $USER_SOURCE_PATH if the user specifies '--user'.
2024-07-14 23:10:10 +10:00
# INSTALLATION PROCESS
2024-07-15 21:03:11 +00:00
INSTALLED_EXES =() # List of executable file names of officially supported applications that have already been configured during the current installation process.
2024-07-14 23:10:10 +10:00
### TRAPS ###
2024-07-15 21:03:11 +00:00
set -o errtrace # Ensure traps are inherited by all shell functions and subshells.
trap "waTerminateScript" ERR # Catch non-zero return values.
2024-07-14 23:10:10 +10:00
### FUNCTIONS ###
# Name: 'waTerminateScript'
# Role: Terminates the script when a non-zero return value is encountered.
2025-09-10 22:00:45 +10:00
# shellcheck disable=SC2329 # Silence warning regarding this function never being invoked (shellCheck is currently bad at figuring out functions that are invoked via trap).
2024-07-14 23:10:10 +10:00
function waTerminateScript() {
2024-07-17 00:07:49 +10:00
# Store the non-zero exit status received by the trap.
local EXIT_STATUS = $?
2024-07-14 23:10:10 +10:00
2024-07-17 00:07:49 +10:00
# Display the exit status.
echo -e " ${ EXIT_TEXT } Exiting with status ' ${ EXIT_STATUS } '. ${ CLEAR_TEXT } "
2024-07-14 23:10:10 +10:00
2024-07-17 00:07:49 +10:00
# Terminate the script.
exit " $EXIT_STATUS "
2020-11-13 13:13:32 -05:00
}
2024-07-14 23:10:10 +10:00
# Name: 'waUsage'
# Role: Displays usage information for the script.
function waUsage() {
2024-07-17 00:07:49 +10:00
echo -e "Usage:
2025-02-02 17:42:24 +11:00
${ COMMAND_TEXT } --user ${ CLEAR_TEXT } # Install WinApps and selected applications in ${ HOME }
${ COMMAND_TEXT } --system ${ CLEAR_TEXT } # Install WinApps and selected applications in /usr
${ COMMAND_TEXT } --user --setupAllOfficiallySupportedApps ${ CLEAR_TEXT } # Install WinApps and all officially supported applications in ${ HOME }
${ COMMAND_TEXT } --system --setupAllOfficiallySupportedApps ${ CLEAR_TEXT } # Install WinApps and all officially supported applications in /usr
${ COMMAND_TEXT } --user --uninstall ${ CLEAR_TEXT } # Uninstall everything in ${ HOME }
${ COMMAND_TEXT } --system --uninstall ${ CLEAR_TEXT } # Uninstall everything in /usr
2026-01-24 17:03:17 +01:00
${ COMMAND_TEXT } --user --add-apps ${ CLEAR_TEXT } # Add new applications to existing installation in ${ HOME }
${ COMMAND_TEXT } --system --add-apps ${ CLEAR_TEXT } # Add new applications to existing installation in /usr
2025-02-02 17:42:24 +11:00
${ COMMAND_TEXT } --help ${ CLEAR_TEXT } # Display this usage message."
2020-11-13 10:45:07 -05:00
}
2020-11-07 16:25:05 -05:00
2026-01-24 17:03:17 +01:00
2024-08-28 16:03:17 +02:00
# Name: 'waGetSourceCode'
# Role: Grab the WinApps source code using Git.
function waGetSourceCode() {
2024-07-17 00:07:49 +10:00
# Declare variables.
local SCRIPT_DIR_PATH = "" # Stores the absolute path of the directory containing the script.
# Determine the absolute path to the directory containing the script.
SCRIPT_DIR_PATH = $( readlink -f " $( dirname " ${ BASH_SOURCE [0] } " ) " )
2024-08-28 16:03:17 +02:00
# Check if winapps is currently installed on $SOURCE_PATH
2025-08-01 22:04:48 +10:00
if [[ -f " $SCRIPT_DIR_PATH /winapps" && " $SCRIPT_DIR_PATH " != " $SOURCE_PATH " ]] ; then
2024-08-28 16:03:17 +02:00
# Display a warning.
echo -e " ${ WARNING_TEXT } [WARNING] ${ CLEAR_TEXT } You are running a WinApps installation located outside of default location ' ${ SOURCE_PATH } '. A new installation will be created."
echo -e " ${ WARNING_TEXT } [WARNING] ${ CLEAR_TEXT } You might want to remove your old installation on ' ${ SCRIPT_DIR_PATH } '."
fi
if [[ ! -d " $SOURCE_PATH " ]] ; then
$SUDO git clone --recurse-submodules --remote-submodules https://github.com/winapps-org/winapps.git " $SOURCE_PATH "
2024-08-29 12:29:31 +02:00
else
echo -e " ${ INFO_TEXT } WinApps installation already present at ${ CLEAR_TEXT }${ COMMAND_TEXT }${ SOURCE_PATH }${ CLEAR_TEXT }${ INFO_TEXT } . Updating... ${ CLEAR_TEXT } "
$SUDO git -C " $SOURCE_PATH " pull --no-rebase
2024-08-28 16:03:17 +02:00
fi
2024-07-17 00:07:49 +10:00
# Silently change the working directory.
2024-08-28 16:03:17 +02:00
if ! cd " $SOURCE_PATH " & >/dev/null; then
2024-07-17 00:07:49 +10:00
# Display the error type.
echo -e " ${ ERROR_TEXT } ERROR: ${ CLEAR_TEXT } ${ BOLD_TEXT } DIRECTORY CHANGE FAILURE. ${ CLEAR_TEXT } "
# Display error details.
2024-08-28 16:03:17 +02:00
echo -e " ${ INFO_TEXT } Failed to change the working directory to ${ CLEAR_TEXT }${ COMMAND_TEXT }${ SOURCE_PATH }${ CLEAR_TEXT }${ INFO_TEXT } . ${ CLEAR_TEXT } "
2024-07-17 00:07:49 +10:00
# Display the suggested action(s).
echo "--------------------------------------------------------------------------------"
echo "Ensure:"
2024-08-28 16:03:17 +02:00
echo -e " - ${ COMMAND_TEXT }${ SOURCE_PATH }${ CLEAR_TEXT } exists."
echo -e " - ${ COMMAND_TEXT }${ SOURCE_PATH }${ CLEAR_TEXT } has been cloned and checked out properly."
echo -e " - The current user has sufficient permissions to access and write to ${ COMMAND_TEXT }${ SOURCE_PATH }${ CLEAR_TEXT } ."
2024-07-17 00:07:49 +10:00
echo "--------------------------------------------------------------------------------"
# Terminate the script.
return " $EC_FAILED_CD "
fi
2020-11-13 10:45:07 -05:00
}
2020-11-07 16:25:05 -05:00
2024-08-30 13:01:05 +02:00
# Name: 'waGetInquirer'
# Role: Loads the inquirer script, even if the source isn't cloned yet
function waGetInquirer() {
2024-09-07 13:23:37 +02:00
local INQUIRER = $INQUIRER_PATH
2025-01-03 15:06:19 +08:00
if [ -d " $SYS_SOURCE_PATH " ] ; then
2025-01-03 11:16:46 +01:00
INQUIRER = $SYS_SOURCE_PATH /$INQUIRER_PATH
2025-01-03 15:06:19 +08:00
elif [ -d " $USER_SOURCE_PATH " ] ; then
2025-01-03 11:16:46 +01:00
INQUIRER = $USER_SOURCE_PATH /$INQUIRER_PATH
2025-01-03 15:06:19 +08:00
else
2025-01-03 11:16:46 +01:00
INQUIRER = "/tmp/waInquirer.sh"
2024-09-07 13:23:37 +02:00
rm -f " $INQUIRER "
2024-08-30 12:05:07 +00:00
2024-09-07 13:23:37 +02:00
curl -o " $INQUIRER " "https://raw.githubusercontent.com/winapps-org/winapps/main/install/inquirer.sh"
2024-08-30 13:01:05 +02:00
fi
# shellcheck source=/dev/null # Exclude this file from being checked by ShellCheck.
2024-09-07 13:23:37 +02:00
source " $INQUIRER "
2024-08-30 13:01:05 +02:00
}
2024-07-14 23:10:10 +10:00
# Name: 'waCheckInput'
# Role: Sanitises input and guides users through selecting appropriate options if no arguments are provided.
function waCheckInput() {
2024-07-17 00:07:49 +10:00
# Declare variables.
local OPTIONS =() # Stores the options.
local SELECTED_OPTION # Stores the option selected by the user.
if [[ $# -gt 0 ]] ; then
# Parse arguments.
for argument in " $@ " ; do
case " $argument " in
"--user" )
OPT_USER = 1
;;
"--system" )
OPT_SYSTEM = 1
;;
"--setupAllOfficiallySupportedApps" )
OPT_AOSA = 1
;;
"--uninstall" )
OPT_UNINSTALL = 1
;;
2026-01-24 17:03:17 +01:00
"--add-apps" )
OPT_ADD_APPS = 1
;;
2024-07-17 00:07:49 +10:00
"--help" )
waUsage
exit 0
;;
*)
# Display the error type.
echo -e " ${ ERROR_TEXT } ERROR: ${ CLEAR_TEXT } ${ BOLD_TEXT } INVALID ARGUMENT. ${ CLEAR_TEXT } "
# Display the error details.
echo -e " ${ INFO_TEXT } Unsupported argument ${ CLEAR_TEXT } ${ COMMAND_TEXT }${ argument }${ CLEAR_TEXT }${ INFO_TEXT } . ${ CLEAR_TEXT } "
# Display the suggested action(s).
echo "--------------------------------------------------------------------------------"
waUsage
echo "--------------------------------------------------------------------------------"
# Terminate the script.
return " $EC_BAD_ARGUMENT "
;;
esac
done
else
# Install vs. uninstall?
OPTIONS =( "Install" "Uninstall" )
inqMenu "Install or uninstall WinApps?" OPTIONS SELECTED_OPTION
# Set flags.
if [[ $SELECTED_OPTION == "Uninstall" ]] ; then
OPT_UNINSTALL = 1
fi
# User vs. system?
OPTIONS =( "Current User" "System" )
inqMenu "Configure WinApps for the current user ' $( whoami) ' or the whole system?" OPTIONS SELECTED_OPTION
# Set flags.
if [[ $SELECTED_OPTION == "Current User" ]] ; then
OPT_USER = 1
elif [[ $SELECTED_OPTION == "System" ]] ; then
OPT_SYSTEM = 1
fi
# Automatic vs. manual?
if [ " $OPT_UNINSTALL " -eq 0 ] ; then
OPTIONS =( "Manual (Default)" "Automatic" )
inqMenu "Automatically install supported applications or choose manually?" OPTIONS SELECTED_OPTION
# Set flags.
if [[ $SELECTED_OPTION == "Automatic" ]] ; then
OPT_AOSA = 1
fi
fi
# Newline.
echo ""
fi
# Simultaneous 'User' and 'System'.
if [ " $OPT_SYSTEM " -eq 1 ] && [ " $OPT_USER " -eq 1 ] ; then
# Display the error type.
echo -e " ${ ERROR_TEXT } ERROR: ${ CLEAR_TEXT } ${ BOLD_TEXT } CONFLICTING ARGUMENTS. ${ CLEAR_TEXT } "
# Display the error details.
echo -e " ${ INFO_TEXT } You cannot specify both ${ CLEAR_TEXT } ${ COMMAND_TEXT } --user ${ CLEAR_TEXT } ${ INFO_TEXT } and ${ CLEAR_TEXT } ${ COMMAND_TEXT } --system ${ CLEAR_TEXT } ${ INFO_TEXT } simultaneously. ${ CLEAR_TEXT } "
# Display the suggested action(s).
echo "--------------------------------------------------------------------------------"
waUsage
echo "--------------------------------------------------------------------------------"
# Terminate the script.
return " $EC_BAD_ARGUMENT "
fi
# Simultaneous 'Uninstall' and 'AOSA'.
if [ " $OPT_UNINSTALL " -eq 1 ] && [ " $OPT_AOSA " -eq 1 ] ; then
# Display the error type.
echo -e " ${ ERROR_TEXT } ERROR: ${ CLEAR_TEXT } ${ BOLD_TEXT } CONFLICTING ARGUMENTS. ${ CLEAR_TEXT } "
# Display the error details.
echo -e " ${ INFO_TEXT } You cannot specify both ${ CLEAR_TEXT } ${ COMMAND_TEXT } --uninstall ${ CLEAR_TEXT } ${ INFO_TEXT } and ${ CLEAR_TEXT } ${ COMMAND_TEXT } --aosa ${ CLEAR_TEXT } ${ INFO_TEXT } simultaneously. ${ CLEAR_TEXT } "
# Display the suggested action(s).
echo "--------------------------------------------------------------------------------"
waUsage
echo "--------------------------------------------------------------------------------"
# Terminate the script.
return " $EC_BAD_ARGUMENT "
fi
2026-01-24 17:03:17 +01:00
# Simultaneous 'Uninstall' and 'Add Apps'.
if [ " $OPT_UNINSTALL " -eq 1 ] && [ " $OPT_ADD_APPS " -eq 1 ] ; then
# Display the error type.
echo -e " ${ ERROR_TEXT } ERROR: ${ CLEAR_TEXT } ${ BOLD_TEXT } CONFLICTING ARGUMENTS. ${ CLEAR_TEXT } "
# Display the error details.
echo -e " ${ INFO_TEXT } You cannot specify both ${ CLEAR_TEXT } ${ COMMAND_TEXT } --uninstall ${ CLEAR_TEXT } ${ INFO_TEXT } and ${ CLEAR_TEXT } ${ COMMAND_TEXT } --add-apps ${ CLEAR_TEXT } ${ INFO_TEXT } simultaneously. ${ CLEAR_TEXT } "
# Display the suggested action(s).
echo "--------------------------------------------------------------------------------"
waUsage
echo "--------------------------------------------------------------------------------"
# Terminate the script.
return " $EC_BAD_ARGUMENT "
fi
# Simultaneous 'AOSA' and 'Add Apps'.
if [ " $OPT_AOSA " -eq 1 ] && [ " $OPT_ADD_APPS " -eq 1 ] ; then
# Display the error type.
echo -e " ${ ERROR_TEXT } ERROR: ${ CLEAR_TEXT } ${ BOLD_TEXT } CONFLICTING ARGUMENTS. ${ CLEAR_TEXT } "
# Display the error details.
echo -e " ${ INFO_TEXT } You cannot specify both ${ CLEAR_TEXT } ${ COMMAND_TEXT } --setupAllOfficiallySupportedApps ${ CLEAR_TEXT } ${ INFO_TEXT } and ${ CLEAR_TEXT } ${ COMMAND_TEXT } --add-apps ${ CLEAR_TEXT } ${ INFO_TEXT } simultaneously. ${ CLEAR_TEXT } "
# Display the suggested action(s).
echo "--------------------------------------------------------------------------------"
waUsage
echo "--------------------------------------------------------------------------------"
# Terminate the script.
return " $EC_BAD_ARGUMENT "
fi
2024-07-17 00:07:49 +10:00
# No 'User' or 'System'.
if [ " $OPT_SYSTEM " -eq 0 ] && [ " $OPT_USER " -eq 0 ] ; then
# Display the error type.
echo -e " ${ ERROR_TEXT } ERROR: ${ CLEAR_TEXT } ${ BOLD_TEXT } INSUFFICIENT ARGUMENTS. ${ CLEAR_TEXT } "
# Display the error details.
echo -e " ${ INFO_TEXT } You must specify either ${ CLEAR_TEXT } ${ COMMAND_TEXT } --user ${ CLEAR_TEXT } ${ INFO_TEXT } or ${ CLEAR_TEXT } ${ COMMAND_TEXT } --system ${ CLEAR_TEXT } ${ INFO_TEXT } to proceed. ${ CLEAR_TEXT } "
# Display the suggested action(s).
echo "--------------------------------------------------------------------------------"
waUsage
echo "--------------------------------------------------------------------------------"
# Terminate the script.
return " $EC_BAD_ARGUMENT "
fi
2024-07-14 23:10:10 +10:00
}
# Name: 'waConfigurePathsAndPermissions'
# Role: Sets paths and adjusts permissions as specified.
function waConfigurePathsAndPermissions() {
2024-07-17 00:07:49 +10:00
if [ " $OPT_USER " -eq 1 ] ; then
SUDO = ""
2024-08-28 16:03:17 +02:00
SOURCE_PATH = " $USER_SOURCE_PATH "
2024-07-17 00:07:49 +10:00
BIN_PATH = " $USER_BIN_PATH "
APP_PATH = " $USER_APP_PATH "
APPDATA_PATH = " $USER_APPDATA_PATH "
elif [ " $OPT_SYSTEM " -eq 1 ] ; then
SUDO = "sudo"
2024-08-28 16:03:17 +02:00
SOURCE_PATH = " $SYS_SOURCE_PATH "
2024-07-17 00:07:49 +10:00
BIN_PATH = " $SYS_BIN_PATH "
APP_PATH = " $SYS_APP_PATH "
APPDATA_PATH = " $SYS_APPDATA_PATH "
# Preemptively obtain superuser privileges.
sudo -v || {
# Display the error type.
echo -e " ${ ERROR_TEXT } ERROR: ${ CLEAR_TEXT } ${ BOLD_TEXT } AUTHENTICATION FAILURE. ${ CLEAR_TEXT } "
# Display the error details.
echo -e " ${ INFO_TEXT } Failed to gain superuser privileges. ${ CLEAR_TEXT } "
# Display the suggested action(s).
echo "--------------------------------------------------------------------------------"
echo "Please check your password and try again."
echo "If you continue to experience issues, contact your system administrator."
echo "--------------------------------------------------------------------------------"
# Terminate the script.
return " $EC_NO_SUDO "
}
fi
2024-07-14 23:10:10 +10:00
}
# Name: 'waCheckExistingInstall'
# Role: Identifies any existing WinApps installations that may conflict with the new installation.
function waCheckExistingInstall() {
2024-07-17 00:07:49 +10:00
# Print feedback.
echo -n "Checking for existing conflicting WinApps installations... "
2024-07-14 23:10:10 +10:00
2026-01-24 17:03:17 +01:00
# If --add-apps is specified, we don't want to fail if an installation exists
if [ " $OPT_ADD_APPS " -eq 1 ] ; then
# Check for an existing 'user' installation.
if [[ -f " ${ USER_BIN_PATH } /winapps" && -d " ${ USER_SOURCE_PATH } /winapps" ]] ; then
# Complete the previous line.
echo -e " ${ DONE_TEXT } Found! ${ CLEAR_TEXT } "
echo -e " ${ INFO_TEXT } Adding new applications to existing user installation. ${ CLEAR_TEXT } "
return 0
fi
# Check for an existing 'system' installation.
if [[ -f " ${ SYS_BIN_PATH } /winapps" && -d " ${ SYS_SOURCE_PATH } /winapps" ]] ; then
# Complete the previous line.
echo -e " ${ DONE_TEXT } Found! ${ CLEAR_TEXT } "
echo -e " ${ INFO_TEXT } Adding new applications to existing system installation. ${ CLEAR_TEXT } "
return 0
fi
# If we're adding apps but no installation exists, that's an error
echo -e " ${ FAIL_TEXT } Failed! ${ CLEAR_TEXT } \n"
# Display the error type.
echo -e " ${ ERROR_TEXT } ERROR: ${ CLEAR_TEXT } ${ BOLD_TEXT } NO EXISTING WINAPPS INSTALLATION. ${ CLEAR_TEXT } "
# Display the error details.
echo -e " ${ INFO_TEXT } No existing WinApps installation was detected. ${ CLEAR_TEXT } "
# Display the suggested action(s).
echo "--------------------------------------------------------------------------------"
echo -e "Please install WinApps first using ${ COMMAND_TEXT } winapps-setup --user ${ CLEAR_TEXT } or ${ COMMAND_TEXT } winapps-setup --system ${ CLEAR_TEXT } ."
echo "--------------------------------------------------------------------------------"
# Terminate the script.
return " $EC_EXISTING_INSTALL "
fi
2024-07-17 00:07:49 +10:00
# Check for an existing 'user' installation.
2024-08-28 16:03:17 +02:00
if [[ -f " ${ USER_BIN_PATH } /winapps" || -d " ${ USER_SOURCE_PATH } /winapps" ]] ; then
2024-07-17 00:07:49 +10:00
# Complete the previous line.
echo -e " ${ FAIL_TEXT } Failed! ${ CLEAR_TEXT } \n"
2024-07-14 23:10:10 +10:00
2024-07-17 00:07:49 +10:00
# Display the error type.
echo -e " ${ ERROR_TEXT } ERROR: ${ CLEAR_TEXT } ${ BOLD_TEXT } EXISTING 'USER' WINAPPS INSTALLATION. ${ CLEAR_TEXT } "
2024-07-14 23:10:10 +10:00
2024-07-17 00:07:49 +10:00
# Display the error details.
echo -e " ${ INFO_TEXT } A previous WinApps installation was detected for the current user. ${ CLEAR_TEXT } "
2024-07-14 23:10:10 +10:00
2024-07-17 00:07:49 +10:00
# Display the suggested action(s).
echo "--------------------------------------------------------------------------------"
2025-02-02 17:42:24 +11:00
echo -e "Please remove the existing WinApps installation using ${ COMMAND_TEXT } winapps-setup --user --uninstall ${ CLEAR_TEXT } ."
2024-07-17 00:07:49 +10:00
echo "--------------------------------------------------------------------------------"
2024-07-14 23:10:10 +10:00
2024-07-17 00:07:49 +10:00
# Terminate the script.
return " $EC_EXISTING_INSTALL "
fi
2024-07-14 23:10:10 +10:00
2024-07-17 00:07:49 +10:00
# Check for an existing 'system' installation.
2024-08-29 12:29:31 +02:00
if [[ -f " ${ SYS_BIN_PATH } /winapps" || -d " ${ SYS_SOURCE_PATH } /winapps" ]] ; then
2024-07-17 00:07:49 +10:00
# Complete the previous line.
echo -e " ${ FAIL_TEXT } Failed! ${ CLEAR_TEXT } \n"
2024-07-14 23:10:10 +10:00
2024-07-17 00:07:49 +10:00
# Display the error type.
echo -e " ${ ERROR_TEXT } ERROR: ${ CLEAR_TEXT } ${ BOLD_TEXT } EXISTING 'SYSTEM' WINAPPS INSTALLATION. ${ CLEAR_TEXT } "
2024-07-14 23:10:10 +10:00
2024-07-17 00:07:49 +10:00
# Display the error details.
echo -e " ${ INFO_TEXT } A previous system-wide WinApps installation was detected. ${ CLEAR_TEXT } "
2024-07-14 23:10:10 +10:00
2024-07-17 00:07:49 +10:00
# Display the suggested action(s).
echo "--------------------------------------------------------------------------------"
2025-02-02 17:42:24 +11:00
echo -e "Please remove the existing WinApps installation using ${ COMMAND_TEXT } winapps-setup --system --uninstall ${ CLEAR_TEXT } ."
2024-07-17 00:07:49 +10:00
echo "--------------------------------------------------------------------------------"
2024-07-14 23:10:10 +10:00
2024-07-17 00:07:49 +10:00
# Terminate the script.
return " $EC_EXISTING_INSTALL "
fi
2024-07-14 23:10:10 +10:00
2024-07-17 00:07:49 +10:00
# Print feedback.
echo -e " ${ DONE_TEXT } Done! ${ CLEAR_TEXT } "
2024-07-14 23:10:10 +10:00
}
2026-01-24 17:03:17 +01:00
2024-07-17 22:01:40 +10:00
# Name: 'waFixScale'
2026-10-27 10:16:40 -04:00
# Role: Validate the scales and choose the nearest device scales.
2024-07-17 22:01:40 +10:00
function waFixScale() {
2026-10-27 10:16:40 -04:00
local SCALE_KEY = ""
local DEVICE_SCALE_KEY = ""
local RAW_SCALE = ""
local SCALE_DIGITS = ""
local SCALE_VALUE = 0
local DEVICE_SCALE = 0
for SCALE_KEY in RDP_SCALE RDP_DESKTOP_SCALE; do
RAW_SCALE = " ${ !SCALE_KEY } "
if [ " $SCALE_KEY " = "RDP_SCALE" ] ; then
DEVICE_SCALE_KEY = "RDP_DEVICE_SCALE"
2024-07-18 07:19:18 +10:00
else
2026-10-27 10:16:40 -04:00
DEVICE_SCALE_KEY = "RDP_DESKTOP_DEVICE_SCALE"
if [ " $RAW_SCALE " = "inherit" ] ; then
RAW_SCALE = " $RDP_SCALE "
fi
2024-07-18 07:19:18 +10:00
fi
2024-07-17 22:01:40 +10:00
2026-10-27 10:16:40 -04:00
if [[ ! " $RAW_SCALE " = ~ ^[ +-] ?[ 0-9] +$ ]] ; then
echo -e " ${ ERROR_TEXT } ERROR: ${ CLEAR_TEXT } ${ BOLD_TEXT }${ SCALE_KEY } must be an integer; received ' ${ RAW_SCALE } '. ${ CLEAR_TEXT } "
return " $EC_INVALID_SCALE "
fi
SCALE_DIGITS = " ${ RAW_SCALE #[+-] } "
while [[ " $SCALE_DIGITS " == 0* ]] && [ " $SCALE_DIGITS " != "0" ] ; do
SCALE_DIGITS = " ${ SCALE_DIGITS #0 } "
done
# Bound the value before arithmetic to avoid integer overflow.
if [[ " $RAW_SCALE " == -* ]] ; then
SCALE_VALUE = 0
elif (( ${# SCALE_DIGITS } > 3 )) ; then
SCALE_VALUE = 501
else
SCALE_VALUE = $(( 10# $SCALE_DIGITS ))
fi
if (( SCALE_VALUE < 100 )) ; then
SCALE_VALUE = 100
echo -e " ${ WARNING_TEXT } [WARNING] ${ CLEAR_TEXT } ${ SCALE_KEY } value ' ${ RAW_SCALE } ' is below 100. Clamping desktop scale to ' ${ SCALE_VALUE } '. ${ CLEAR_TEXT } "
elif (( SCALE_VALUE > 500 )) ; then
SCALE_VALUE = 500
echo -e " ${ WARNING_TEXT } [WARNING] ${ CLEAR_TEXT } ${ SCALE_KEY } value ' ${ RAW_SCALE } ' is above 500. Clamping desktop scale to ' ${ SCALE_VALUE } '. ${ CLEAR_TEXT } "
fi
DEVICE_SCALE = $(( SCALE_VALUE <= 120 ? 100 : SCALE_VALUE <= 160 ? 140 : 180 ))
printf -v " $SCALE_KEY " '%s' " $SCALE_VALUE "
printf -v " $DEVICE_SCALE_KEY " '%s' " $DEVICE_SCALE "
if [ " $DEVICE_SCALE " != " $SCALE_VALUE " ] ; then
echo -e " ${ INFO_TEXT } Approximating the device scale for ${ SCALE_KEY } from ' ${ SCALE_VALUE } ' to ' ${ DEVICE_SCALE } '; desktop scale remains ' ${ SCALE_VALUE } '. ${ CLEAR_TEXT } "
fi
done
return 0
2024-07-17 22:01:40 +10:00
}
2024-07-14 23:10:10 +10:00
# Name: 'waLoadConfig'
# Role: Loads settings specified within the WinApps configuration file.
function waLoadConfig() {
2024-07-17 00:07:49 +10:00
# Print feedback.
echo -n "Attempting to load WinApps configuration file... "
if [ ! -f " $CONFIG_PATH " ] ; 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 CONFIGURATION FILE. ${ CLEAR_TEXT } "
# Display the error details.
echo -e " ${ INFO_TEXT } A valid WinApps configuration file was not found. ${ CLEAR_TEXT } "
# Display the suggested action(s).
echo "--------------------------------------------------------------------------------"
echo -e "Please create a configuration file at ${ COMMAND_TEXT }${ CONFIG_PATH }${ CLEAR_TEXT } ."
2024-07-30 23:16:51 +10:00
echo -e "See https://github.com/winapps-org/winapps?tab=readme-ov-file#step-3-create-a-winapps-configuration-file"
2024-07-17 00:07:49 +10:00
echo "--------------------------------------------------------------------------------"
# Terminate the script.
return " $EC_NO_CONFIG "
else
# Load the WinApps configuration file.
# shellcheck source=/dev/null # Exclude this file from being checked by ShellCheck.
source " $CONFIG_PATH "
2026-03-16 11:28:32 +10:00
2026-05-10 15:59:53 +09:00
RDP_PORT = " ${ RDP_PORT :- 3389 } "
2026-11-26 15:41:17 +05:30
# An empty domain makes FreeRDP try Kerberos against the system default realm,
# which can stall the login for minutes. '.' means the local Windows account.
RDP_DOMAIN = " ${ RDP_DOMAIN :- . } "
2026-05-10 15:59:53 +09:00
2026-03-16 11:28:32 +10:00
# Send password on the command line if a command to retrieve the password from is not given
# Otherwise, set FREERDP_ASKPASS which freerdp will read the stdout of to use as the password
RDP_PASSWORD_ARG = "/p: $RDP_PASS "
if [[ ! -z " $RDP_ASKPASS " ]] ; then
export FREERDP_ASKPASS = " $RDP_ASKPASS "
unset RDP_PASSWORD_ARG
fi
2024-07-17 00:07:49 +10:00
fi
# Print feedback.
echo -e " ${ DONE_TEXT } Done! ${ CLEAR_TEXT } "
2020-11-13 10:45:07 -05:00
}
2024-07-23 17:14:43 +10:00
# Name: 'waCheckScriptDependencies'
2024-07-14 23:10:10 +10:00
# Role: Terminate script if dependencies are missing.
2024-07-23 17:14:43 +10:00
function waCheckScriptDependencies() {
2024-08-28 16:03:17 +02:00
# 'Git'
if ! command -v git & >/dev/null; then
# 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 'git' to proceed. ${ CLEAR_TEXT } "
# Display the suggested action(s).
echo "--------------------------------------------------------------------------------"
echo "Debian/Ubuntu-based systems:"
echo -e " ${ COMMAND_TEXT } sudo apt install git ${ CLEAR_TEXT } "
echo "Red Hat/Fedora-based systems:"
echo -e " ${ COMMAND_TEXT } sudo dnf install git ${ CLEAR_TEXT } "
echo "Arch Linux systems:"
echo -e " ${ COMMAND_TEXT } sudo pacman -S git ${ CLEAR_TEXT } "
echo "Gentoo Linux systems:"
echo -e " ${ COMMAND_TEXT } sudo emerge --ask dev-vcs/git ${ CLEAR_TEXT } "
echo "--------------------------------------------------------------------------------"
# Terminate the script.
return " $EC_MISSING_DEPS "
fi
2024-08-29 12:29:31 +02:00
# 'curl'
if ! command -v curl & >/dev/null; then
# 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 'curl' to proceed. ${ CLEAR_TEXT } "
# Display the suggested action(s).
echo "--------------------------------------------------------------------------------"
echo "Debian/Ubuntu-based systems:"
echo -e " ${ COMMAND_TEXT } sudo apt install curl ${ CLEAR_TEXT } "
echo "Red Hat/Fedora-based systems:"
echo -e " ${ COMMAND_TEXT } sudo dnf install curl ${ CLEAR_TEXT } "
echo "Arch Linux systems:"
echo -e " ${ COMMAND_TEXT } sudo pacman -S curl ${ CLEAR_TEXT } "
echo "Gentoo Linux systems:"
echo -e " ${ COMMAND_TEXT } sudo emerge --ask net-misc/curl ${ CLEAR_TEXT } "
echo "--------------------------------------------------------------------------------"
# Terminate the script.
return " $EC_MISSING_DEPS "
fi
2024-07-17 00:07:49 +10:00
# 'Dialog'.
if ! command -v dialog & >/dev/null; then
# 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 'dialog' to proceed. ${ CLEAR_TEXT } "
# Display the suggested action(s).
echo "--------------------------------------------------------------------------------"
echo "Debian/Ubuntu-based systems:"
echo -e " ${ COMMAND_TEXT } sudo apt install dialog ${ CLEAR_TEXT } "
echo "Red Hat/Fedora-based systems:"
echo -e " ${ COMMAND_TEXT } sudo dnf install dialog ${ CLEAR_TEXT } "
echo "Arch Linux systems:"
echo -e " ${ COMMAND_TEXT } sudo pacman -S dialog ${ CLEAR_TEXT } "
echo "Gentoo Linux systems:"
echo -e " ${ COMMAND_TEXT } sudo emerge --ask dialog ${ CLEAR_TEXT } "
echo "--------------------------------------------------------------------------------"
# Terminate the script.
return " $EC_MISSING_DEPS "
fi
2024-07-23 17:14:43 +10:00
}
2024-07-17 00:07:49 +10:00
2024-07-23 17:14:43 +10:00
# Name: 'waCheckInstallDependencies'
# Role: Terminate script if dependencies required to install WinApps are missing.
function waCheckInstallDependencies() {
# Declare variables.
local FREERDP_MAJOR_VERSION = "" # Stores the major version of the installed copy of FreeRDP.
2024-07-23 06:54:57 +10:00
2024-07-23 17:14:43 +10:00
# Print feedback.
echo -n "Checking whether dependencies are installed... "
2024-07-23 06:54:57 +10:00
2024-07-28 21:29:37 +10:00
# 'libnotify'
if ! command -v notify-send & >/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 'libnotify' to proceed. ${ CLEAR_TEXT } "
# Display the suggested action(s).
echo "--------------------------------------------------------------------------------"
echo "Debian/Ubuntu-based systems:"
echo -e " ${ COMMAND_TEXT } sudo apt install libnotify-bin ${ CLEAR_TEXT } "
echo "Red Hat/Fedora-based systems:"
echo -e " ${ COMMAND_TEXT } sudo dnf install libnotify ${ CLEAR_TEXT } "
echo "Arch Linux systems:"
echo -e " ${ COMMAND_TEXT } sudo pacman -S libnotify ${ CLEAR_TEXT } "
echo "Gentoo Linux systems:"
echo -e " ${ COMMAND_TEXT } sudo emerge --ask x11-libs/libnotify ${ CLEAR_TEXT } "
echo "--------------------------------------------------------------------------------"
# Terminate the script.
return " $EC_MISSING_DEPS "
fi
2024-07-23 06:54:57 +10:00
# 'Netcat'
if ! command -v nc & >/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 'netcat' to proceed. ${ CLEAR_TEXT } "
# Display the suggested action(s).
echo "--------------------------------------------------------------------------------"
echo "Debian/Ubuntu-based systems:"
echo -e " ${ COMMAND_TEXT } sudo apt install netcat ${ CLEAR_TEXT } "
echo "Red Hat/Fedora-based systems:"
echo -e " ${ COMMAND_TEXT } sudo dnf install nmap-ncat ${ CLEAR_TEXT } "
echo "Arch Linux systems:"
2025-12-08 22:06:16 +05:00
echo -e " ${ COMMAND_TEXT } sudo pacman -S openbsd-netcat ${ CLEAR_TEXT } "
2024-07-23 06:54:57 +10:00
echo "Gentoo Linux systems:"
echo -e " ${ COMMAND_TEXT } sudo emerge --ask net-analyzer/netcat ${ CLEAR_TEXT } "
echo "--------------------------------------------------------------------------------"
# Terminate the script.
return " $EC_MISSING_DEPS "
fi
2024-07-17 00:07:49 +10:00
# 'FreeRDP' (Version 3).
# Attempt to set a FreeRDP command if the command variable is empty.
if [ -z " $FREERDP_COMMAND " ] ; then
# Check common commands used to launch FreeRDP.
if command -v xfreerdp & >/dev/null; then
# Check FreeRDP major version is 3 or greater.
2024-07-17 22:15:23 +10:00
FREERDP_MAJOR_VERSION = $( xfreerdp --version | head -n 1 | grep -o -m 1 '\b[0-9]\S*' | head -n 1 | cut -d'.' -f1)
2024-07-17 00:07:49 +10:00
if [[ $FREERDP_MAJOR_VERSION = ~ ^[ 0-9] +$ ]] && (( FREERDP_MAJOR_VERSION >= 3)) ; then
FREERDP_COMMAND = "xfreerdp"
fi
2024-08-11 10:56:19 +08:00
fi
# Check for xfreerdp3 command as a fallback option.
if [ -z " $FREERDP_COMMAND " ] ; then
if command -v xfreerdp3 & >/dev/null; then
# Check FreeRDP major version is 3 or greater.
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
FREERDP_COMMAND = "xfreerdp3"
fi
2024-07-17 00:07:49 +10:00
fi
fi
# Check for FreeRDP flatpak as a fallback option.
if [ -z " $FREERDP_COMMAND " ] ; then
if command -v flatpak & >/dev/null; then
if flatpak list --columns= application | grep -q "^com.freerdp.FreeRDP $" ; then
# Check FreeRDP major version is 3 or greater.
FREERDP_MAJOR_VERSION = $( flatpak list --columns= application,version | grep "^com.freerdp.FreeRDP" | awk '{print $2}' | cut -d'.' -f1)
if [[ $FREERDP_MAJOR_VERSION = ~ ^[ 0-9] +$ ]] && (( FREERDP_MAJOR_VERSION >= 3)) ; then
FREERDP_COMMAND = "flatpak run --command=xfreerdp com.freerdp.FreeRDP"
fi
fi
fi
fi
fi
if ! command -v " $FREERDP_COMMAND " & >/dev/null && [ " $FREERDP_COMMAND " != "flatpak run --command=xfreerdp com.freerdp.FreeRDP" ] ; 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 'FreeRDP' version 3 to proceed. ${ CLEAR_TEXT } "
# Display the suggested action(s).
echo "--------------------------------------------------------------------------------"
echo "Debian/Ubuntu-based systems:"
echo -e " ${ COMMAND_TEXT } sudo apt install freerdp3-x11 ${ CLEAR_TEXT } "
echo "Red Hat/Fedora-based systems:"
echo -e " ${ COMMAND_TEXT } sudo dnf install freerdp ${ CLEAR_TEXT } "
echo "Arch Linux systems:"
echo -e " ${ COMMAND_TEXT } sudo pacman -S freerdp ${ CLEAR_TEXT } "
echo "Gentoo Linux systems:"
echo -e " ${ COMMAND_TEXT } sudo emerge --ask net-misc/freerdp ${ CLEAR_TEXT } "
echo ""
echo "You can also install FreeRDP as a Flatpak."
echo "Install Flatpak, add the Flathub repository and then install FreeRDP:"
echo -e " ${ COMMAND_TEXT } flatpak install flathub com.freerdp.FreeRDP ${ CLEAR_TEXT } "
echo -e " ${ COMMAND_TEXT } sudo flatpak override --filesystem=home com.freerdp.FreeRDP ${ CLEAR_TEXT } "
echo "--------------------------------------------------------------------------------"
# Terminate the script.
return " $EC_MISSING_DEPS "
fi
2024-07-25 10:12:59 +10:00
# 'libvirt'/'virt-manager' + 'iproute2'.
2024-07-17 18:51:22 +10:00
if [ " $WAFLAVOR " = "libvirt" ] ; then
if ! command -v virsh & >/dev/null; then
# Complete the previous line.
echo -e " ${ FAIL_TEXT } Failed! ${ CLEAR_TEXT } \n"
2024-07-17 00:07:49 +10:00
2024-07-17 18:51:22 +10:00
# Display the error type.
echo -e " ${ ERROR_TEXT } ERROR: ${ CLEAR_TEXT } ${ BOLD_TEXT } MISSING DEPENDENCIES. ${ CLEAR_TEXT } "
2024-07-17 00:07:49 +10:00
2024-07-17 18:51:22 +10:00
# Display the error details.
echo -e " ${ INFO_TEXT } Please install 'Virtual Machine Manager' to proceed. ${ CLEAR_TEXT } "
2024-07-17 00:07:49 +10:00
2024-07-17 18:51:22 +10:00
# Display the suggested action(s).
echo "--------------------------------------------------------------------------------"
echo "Debian/Ubuntu-based systems:"
echo -e " ${ COMMAND_TEXT } sudo apt install virt-manager ${ CLEAR_TEXT } "
echo "Red Hat/Fedora-based systems:"
echo -e " ${ COMMAND_TEXT } sudo dnf install virt-manager ${ CLEAR_TEXT } "
echo "Arch Linux systems:"
echo -e " ${ COMMAND_TEXT } sudo pacman -S virt-manager ${ CLEAR_TEXT } "
echo "Gentoo Linux systems:"
echo -e " ${ COMMAND_TEXT } sudo emerge --ask app-emulation/virt-manager ${ CLEAR_TEXT } "
echo "--------------------------------------------------------------------------------"
2024-07-17 00:07:49 +10:00
2024-07-17 18:51:22 +10:00
# Terminate the script.
return " $EC_MISSING_DEPS "
fi
2024-07-23 17:14:43 +10:00
2024-07-25 10:12:59 +10:00
if ! command -v ip & >/dev/null; then
2024-07-23 17:14:43 +10:00
# 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.
2024-07-25 10:12:59 +10:00
echo -e " ${ INFO_TEXT } Please install 'iproute2' to proceed. ${ CLEAR_TEXT } "
2024-07-23 17:14:43 +10:00
# Display the suggested action(s).
echo "--------------------------------------------------------------------------------"
echo "Debian/Ubuntu-based systems:"
2024-07-25 10:12:59 +10:00
echo -e " ${ COMMAND_TEXT } sudo apt install iproute2 ${ CLEAR_TEXT } "
2024-07-23 17:14:43 +10:00
echo "Red Hat/Fedora-based systems:"
2024-07-25 10:12:59 +10:00
echo -e " ${ COMMAND_TEXT } sudo dnf install iproute ${ CLEAR_TEXT } "
2024-07-23 17:14:43 +10:00
echo "Arch Linux systems:"
2024-07-25 10:12:59 +10:00
echo -e " ${ COMMAND_TEXT } sudo pacman -S iproute2 ${ CLEAR_TEXT } "
2024-07-23 17:14:43 +10:00
echo "Gentoo Linux systems:"
2024-07-25 10:12:59 +10:00
echo -e " ${ COMMAND_TEXT } sudo emerge --ask net-misc/iproute2 ${ CLEAR_TEXT } "
2024-07-23 17:14:43 +10:00
echo "--------------------------------------------------------------------------------"
# Terminate the script.
return " $EC_MISSING_DEPS "
fi
2024-07-17 18:51:22 +10:00
elif [ " $WAFLAVOR " = "docker" ] ; then
2024-07-19 13:13:02 +10:00
if ! command -v docker & >/dev/null; then
2024-07-17 18:51:22 +10:00
# 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.
2024-07-19 13:13:02 +10:00
echo -e " ${ INFO_TEXT } Please install 'Docker Engine' to proceed. ${ CLEAR_TEXT } "
2024-07-17 18:51:22 +10:00
# Display the suggested action(s).
echo "--------------------------------------------------------------------------------"
2024-07-18 18:27:07 +10:00
echo "Please visit https://docs.docker.com/engine/install/ for more information."
2024-07-19 13:13:02 +10:00
echo "--------------------------------------------------------------------------------"
# Terminate the script.
return " $EC_MISSING_DEPS "
fi
elif [ " $WAFLAVOR " = "podman" ] ; then
if ! command -v podman-compose & >/dev/null || ! command -v podman & >/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 'podman' and 'podman-compose' to proceed. ${ CLEAR_TEXT } "
# Display the suggested action(s).
echo "--------------------------------------------------------------------------------"
2024-07-19 08:06:53 +10:00
echo "Please visit https://podman.io/docs/installation for more information."
echo "Please visit https://github.com/containers/podman-compose for more information."
2024-07-17 18:51:22 +10:00
echo "--------------------------------------------------------------------------------"
# Terminate the script.
return " $EC_MISSING_DEPS "
fi
2024-07-17 00:07:49 +10:00
fi
# Print feedback.
echo -e " ${ DONE_TEXT } Done! ${ CLEAR_TEXT } "
2024-07-14 23:10:10 +10:00
}
# Name: 'waCheckGroupMembership'
# Role: Ensures the current user is part of the required groups.
function waCheckGroupMembership() {
2024-07-17 00:07:49 +10:00
# Print feedback.
echo -n "Checking whether the user ' $( whoami) ' is part of the required groups... "
2024-07-14 23:10:10 +10:00
2024-07-17 00:07:49 +10:00
# Declare variables.
local USER_GROUPS = "" # Stores groups the current user belongs to.
2024-07-14 23:10:10 +10:00
2024-07-17 00:07:49 +10:00
# Identify groups the current user belongs to.
USER_GROUPS = $( groups " $( whoami) " )
2024-07-14 23:10:10 +10:00
2024-07-17 00:07:49 +10:00
if ! ( echo " $USER_GROUPS " | grep -q -E "\blibvirt\b" ) || ! ( echo " $USER_GROUPS " | grep -q -E "\bkvm\b" ) ; then
# Complete the previous line.
echo -e " ${ FAIL_TEXT } Failed! ${ CLEAR_TEXT } \n"
2024-07-14 23:10:10 +10:00
2024-07-17 00:07:49 +10:00
# Display the error type.
echo -e " ${ ERROR_TEXT } ERROR: ${ CLEAR_TEXT } ${ BOLD_TEXT } GROUP MEMBERSHIP CHECK ERROR. ${ CLEAR_TEXT } "
2024-07-14 23:10:10 +10:00
2024-07-17 00:07:49 +10:00
# Display the error details.
echo -e " ${ INFO_TEXT } The current user ' $( whoami) ' is not part of group 'libvirt' and/or group 'kvm'. ${ CLEAR_TEXT } "
2024-07-14 23:10:10 +10:00
2024-07-17 00:07:49 +10:00
# Display the suggested action(s).
echo "--------------------------------------------------------------------------------"
echo "Please run the below commands, followed by a system reboot:"
echo -e " ${ COMMAND_TEXT } sudo usermod -a -G libvirt $( whoami) ${ CLEAR_TEXT } "
echo -e " ${ COMMAND_TEXT } sudo usermod -a -G kvm $( whoami) ${ CLEAR_TEXT } "
echo "--------------------------------------------------------------------------------"
2024-07-14 23:10:10 +10:00
2024-07-17 00:07:49 +10:00
# Terminate the script.
return " $EC_NOT_IN_GROUP "
fi
2024-07-14 23:10:10 +10:00
2024-07-17 00:07:49 +10:00
# Print feedback.
echo -e " ${ DONE_TEXT } Done! ${ CLEAR_TEXT } "
2024-07-14 23:10:10 +10:00
}
# Name: 'waCheckVMRunning'
2024-07-18 18:27:07 +10:00
# Role: Checks the state of the Windows 'libvirt' VM to ensure it is running.
2024-07-14 23:10:10 +10:00
function waCheckVMRunning() {
2024-07-17 00:07:49 +10:00
# Print feedback.
echo -n "Checking the status of the Windows VM... "
2024-07-14 23:10:10 +10:00
2024-07-17 00:07:49 +10:00
# Obtain VM Status
2024-08-18 14:12:48 +02:00
VM_PAUSED = 0
2025-09-04 21:44:42 +10:00
virsh list --state-paused --name | grep -Fxq -- " $VM_NAME " || VM_PAUSED = " $? "
2024-08-18 14:12:48 +02:00
VM_RUNNING = 0
2025-09-04 21:44:42 +10:00
virsh list --state-running --name | grep -Fxq -- " $VM_NAME " || VM_RUNNING = " $? "
2024-08-18 14:12:48 +02:00
VM_SHUTOFF = 0
2025-09-04 21:44:42 +10:00
virsh list --state-shutoff --name | grep -Fxq -- " $VM_NAME " || VM_SHUTOFF = " $? "
2024-08-18 14:12:48 +02:00
if [[ $VM_SHUTOFF == "0" ]] ; then
2024-07-17 00:07:49 +10:00
# Complete the previous line.
echo -e " ${ FAIL_TEXT } Failed! ${ CLEAR_TEXT } \n"
2024-07-14 23:10:10 +10:00
2024-07-17 00:07:49 +10:00
# Display the error type.
echo -e " ${ ERROR_TEXT } ERROR: ${ CLEAR_TEXT } ${ BOLD_TEXT } WINDOWS VM NOT RUNNING. ${ CLEAR_TEXT } "
2024-07-14 23:10:10 +10:00
2024-07-17 00:07:49 +10:00
# Display the error details.
echo -e " ${ INFO_TEXT } The Windows VM ' ${ VM_NAME } ' is powered off. ${ CLEAR_TEXT } "
2024-07-14 23:10:10 +10:00
2024-07-17 00:07:49 +10:00
# Display the suggested action(s).
echo "--------------------------------------------------------------------------------"
echo "Please run the below command to start the Windows VM:"
echo -e " ${ COMMAND_TEXT } virsh start ${ VM_NAME }${ CLEAR_TEXT } "
echo "--------------------------------------------------------------------------------"
2024-07-14 23:10:10 +10:00
2024-07-17 00:07:49 +10:00
# Terminate the script.
return " $EC_VM_OFF "
2024-08-18 14:12:48 +02:00
elif [[ $VM_PAUSED == "0" ]] ; then
2024-07-17 00:07:49 +10:00
# Complete the previous line.
echo -e " ${ FAIL_TEXT } Failed! ${ CLEAR_TEXT } \n"
2024-07-14 23:10:10 +10:00
2024-07-17 00:07:49 +10:00
# Display the error type.
echo -e " ${ ERROR_TEXT } ERROR: ${ CLEAR_TEXT } ${ BOLD_TEXT } WINDOWS VM NOT RUNNING. ${ CLEAR_TEXT } "
2024-07-14 23:10:10 +10:00
2024-07-17 00:07:49 +10:00
# Display the error details.
echo -e " ${ INFO_TEXT } The Windows VM ' ${ VM_NAME } ' is paused. ${ CLEAR_TEXT } "
2024-07-14 23:10:10 +10:00
2024-07-17 00:07:49 +10:00
# Display the suggested action(s).
echo "--------------------------------------------------------------------------------"
echo "Please run the below command to resume the Windows VM:"
echo -e " ${ COMMAND_TEXT } virsh resume ${ VM_NAME }${ CLEAR_TEXT } "
echo "--------------------------------------------------------------------------------"
2024-07-14 23:10:10 +10:00
2024-07-17 00:07:49 +10:00
# Terminate the script.
return " $EC_VM_PAUSED "
2024-08-18 14:12:48 +02:00
elif [[ $VM_RUNNING != "0" ]] ; then
2024-07-17 00:07:49 +10:00
# Complete the previous line.
echo -e " ${ FAIL_TEXT } Failed! ${ CLEAR_TEXT } \n"
2024-07-14 23:10:10 +10:00
2024-07-17 00:07:49 +10:00
# Display the error type.
echo -e " ${ ERROR_TEXT } ERROR: ${ CLEAR_TEXT } ${ BOLD_TEXT } WINDOWS VM DOES NOT EXIST. ${ CLEAR_TEXT } "
2024-07-14 23:10:10 +10:00
2024-07-17 00:07:49 +10:00
# Display the error details.
echo -e " ${ INFO_TEXT } The Windows VM ' ${ VM_NAME } ' could not be found. ${ CLEAR_TEXT } "
2024-07-14 23:10:10 +10:00
2024-07-17 00:07:49 +10:00
# Display the suggested action(s).
echo "--------------------------------------------------------------------------------"
echo "Please ensure a Windows VM with the name ' ${ VM_NAME } ' exists."
echo "--------------------------------------------------------------------------------"
2024-07-14 23:10:10 +10:00
2024-07-17 00:07:49 +10:00
# Terminate the script.
return " $EC_VM_ABSENT "
fi
2024-07-14 23:10:10 +10:00
2024-07-17 00:07:49 +10:00
# Print feedback.
echo -e " ${ DONE_TEXT } Done! ${ CLEAR_TEXT } "
2024-07-14 23:10:10 +10:00
}
2024-07-17 18:51:22 +10:00
# Name: 'waCheckContainerRunning'
2024-07-24 02:39:57 +10:00
# Role: Throw an error if the Docker/Podman container is not running.
2024-07-17 18:51:22 +10:00
function waCheckContainerRunning() {
# Print feedback.
2024-07-18 18:27:07 +10:00
echo -n "Checking container status... "
2024-07-17 18:51:22 +10:00
# Declare variables.
local CONTAINER_STATE = ""
2024-07-24 16:33:05 +10:00
local COMPOSE_COMMAND = ""
2024-07-17 18:51:22 +10:00
2024-07-24 16:33:05 +10:00
# Determine the state of the container.
CONTAINER_STATE = $( " $WAFLAVOR " ps --all --filter name = "WinApps" --format '{{.Status}}' )
2024-07-17 18:51:22 +10:00
CONTAINER_STATE = ${ CONTAINER_STATE ,, } # Convert the string to lowercase.
CONTAINER_STATE = ${ CONTAINER_STATE %% * } # Extract the first word.
2024-07-24 16:33:05 +10:00
# Determine the compose command.
case " $WAFLAVOR " in
"docker" ) COMPOSE_COMMAND = "docker compose" ;;
"podman" ) COMPOSE_COMMAND = "podman-compose" ;;
esac
2024-07-17 18:51:22 +10:00
# Check container state.
if [[ " $CONTAINER_STATE " != "up" ]] ; then
# Complete the previous line.
echo -e " ${ FAIL_TEXT } Failed! ${ CLEAR_TEXT } \n"
# Display the error type.
2024-07-24 02:39:57 +10:00
echo -e " ${ ERROR_TEXT } ERROR: ${ CLEAR_TEXT } ${ BOLD_TEXT } CONTAINER NOT RUNNING. ${ CLEAR_TEXT } "
2024-07-17 18:51:22 +10:00
# Display the error details.
2024-07-18 18:27:07 +10:00
echo -e " ${ INFO_TEXT } Windows is not running. ${ CLEAR_TEXT } "
2024-07-17 18:51:22 +10:00
# Display the suggested action(s).
echo "--------------------------------------------------------------------------------"
2024-07-18 18:27:07 +10:00
echo "Please ensure Windows is powered on:"
2024-08-28 16:03:17 +02:00
echo -e " ${ COMMAND_TEXT }${ COMPOSE_COMMAND } --file ~/.config/winapps/compose.yaml start ${ CLEAR_TEXT } "
2024-07-17 18:51:22 +10:00
echo "--------------------------------------------------------------------------------"
# Terminate the script.
return " $EC_CONTAINER_OFF "
fi
# Print feedback.
echo -e " ${ DONE_TEXT } Done! ${ CLEAR_TEXT } "
}
2026-10-16 02:55:36 +03:00
# Name: 'waFindVMIPs'
# Role: List unique IPv4 addresses associated with the Windows VM MAC in the neighbour table.
# Note: After a VM reset, 'ip neigh' can return more than one IP for the same MAC (#432).
function waFindVMIPs() {
local VM_MAC = ""
VM_MAC = $( virsh domiflist " $VM_NAME " | grep -oE "([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})" ) # VM MAC address.
[ -z " $VM_MAC " ] && return 1
ip neigh show | grep -F -- " $VM_MAC " | grep -oE "([0-9]{1,3}\.){3}[0-9]{1,3}" | awk '!seen[$0]++'
}
# Name: 'waSelectReachableVMIP'
# Role: Try each VM neighbour IP until RDP_PORT accepts a connection; set RDP_IP on success.
# Returns: 0 if a reachable IP was selected, 1 if no IPs found, 2 if all candidates failed.
function waSelectReachableVMIP() {
local candidate = ""
local ips = ""
local last_ip = ""
ips = $( waFindVMIPs)
if [ -z " $ips " ] ; then
return 1
fi
while IFS = read -r candidate; do
[ -z " $candidate " ] && continue
last_ip = " $candidate "
if timeout " $PORT_TIMEOUT " nc -z " $candidate " " $RDP_PORT " & >/dev/null; then
RDP_IP = " $candidate "
return 0
fi
echo -e " ${ WARNING_TEXT } RDP port ${ RDP_PORT } closed on ${ candidate } ; trying next address if any... ${ CLEAR_TEXT } "
done <<< " $ips "
# Preserve last candidate so the BAD_PORT message can include the IP.
RDP_IP = " $last_ip "
return 2
}
2024-07-18 18:27:07 +10:00
# Name: 'waCheckPortOpen'
# Role: Assesses whether the RDP port on Windows is open.
function waCheckPortOpen() {
2024-07-17 00:07:49 +10:00
# Print feedback.
2024-07-18 18:27:07 +10:00
echo -n "Checking for an open RDP Port on Windows... "
2024-07-14 23:10:10 +10:00
2024-07-17 00:07:49 +10:00
# Declare variables.
2026-10-16 02:55:36 +03:00
local SELECT_STATUS = 0
2024-07-14 23:10:10 +10:00
2024-07-18 18:27:07 +10:00
# Obtain Windows VM IP Address (FOR 'libvirt' ONLY)
# Note: 'RDP_IP' should not be empty if 'WAFLAVOR' is 'docker', since it is set to localhost before this function is called.
if [ -z " $RDP_IP " ] && [ " $WAFLAVOR " = "libvirt" ] ; then
2026-10-16 02:55:36 +03:00
waSelectReachableVMIP
SELECT_STATUS = $?
if [ " $SELECT_STATUS " -ne 0 ] ; then
2024-07-17 00:07:49 +10:00
# Complete the previous line.
echo -e " ${ FAIL_TEXT } Failed! ${ CLEAR_TEXT } \n"
2024-07-14 23:10:10 +10:00
2024-07-17 00:07:49 +10:00
# Display the error type.
echo -e " ${ ERROR_TEXT } ERROR: ${ CLEAR_TEXT } ${ BOLD_TEXT } NETWORK CONFIGURATION ERROR. ${ CLEAR_TEXT } "
2024-07-14 23:10:10 +10:00
2026-10-16 02:55:36 +03:00
if [ " $SELECT_STATUS " -eq 1 ] ; then
# Display the error details.
echo -e " ${ INFO_TEXT } The IP address of the Windows VM ' ${ VM_NAME } ' could not be found. ${ CLEAR_TEXT } "
# Display the suggested action(s).
echo "--------------------------------------------------------------------------------"
echo "Please ensure networking is properly configured for the Windows VM."
echo "--------------------------------------------------------------------------------"
# Terminate the script.
return " $EC_NO_IP "
fi
# Display the error details (include IP for debugging multi-address neigh tables).
echo -e " ${ INFO_TEXT } Failed to establish a connection with Windows at ' ${ RDP_IP } : ${ RDP_PORT } '. ${ CLEAR_TEXT } "
2024-07-14 23:10:10 +10:00
2024-07-17 00:07:49 +10:00
# Display the suggested action(s).
echo "--------------------------------------------------------------------------------"
2026-10-16 02:55:36 +03:00
echo "Please ensure Remote Desktop is configured on Windows as per the WinApps README."
echo -e "Then you can try increasing the ${ COMMAND_TEXT } PORT_TIMEOUT ${ CLEAR_TEXT } in ${ COMMAND_TEXT }${ CONFIG_PATH }${ CLEAR_TEXT } ."
2024-07-17 00:07:49 +10:00
echo "--------------------------------------------------------------------------------"
2024-07-14 23:10:10 +10:00
2024-07-17 00:07:49 +10:00
# Terminate the script.
2026-10-16 02:55:36 +03:00
return " $EC_BAD_PORT "
2024-07-17 00:07:49 +10:00
fi
2026-10-16 02:55:36 +03:00
# Print feedback.
echo -e " ${ DONE_TEXT } Done! ${ CLEAR_TEXT } "
return 0
2024-07-17 00:07:49 +10:00
fi
2024-07-14 23:10:10 +10:00
2026-10-16 02:55:36 +03:00
# Check for an open RDP port (configured / non-libvirt path).
2025-06-05 10:31:03 +02:00
if ! timeout " $PORT_TIMEOUT " nc -z " $RDP_IP " " $RDP_PORT " & >/dev/null; then
2024-07-17 00:07:49 +10:00
# Complete the previous line.
echo -e " ${ FAIL_TEXT } Failed! ${ CLEAR_TEXT } \n"
2024-07-14 23:10:10 +10:00
2024-07-17 00:07:49 +10:00
# Display the error type.
echo -e " ${ ERROR_TEXT } ERROR: ${ CLEAR_TEXT } ${ BOLD_TEXT } NETWORK CONFIGURATION ERROR. ${ CLEAR_TEXT } "
2024-07-14 23:10:10 +10:00
2024-07-17 00:07:49 +10:00
# Display the error details.
2024-07-18 18:27:07 +10:00
echo -e " ${ INFO_TEXT } Failed to establish a connection with Windows at ' ${ RDP_IP } : ${ RDP_PORT } '. ${ CLEAR_TEXT } "
2024-07-14 23:10:10 +10:00
2024-07-17 00:07:49 +10:00
# Display the suggested action(s).
echo "--------------------------------------------------------------------------------"
2024-07-18 18:27:07 +10:00
echo "Please ensure Remote Desktop is configured on Windows as per the WinApps README."
2025-06-05 10:31:03 +02:00
echo -e "Then you can try increasing the ${ COMMAND_TEXT } PORT_TIMEOUT ${ CLEAR_TEXT } in ${ COMMAND_TEXT }${ CONFIG_PATH }${ CLEAR_TEXT } ."
2024-07-17 00:07:49 +10:00
echo "--------------------------------------------------------------------------------"
2024-07-14 23:10:10 +10:00
2024-07-17 00:07:49 +10:00
# Terminate the script.
2024-07-18 18:27:07 +10:00
return " $EC_BAD_PORT "
2024-07-17 00:07:49 +10:00
fi
2024-07-14 23:10:10 +10:00
2024-07-17 00:07:49 +10:00
# Print feedback.
echo -e " ${ DONE_TEXT } Done! ${ CLEAR_TEXT } "
2024-07-14 23:10:10 +10:00
}
2026-08-09 17:48:48 +02:00
# Name: 'waSelectPodmanRoute'
# Role: Determine how FreeRDP can reach the RDP port of the Windows container.
# Note: Depending on the podman version and network backend, the RDP port is
# reachable at the container IP from within the rootless network namespace
# (netavark bridge networking), at localhost from within the rootless
# network namespace (slirp4netns port forwarding), or at localhost from
# the host network namespace (rootlessport/pasta port publishing).
# Probe these routes in order and use the first one that works, modifying
# 'RDP_IP' and 'FREERDP_COMMAND' accordingly.
function waSelectPodmanRoute() {
local CONTAINER_IP = ""
CONTAINER_IP = $( podman inspect --format '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' "WinApps" 2>/dev/null)
if [ -n " $CONTAINER_IP " ] && timeout " $PORT_TIMEOUT " podman unshare --rootless-netns nc -z " $CONTAINER_IP " " $RDP_PORT " & >/dev/null; then
echo -e "RDP port reachable at container IP ' ${ CONTAINER_IP } ' within the rootless network namespace."
RDP_IP = " $CONTAINER_IP "
FREERDP_COMMAND = "podman unshare --rootless-netns ${ FREERDP_COMMAND } "
elif timeout " $PORT_TIMEOUT " podman unshare --rootless-netns nc -z " $RDP_IP " " $RDP_PORT " & >/dev/null; then
echo -e "RDP port reachable at ' ${ RDP_IP } ' within the rootless network namespace."
FREERDP_COMMAND = "podman unshare --rootless-netns ${ FREERDP_COMMAND } "
else
echo -e "RDP port unreachable within the rootless network namespace. Connecting from the host network namespace."
waCheckPortOpen
fi
}
2024-07-14 23:10:10 +10:00
# Name: 'waCheckRDPAccess'
2024-07-18 18:27:07 +10:00
# Role: Tests if Windows is accessible via RDP.
2024-07-14 23:10:10 +10:00
function waCheckRDPAccess() {
2024-07-17 00:07:49 +10:00
# Print feedback.
2024-07-18 18:27:07 +10:00
echo -n "Attempting to establish a Remote Desktop connection with Windows... "
2024-07-17 00:07:49 +10:00
# Declare variables.
local FREERDP_LOG = "" # Stores the path of the FreeRDP log file.
local FREERDP_PROC = "" # Stores the FreeRDP process ID.
local ELAPSED_TIME = "" # Stores the time counter.
# Log file path.
FREERDP_LOG = " ${ USER_APPDATA_PATH } /FreeRDP_Test_ $( date +'%Y%m%d_%H%M_%N' ) .log"
# Ensure the output directory exists.
mkdir -p " $USER_APPDATA_PATH "
# Remove existing 'FreeRDP Connection Test' file.
rm -f " $TEST_PATH "
# This command should create a file on the host filesystem before terminating the RDP session. This command is silently executed as a background process.
2024-07-18 18:27:07 +10:00
# If the file is created, it means Windows received the command via FreeRDP successfully and can read and write to the Linux home folder.
2024-07-17 00:07:49 +10:00
# Note: The following final line is expected within the log, indicating successful execution of the 'tsdiscon' command and termination of the RDP session.
# [INFO][com.freerdp.core] - [rdp_print_errinfo]: ERRINFO_LOGOFF_BY_USER (0x0000000C):The disconnection was initiated by the user logging off their session on the server.
2026-01-18 20:51:12 +01:00
# shellcheck disable=SC2140,SC2027,SC2086 # Disable warnings regarding unquoted strings.
2024-07-17 00:07:49 +10:00
$FREERDP_COMMAND \
2026-01-18 20:51:12 +01:00
$RDP_FLAGS_NON_WINDOWS \
2024-07-17 00:07:49 +10:00
/cert:tofu \
/d:" $RDP_DOMAIN " \
/u:" $RDP_USER " \
2026-03-16 11:28:32 +10:00
${ RDP_PASSWORD_ARG :+ " $RDP_PASSWORD_ARG " } \
2026-10-27 10:16:40 -04:00
/scale-desktop:" $RDP_SCALE " \
/scale-device:" $RDP_DEVICE_SCALE " \
2024-07-17 00:07:49 +10:00
+auto-reconnect \
2025-09-10 21:50:11 +10:00
+home-drive \
2025-03-20 23:39:41 -07:00
/app:program:"C:\Windows\System32\cmd.exe" ,cmd:"/C type NUL > $TEST_PATH_WIN && tsdiscon" \
2026-05-10 15:59:53 +09:00
/v:" $RDP_IP " :" $RDP_PORT " & >" $FREERDP_LOG " &
2024-07-17 00:07:49 +10:00
# Store the FreeRDP process ID.
FREERDP_PROC = $!
# Initialise the time counter.
ELAPSED_TIME = 0
2025-06-05 10:31:03 +02:00
# Wait a maximum of $RDP_TIMEOUT seconds for the background process to complete.
while [ " $ELAPSED_TIME " -lt " $RDP_TIMEOUT " ] ; do
2024-07-17 00:07:49 +10:00
# Check if the FreeRDP process is complete or if the test file exists.
if ! ps -p " $FREERDP_PROC " & >/dev/null || [ -f " $TEST_PATH " ] ; then
break
fi
# Wait for 5 seconds.
sleep 5
ELAPSED_TIME = $(( ELAPSED_TIME + 5 ))
done
# Check if FreeRDP process is not complete.
if ps -p " $FREERDP_PROC " & >/dev/null; then
# SIGKILL FreeRDP.
2024-07-19 13:13:02 +10:00
kill -9 " $FREERDP_PROC " & >/dev/null
2024-07-17 00:07:49 +10:00
fi
# Check if test file does not exist.
if ! [ -f " $TEST_PATH " ] ; 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 } REMOTE DESKTOP PROTOCOL FAILURE. ${ CLEAR_TEXT } "
# Display the error details.
2024-07-18 18:27:07 +10:00
echo -e " ${ INFO_TEXT } FreeRDP failed to establish a connection with Windows. ${ CLEAR_TEXT } "
2024-07-17 00:07:49 +10:00
# Display the suggested action(s).
echo "--------------------------------------------------------------------------------"
echo -e "Please view the log at ${ COMMAND_TEXT }${ FREERDP_LOG }${ CLEAR_TEXT } ."
echo "Troubleshooting Tips:"
2024-07-18 18:27:07 +10:00
echo " - Ensure the user is logged out of Windows prior to initiating the WinApps installation."
2024-07-17 00:07:49 +10:00
echo " - Ensure the credentials within the WinApps configuration file are correct."
echo -e " - Utilise a new certificate by removing relevant certificate(s) in ${ COMMAND_TEXT }${ HOME } /.config/freerdp/server ${ CLEAR_TEXT } ."
2025-06-05 10:31:03 +02:00
echo -e " - Try increasing the ${ COMMAND_TEXT } RDP_TIMEOUT ${ CLEAR_TEXT } in ${ COMMAND_TEXT }${ CONFIG_PATH }${ CLEAR_TEXT } ."
2024-07-17 22:01:40 +10:00
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."
2024-07-18 07:19:18 +10:00
echo " - If using 'libvirt', try logging into and back out of the Windows VM within 'virt-manager' prior to initiating the WinApps installation."
2024-07-17 00:07:49 +10:00
echo "--------------------------------------------------------------------------------"
# Terminate the script.
return " $EC_RDP_FAIL "
else
# Remove the temporary test file.
rm -f " $TEST_PATH "
fi
# Print feedback.
echo -e " ${ DONE_TEXT } Done! ${ CLEAR_TEXT } "
2024-07-14 23:10:10 +10:00
}
# Name: 'waFindInstalled'
2024-07-18 18:27:07 +10:00
# Role: Identifies installed applications on Windows.
2024-07-14 23:10:10 +10:00
function waFindInstalled() {
2024-07-17 00:07:49 +10:00
# Print feedback.
echo -n "Checking for installed Windows applications... "
# Declare variables.
local FREERDP_LOG = "" # Stores the path of the FreeRDP log file.
local FREERDP_PROC = "" # Stores the FreeRDP process ID.
local ELAPSED_TIME = "" # Stores the time counter.
# Log file path.
FREERDP_LOG = " ${ USER_APPDATA_PATH } /FreeRDP_Scan_ $( date +'%Y%m%d_%H%M_%N' ) .log"
# Make the output directory if required.
mkdir -p " $USER_APPDATA_PATH "
# Remove temporary files from previous WinApps installations.
rm -f " $BATCH_SCRIPT_PATH " " $TMP_INST_FILE_PATH " " $INST_FILE_PATH " " $PS_SCRIPT_HOME_PATH " " $DETECTED_FILE_PATH "
# Copy PowerShell script to a directory within the user's home folder.
2024-07-18 18:27:07 +10:00
# This will enable the PowerShell script to be accessed and executed by Windows.
2024-07-17 00:07:49 +10:00
cp " $PS_SCRIPT_PATH " " $PS_SCRIPT_HOME_PATH "
# Enumerate over each officially supported application.
for APPLICATION in ./apps/*; do
# Extract the name of the application from the absolute path of the folder.
APPLICATION = " $( basename " $APPLICATION " ) "
2025-05-15 14:09:17 +02:00
if [[ " $APPLICATION " == "ms-office-protocol-handler.desktop" ]] ; then
continue
fi
2024-07-17 00:07:49 +10:00
# Source 'Info' File Containing:
# - The Application Name (FULL_NAME)
# - The Shortcut Name (NAME)
# - Application Categories (CATEGORIES)
# - Executable Path (WIN_EXECUTABLE)
# - Supported MIME Types (MIME_TYPES)
# - Application Icon (ICON)
# shellcheck source=/dev/null # Exclude this file from being checked by ShellCheck.
source "./apps/ ${ APPLICATION } /info"
# Append commands to batch file.
2025-08-31 22:27:32 +10:00
echo "IF EXIST \" ${ WIN_EXECUTABLE } \" ECHO ${ APPLICATION } ^|^|^| ${ WIN_EXECUTABLE } >> ${ TMP_INST_FILE_PATH_WIN } " >>" $BATCH_SCRIPT_PATH "
2024-07-17 00:07:49 +10:00
done
2025-08-01 16:51:42 +10:00
# Append a command to the batch script to run the PowerShell script and store its output in the 'detected' file.
2024-07-17 00:07:49 +10:00
# shellcheck disable=SC2129 # Silence warning regarding repeated redirects.
echo "powershell.exe -ExecutionPolicy Bypass -File ${ PS_SCRIPT_HOME_PATH_WIN } > ${ DETECTED_FILE_PATH_WIN } " >>" $BATCH_SCRIPT_PATH "
# Append a command to the batch script to rename the temporary file containing the names of all detected officially supported applications.
echo "RENAME ${ TMP_INST_FILE_PATH_WIN } installed" >>" $BATCH_SCRIPT_PATH "
# Append a command to the batch script to terminate the remote desktop session once all previous commands are complete.
echo "tsdiscon" >>" $BATCH_SCRIPT_PATH "
2024-07-18 18:27:07 +10:00
# Silently execute the batch script within Windows in the background (Log Output To File)
2024-07-17 00:07:49 +10:00
# Note: The following final line is expected within the log, indicating successful execution of the 'tsdiscon' command and termination of the RDP session.
# [INFO][com.freerdp.core] - [rdp_print_errinfo]: ERRINFO_LOGOFF_BY_USER (0x0000000C):The disconnection was initiated by the user logging off their session on the server.
2026-01-18 20:51:12 +01:00
# shellcheck disable=SC2140,SC2027,SC2086 # Disable warnings regarding unquoted strings.
2024-07-17 00:07:49 +10:00
$FREERDP_COMMAND \
2026-01-18 20:51:12 +01:00
$RDP_FLAGS_NON_WINDOWS \
2024-07-17 00:07:49 +10:00
/cert:tofu \
/d:" $RDP_DOMAIN " \
/u:" $RDP_USER " \
2026-03-16 11:28:32 +10:00
${ RDP_PASSWORD_ARG :+ " $RDP_PASSWORD_ARG " } \
2026-10-27 10:16:40 -04:00
/scale-desktop:" $RDP_SCALE " \
/scale-device:" $RDP_DEVICE_SCALE " \
2024-07-17 00:07:49 +10:00
+auto-reconnect \
2025-09-10 21:50:11 +10:00
+home-drive \
2026-05-15 22:09:03 +02:00
/app:program:"C:\Windows\System32\cmd.exe" ,cmd:"/C $BATCH_SCRIPT_PATH_WIN " \
2026-05-10 15:59:53 +09:00
/v:" $RDP_IP " :" $RDP_PORT " & >" $FREERDP_LOG " &
2024-07-17 00:07:49 +10:00
# Store the FreeRDP process ID.
FREERDP_PROC = $!
# Initialise the time counter.
ELAPSED_TIME = 0
2025-06-05 10:31:03 +02:00
# Wait a maximum of $APP_SCAN_TIMEOUT seconds for the batch script to finish running.
while [ $ELAPSED_TIME -lt " $APP_SCAN_TIMEOUT " ] ; do
2024-07-17 00:07:49 +10:00
# Check if the FreeRDP process is complete or if the 'installed' file exists.
if ! ps -p " $FREERDP_PROC " & >/dev/null || [ -f " $INST_FILE_PATH " ] ; then
break
fi
# Wait for 5 seconds.
sleep 5
ELAPSED_TIME = $(( ELAPSED_TIME + 5 ))
done
# Check if the FreeRDP process is not complete.
if ps -p " $FREERDP_PROC " & >/dev/null; then
# SIGKILL FreeRDP.
2024-07-19 13:13:02 +10:00
kill -9 " $FREERDP_PROC " & >/dev/null
2024-07-17 00:07:49 +10:00
fi
# Check if test file does not exist.
if ! [ -f " $INST_FILE_PATH " ] ; 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 } APPLICATION QUERY FAILURE. ${ CLEAR_TEXT } "
# Display the error details.
2024-07-18 18:27:07 +10:00
echo -e " ${ INFO_TEXT } Failed to query Windows for installed applications. ${ CLEAR_TEXT } "
2024-07-17 00:07:49 +10:00
# Display the suggested action(s).
echo "--------------------------------------------------------------------------------"
echo -e "Please view the log at ${ COMMAND_TEXT }${ FREERDP_LOG }${ CLEAR_TEXT } ."
2025-06-05 10:31:03 +02:00
echo -e "You can try increasing the ${ COMMAND_TEXT } APP_SCAN_TIMEOUT ${ CLEAR_TEXT } in ${ COMMAND_TEXT }${ CONFIG_PATH }${ CLEAR_TEXT } ."
2024-07-17 00:07:49 +10:00
echo "--------------------------------------------------------------------------------"
# Terminate the script.
return " $EC_APPQUERY_FAIL "
fi
# Print feedback.
echo -e " ${ DONE_TEXT } Done! ${ CLEAR_TEXT } "
2024-07-14 23:10:10 +10:00
}
# Name: 'waConfigureWindows'
2024-07-18 18:27:07 +10:00
# Role: Create an application entry for launching Windows via Remote Desktop.
2024-07-14 23:10:10 +10:00
function waConfigureWindows() {
2024-07-17 00:07:49 +10:00
# Print feedback.
2024-07-18 18:27:07 +10:00
echo -n "Creating an application entry for Windows... "
2024-07-14 23:10:10 +10:00
2024-07-17 00:07:49 +10:00
# Declare variables.
2024-07-18 18:27:07 +10:00
local WIN_BASH = "" # Stores the bash script to launch a Windows RDP session.
local WIN_DESKTOP = "" # Stores the '.desktop' file to launch a Windows RDP session.
2024-07-14 23:10:10 +10:00
2024-07-17 00:07:49 +10:00
# Populate variables.
WIN_BASH = "\
2024-07-14 23:10:10 +10:00
#!/usr/bin/env bash
2026-06-11 14:24:45 +02:00
${ BIN_PATH } /winapps windows \"\$@\""
2024-07-17 00:07:49 +10:00
WIN_DESKTOP = "\
2024-07-16 00:30:17 +10:00
[Desktop Entry]
Name=Windows
Exec= ${ BIN_PATH } /winapps windows %F
Terminal=false
Type=Application
Icon= ${ APPDATA_PATH } /icons/windows.svg
StartupWMClass=Microsoft Windows
2024-07-18 18:27:07 +10:00
Comment=Microsoft Windows RDP Session"
2024-07-14 23:10:10 +10:00
2024-07-17 00:07:49 +10:00
# Copy the 'Windows' icon.
2025-08-31 15:19:05 +02:00
$SUDO cp "./install/windows.svg" " ${ APPDATA_PATH } /icons/windows.svg"
2024-07-14 23:10:10 +10:00
2024-07-17 00:07:49 +10:00
# Write the desktop entry content to a file.
echo " $WIN_DESKTOP " | $SUDO tee " ${ APP_PATH } /windows.desktop" & >/dev/null
2024-05-15 10:14:26 +02:00
2024-07-17 00:07:49 +10:00
# Write the bash script to a file.
echo " $WIN_BASH " | $SUDO tee " ${ BIN_PATH } /windows" & >/dev/null
2024-07-14 23:10:10 +10:00
2024-07-17 00:07:49 +10:00
# Mark the bash script as executable.
$SUDO chmod a+x " ${ BIN_PATH } /windows"
2024-07-14 23:10:10 +10:00
2024-07-17 00:07:49 +10:00
# Print feedback.
echo -e " ${ DONE_TEXT } Done! ${ CLEAR_TEXT } "
2020-11-19 22:05:52 -05:00
}
2024-07-14 23:10:10 +10:00
# Name: 'waConfigureApp'
2024-07-18 18:27:07 +10:00
# Role: Create application entries for a given application installed on Windows.
2024-07-14 23:10:10 +10:00
function waConfigureApp() {
2024-07-17 00:07:49 +10:00
# Declare variables.
local APP_ICON = "" # Stores the path to the application icon.
local APP_BASH = "" # Stores the bash script used to launch the application.
local APP_DESKTOP_FILE = "" # Stores the '.desktop' file used to launch the application.
# Source 'Info' File Containing:
# - The Application Name (FULL_NAME)
2025-07-31 12:26:27 +10:00
# - The Shortcut Name (NAME)
2024-07-17 00:07:49 +10:00
# - Application Categories (CATEGORIES)
# - Executable Path (WIN_EXECUTABLE)
# - Supported MIME Types (MIME_TYPES)
# - Application Icon (ICON)
# shellcheck source=/dev/null # Exclude this file from being checked by ShellCheck.
source " ${ APPDATA_PATH } /apps/ ${ 1 } /info"
# Determine path to application icon using arguments passed to function.
APP_ICON = " ${ APPDATA_PATH } /apps/ ${ 1 } /icon. ${ 2 } "
# Determine the content of the bash script for the application.
APP_BASH = "\
2024-07-16 00:30:17 +10:00
#!/usr/bin/env bash
2026-06-11 14:24:45 +02:00
${ BIN_PATH } /winapps ${ 1 } \"\$@\""
2024-07-14 23:10:10 +10:00
2024-07-17 00:07:49 +10:00
# Determine the content of the '.desktop' file for the application.
APP_DESKTOP_FILE = "\
2024-07-16 00:30:17 +10:00
[Desktop Entry]
Name= ${ NAME }
Exec= ${ BIN_PATH } /winapps ${ 1 } %F
Terminal=false
Type=Application
Icon= ${ APP_ICON }
StartupWMClass= ${ FULL_NAME }
Comment= ${ FULL_NAME }
Categories= ${ CATEGORIES }
MimeType= ${ MIME_TYPES } "
2024-07-14 23:10:10 +10:00
2024-07-17 00:07:49 +10:00
# Store the '.desktop' file for the application.
echo " $APP_DESKTOP_FILE " | $SUDO tee " ${ APP_PATH } / ${ 1 } .desktop" & >/dev/null
2024-07-14 23:10:10 +10:00
2024-07-17 00:07:49 +10:00
# Store the bash script for the application.
echo " $APP_BASH " | $SUDO tee " ${ BIN_PATH } / ${ 1 } " & >/dev/null
2024-07-14 23:10:10 +10:00
2024-07-17 00:07:49 +10:00
# Mark bash script as executable.
$SUDO chmod a+x " ${ BIN_PATH } / ${ 1 } "
2024-07-14 23:10:10 +10:00
}
# Name: 'waConfigureOfficiallySupported'
2024-07-18 18:27:07 +10:00
# Role: Create application entries for officially supported applications installed on Windows.
2024-07-14 23:10:10 +10:00
function waConfigureOfficiallySupported() {
2024-07-17 00:07:49 +10:00
# Declare variables.
2024-07-18 18:27:07 +10:00
local OSA_LIST =() # Stores a list of all officially supported applications installed on Windows.
2025-08-30 06:18:54 +00:00
local OFFICE_APPS =( "access" "access-o365" "access-o365-x86" "access-x86" "adobe-cc" "acrobat9" "acrobat-x-pro" "aftereffects-cc" "audition-cc" "bridge-cc" "bridge-cc-x86" "bridge-cs6" "bridge-cs6-x86" "cmd" "dymo-connect" "excel" "excel-o365" "excel-o365-x86" "excel-x86" "excel-x86-2010" "explorer" "iexplorer" "illustrator-cc" "lightroom-cc" "linqpad8" "mirc" "mspaint" "onenote" "onenote-o365" "onenote-o365-x86" "onenote-x86" "outlook" "outlook-o365" "outlook-o365-x86" "powerbi" "powerbi-store" "powerpoint" "powerpoint-o365" "powerpoint-o365-x86" "powerpoint-x86" "publisher" "publisher-o365" "publisher-o365-x86" "publisher-x86" "project" "project-x86" "remarkable-desktop" "ssms20" "visual-studio-comm" "visual-studio-ent" "visual-studio-pro" "visio" "visio-x86" "word" "word-o365" "word-o365-x86" "word-x86" "word-x86-2010" )
2024-07-14 23:10:10 +10:00
2024-07-18 18:27:07 +10:00
# Read the list of officially supported applications that are installed on Windows into an array, returning an empty array if no such files exist.
2024-07-17 00:07:49 +10:00
readarray -t OSA_LIST < <( grep -v '^[[:space:]]*$' " $INST_FILE_PATH " | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' 2>/dev/null || true )
2024-07-14 23:10:10 +10:00
2024-07-17 00:07:49 +10:00
# Create application entries for each officially supported application.
for OSA in " ${ OSA_LIST [@] } " ; do
2025-08-31 22:27:32 +10:00
# Split the line by the '|||' delimiter
local APP_NAME = " ${ OSA %%|||* } "
local ACTUAL_WIN_EXECUTABLE = " ${ OSA ##*||| } "
# If splitting failed for some reason, skip this line to be safe.
if [[ -z " $APP_NAME " || -z " $ACTUAL_WIN_EXECUTABLE " ]] ; then
continue
fi
# Print feedback using the clean application name.
echo -n "Creating an application entry for ${ APP_NAME } ... "
# Copy the original, unmodified application assets.
2025-10-25 15:26:13 +02:00
# --no-preserve=mode is needed to avoid missing write permissions when copying from Nix store.
$SUDO cp -r --no-preserve= mode "./apps/ ${ APP_NAME } " " ${ APPDATA_PATH } /apps"
2025-08-31 22:27:32 +10:00
local DESTINATION_INFO_FILE = " ${ APPDATA_PATH } /apps/ ${ APP_NAME } /info"
2024-07-14 23:10:10 +10:00
2025-08-31 22:27:32 +10:00
# Sanitize the string using pure Bash. This is fast and safe.
local SED_SAFE_PATH = " ${ ACTUAL_WIN_EXECUTABLE //&/ \\ & } "
SED_SAFE_PATH = " ${ SED_SAFE_PATH // \\ / \\\\ } "
2024-07-14 23:10:10 +10:00
2025-08-31 22:27:32 +10:00
# Use the sanitized string to safely edit the file.
$SUDO sed -i "s|^WIN_EXECUTABLE=.*|WIN_EXECUTABLE=\" ${ SED_SAFE_PATH } \"|" " $DESTINATION_INFO_FILE "
# Configure the application using the clean name.
waConfigureApp " $APP_NAME " svg
2024-07-14 23:10:10 +10:00
2025-05-15 14:01:17 +02:00
# Check if the application is an Office app and copy the protocol handler.
2025-08-31 22:27:32 +10:00
if [[ " ${ OFFICE_APPS [*] } " == *" $APP_NAME " * ]] ; then
2025-05-15 14:01:17 +02:00
# Determine the target directory based on whether the installation is for the system or user.
if [[ " $OPT_SYSTEM " -eq 1 ]] ; then
TARGET_DIR = " $SYS_APP_PATH "
else
TARGET_DIR = " $USER_APP_PATH "
fi
# Copy the protocol handler to the appropriate directory.
$SUDO cp "./apps/ms-office-protocol-handler.desktop" " $TARGET_DIR /ms-office-protocol-handler.desktop"
fi
2024-07-17 00:07:49 +10:00
# Print feedback.
echo -e " ${ DONE_TEXT } Done! ${ CLEAR_TEXT } "
done
2024-07-14 23:10:10 +10:00
2024-07-17 00:07:49 +10:00
# Delete 'install' file.
rm -f " $INST_FILE_PATH "
2024-07-14 23:10:10 +10:00
}
# Name: 'waConfigureApps'
# Role: Allow the user to select which officially supported applications to configure.
2020-11-13 10:45:07 -05:00
function waConfigureApps() {
2024-07-17 00:07:49 +10:00
# Declare variables.
2024-07-18 18:27:07 +10:00
local OSA_LIST =() # Stores a list of all officially supported applications installed on Windows.
2024-07-17 00:07:49 +10:00
local APPS =() # Stores a list of both the simplified and full names of each installed officially supported application.
local OPTIONS =() # Stores a list of options presented to the user.
local APP_INSTALL = "" # Stores the option selected by the user.
local SELECTED_APPS =() # Stores the officially supported applications selected by the user.
local TEMP_ARRAY =() # Temporary array used for sorting elements of an array.
2025-08-31 22:27:32 +10:00
declare -A APP_DATA_MAP # Associative array to map short names back to their full data line.
2024-07-17 00:07:49 +10:00
2024-07-18 18:27:07 +10:00
# Read the list of officially supported applications that are installed on Windows into an array, returning an empty array if no such files exist.
2024-07-17 00:07:49 +10:00
# This will remove leading and trailing whitespace characters as well as ignore empty lines.
readarray -t OSA_LIST < <( grep -v '^[[:space:]]*$' " $INST_FILE_PATH " | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' 2>/dev/null || true )
2024-07-18 18:27:07 +10:00
# Loop over each officially supported application installed on Windows.
2024-07-17 00:07:49 +10:00
for OSA in " ${ OSA_LIST [@] } " ; do
# Source 'Info' File Containing:
# - The Application Name (FULL_NAME)
2025-07-31 12:26:27 +10:00
# - The Shortcut Name (NAME)
2024-07-17 00:07:49 +10:00
# - Application Categories (CATEGORIES)
# - Executable Path (WIN_EXECUTABLE)
# - Supported MIME Types (MIME_TYPES)
# - Application Icon (ICON)
2025-08-31 22:27:32 +10:00
# Split the line to get the clean application name
local APP_NAME = " ${ OSA %%|||* } "
local ACTUAL_WIN_EXECUTABLE = " ${ OSA ##*|||* } "
# If splitting failed, skip this entry.
if [[ -z " $APP_NAME " ]] ; then
continue
fi
# Use the clean APP_NAME to source the info file
2024-07-17 00:07:49 +10:00
# shellcheck source=/dev/null # Exclude this file from being checked by ShellCheck.
2025-08-31 22:27:32 +10:00
source "./apps/ ${ APP_NAME } /info"
2024-07-17 00:07:49 +10:00
# Add both the simplified and full name of the application to an array.
2025-08-31 22:27:32 +10:00
APPS +=( " ${ FULL_NAME } ( ${ APP_NAME } )" )
# Store the original data line in our map so we can retrieve it later.
APP_DATA_MAP[ " $APP_NAME " ]= " $OSA "
2024-07-17 00:07:49 +10:00
# Extract the executable file name (e.g. 'MyApp.exe') from the absolute path.
2025-08-31 22:27:32 +10:00
WIN_EXECUTABLE = " ${ ACTUAL_WIN_EXECUTABLE ##* \\ } "
2024-07-17 00:07:49 +10:00
# Trim any leading or trailing whitespace characters from the executable file name.
read -r WIN_EXECUTABLE <<< " $( echo " $WIN_EXECUTABLE " | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' ) "
# Add the executable file name (in lowercase) to the array.
INSTALLED_EXES +=( " ${ WIN_EXECUTABLE ,, } " )
done
# Sort the 'APPS' array in alphabetical order.
IFS = $'\n'
# shellcheck disable=SC2207 # Silence warnings regarding preferred use of 'mapfile' or 'read -a'.
TEMP_ARRAY =( $( sort <<< " ${ APPS [*] } " ) )
unset IFS
APPS =( " ${ TEMP_ARRAY [@] } " )
# Prompt user to select which officially supported applications to configure.
OPTIONS =(
"Set up all detected officially supported applications"
"Choose specific officially supported applications to set up"
"Skip setting up any officially supported applications"
)
inqMenu "How would you like to handle officially supported applications?" OPTIONS APP_INSTALL
# Remove unselected officially supported applications from the 'install' file.
if [[ $APP_INSTALL == "Choose specific officially supported applications to set up" ]] ; then
inqChkBx "Which officially supported applications would you like to set up?" APPS SELECTED_APPS
# Clear/create the 'install' file.
echo "" >" $INST_FILE_PATH "
# Add each selected officially supported application back to the 'install' file.
for SELECTED_APP in " ${ SELECTED_APPS [@] } " ; do
# Capture the substring within (but not including) the parentheses.
# This substring represents the officially supported application name (see above loop).
2025-08-31 22:27:32 +10:00
local SHORT_NAME = " ${ SELECTED_APP ##*( } "
SHORT_NAME = " ${ SHORT_NAME %%) } "
2024-07-17 00:07:49 +10:00
2025-08-31 22:27:32 +10:00
# Use the map to find the original data line (e.g., "word|||C:\...") and write it back.
echo " ${ APP_DATA_MAP [ $SHORT_NAME ] } " >>" $INST_FILE_PATH "
2024-07-17 00:07:49 +10:00
done
fi
# Configure selected (or all) officially supported applications.
if [[ $APP_INSTALL != "Skip setting up any officially supported applications" ]] ; then
waConfigureOfficiallySupported
fi
2020-11-13 10:45:07 -05:00
}
2020-11-07 16:25:05 -05:00
2024-07-14 23:10:10 +10:00
# Name: 'waConfigureDetectedApps'
# Role: Allow the user to select which detected applications to configure.
2020-11-19 22:05:52 -05:00
function waConfigureDetectedApps() {
2024-07-17 00:07:49 +10:00
# Declare variables.
local APPS =() # Stores a list of both the simplified and full names of each detected application.
local EXE_FILENAME = "" # Stores the executable filename of a given detected application.
local EXE_FILENAME_NOEXT = "" # Stores the executable filename without the file extension of a given detected application.
local EXE_FILENAME_LOWERCASE = "" # Stores the executable filename of a given detected application in lowercase letters only.
local OPTIONS =() # Stores a list of options presented to the user.
local APP_INSTALL = "" # Stores the option selected by the user.
local SELECTED_APPS =() # Detected applications selected by the user.
local APP_DESKTOP_FILE = "" # Stores the '.desktop' file used to launch the application.
local TEMP_ARRAY =() # Temporary array used for sorting elements of an array.
if [ -f " $DETECTED_FILE_PATH " ] ; then
# On UNIX systems, lines are terminated with a newline character (\n).
# On WINDOWS systems, lines are terminated with both a carriage return (\r) and a newline (\n) character.
2024-07-18 18:27:07 +10:00
# Remove all carriage returns (\r) within the 'detected' file, as the file was written by Windows.
2024-07-17 00:07:49 +10:00
sed -i 's/\r//g' " $DETECTED_FILE_PATH "
# Import the detected application information:
# - Application Names (NAMES)
# - Application Icons in base64 (ICONS)
# - Application Executable Paths (EXES)
# shellcheck source=/dev/null # Exclude this file from being checked by ShellCheck.
source " $DETECTED_FILE_PATH "
# shellcheck disable=SC2153 # Silence warnings regarding possible misspellings.
for INDEX in " ${ !NAMES[@] } " ; do
# Extract the executable file name (e.g. 'MyApp.exe').
EXE_FILENAME = ${ EXES [ $INDEX ]##* \\ }
# Convert the executable file name to lower-case (e.g. 'myapp.exe').
EXE_FILENAME_LOWERCASE = " ${ EXE_FILENAME ,, } "
# Remove the file extension (e.g. 'MyApp').
EXE_FILENAME_NOEXT = " ${ EXE_FILENAME %.* } "
# Check if the executable was previously configured as part of setting up officially supported applications.
if [[ " ${ INSTALLED_EXES [*] } " != *" ${ EXE_FILENAME_LOWERCASE } " * ]] ; then
# If not previously configured, add the application to the list of detected applications.
APPS +=( " ${ NAMES [ $INDEX ] } ( ${ EXE_FILENAME_NOEXT } )" )
fi
done
# Sort the 'APPS' array in alphabetical order.
IFS = $'\n'
# shellcheck disable=SC2207 # Silence warnings regarding preferred use of 'mapfile' or 'read -a'.
TEMP_ARRAY =( $( sort <<< " ${ APPS [*] } " ) )
unset IFS
APPS =( " ${ TEMP_ARRAY [@] } " )
# Prompt user to select which other detected applications to configure.
OPTIONS =(
"Set up all detected applications"
"Select which applications to set up"
"Do not set up any applications"
)
inqMenu "How would you like to handle other detected applications?" OPTIONS APP_INSTALL
# Store selected detected applications.
if [[ $APP_INSTALL == "Select which applications to set up" ]] ; then
inqChkBx "Which other applications would you like to set up?" APPS SELECTED_APPS
elif [[ $APP_INSTALL == "Set up all detected applications" ]] ; then
2024-07-19 13:13:02 +10:00
for APP in " ${ APPS [@] } " ; do
SELECTED_APPS +=( " $APP " )
done
2024-07-17 00:07:49 +10:00
fi
for SELECTED_APP in " ${ SELECTED_APPS [@] } " ; do
# Capture the substring within (but not including) the parentheses.
# This substring represents the executable filename without the file extension (see above loop).
EXE_FILENAME_NOEXT = " ${ SELECTED_APP ##*( } "
EXE_FILENAME_NOEXT = " ${ EXE_FILENAME_NOEXT %%) } "
# Capture the substring prior to the space and parentheses.
# This substring represents the detected application name (see above loop).
PROGRAM_NAME = " ${ SELECTED_APP % (* } "
# Loop through all detected applications to find the detected application being processed.
for INDEX in " ${ !NAMES[@] } " ; do
# Check for a matching detected application entry.
if [[ ${ NAMES [ $INDEX ] } == " $PROGRAM_NAME " ]] && [[ ${ EXES [ $INDEX ] } == *"\\ $EXE_FILENAME_NOEXT " * ]] ; then
# Print feedback.
echo -n "Creating an application entry for ${ PROGRAM_NAME } ... "
# Create directory to store application icon and information.
$SUDO mkdir -p " ${ APPDATA_PATH } /apps/ ${ EXE_FILENAME_NOEXT } "
# Determine the content of the '.desktop' file for the application.
APP_DESKTOP_FILE = "\
2024-07-16 00:30:17 +10:00
# GNOME Shortcut Name
NAME=\" ${ PROGRAM_NAME } \"
# Used for Descriptions and Window Class
FULL_NAME=\" ${ PROGRAM_NAME } \"
2024-07-18 18:27:07 +10:00
# Path to executable inside Windows
2024-07-16 00:30:17 +10:00
WIN_EXECUTABLE=\" ${ EXES [ $INDEX ] } \"
# GNOME Categories
CATEGORIES=\"WinApps\"
# GNOME MIME Types
MIME_TYPES=\"\""
2024-07-15 11:36:41 +10:00
2024-07-17 00:07:49 +10:00
# Store the '.desktop' file for the application.
echo " $APP_DESKTOP_FILE " | $SUDO tee " ${ APPDATA_PATH } /apps/ ${ EXE_FILENAME_NOEXT } /info" & >/dev/null
2024-07-14 23:10:10 +10:00
2024-07-17 00:07:49 +10:00
# Write application icon to file.
2024-08-03 21:35:06 +10:00
echo " ${ ICONS [ $INDEX ] } " | base64 -d | $SUDO tee " ${ APPDATA_PATH } /apps/ ${ EXE_FILENAME_NOEXT } /icon.png" & >/dev/null
2024-07-14 23:10:10 +10:00
2024-07-17 00:07:49 +10:00
# Configure the application.
2024-08-03 21:35:06 +10:00
waConfigureApp " $EXE_FILENAME_NOEXT " png
2024-07-14 23:10:10 +10:00
2024-07-17 00:07:49 +10:00
# Print feedback.
echo -e " ${ DONE_TEXT } Done! ${ CLEAR_TEXT } "
fi
done
done
fi
2020-11-19 22:05:52 -05:00
}
2024-07-14 23:10:10 +10:00
# Name: 'waInstall'
# Role: Installs WinApps.
function waInstall() {
2024-07-17 00:07:49 +10:00
# Print feedback.
echo -e " ${ BOLD_TEXT } Installing WinApps. ${ CLEAR_TEXT } "
2024-07-14 23:10:10 +10:00
2024-07-17 00:07:49 +10:00
# Check for existing conflicting WinApps installations.
waCheckExistingInstall
2024-07-14 23:10:10 +10:00
2024-07-17 00:07:49 +10:00
# Load the WinApps configuration file.
waLoadConfig
2024-07-14 23:10:10 +10:00
2024-07-17 00:07:49 +10:00
# Check for missing dependencies.
2024-07-23 17:14:43 +10:00
waCheckInstallDependencies
2024-07-14 23:10:10 +10:00
2026-10-27 10:16:40 -04:00
# Resolve RemoteApp and full-desktop scale settings.
waFixScale || return " $? "
2024-07-17 22:01:40 +10:00
2024-07-17 00:07:49 +10:00
# Append additional FreeRDP flags if required.
if [[ -n $RDP_FLAGS ]] ; then
FREERDP_COMMAND = " ${ FREERDP_COMMAND } ${ RDP_FLAGS } "
fi
2020-11-13 10:45:07 -05:00
2024-07-19 13:13:02 +10:00
# If using 'docker' or 'podman', set RDP_IP to localhost.
if [ " $WAFLAVOR " = "docker" ] || [ " $WAFLAVOR " = "podman" ] ; then
2024-07-17 18:51:22 +10:00
RDP_IP = " $DOCKER_IP "
2024-07-19 13:13:02 +10:00
fi
if [ " $WAFLAVOR " = "docker" ] || [ " $WAFLAVOR " = "podman" ] ; then
2024-07-18 18:27:07 +10:00
# Check if Windows is powered on.
2024-07-17 18:51:22 +10:00
waCheckContainerRunning
elif [ " $WAFLAVOR " = "libvirt" ] ; then
2024-07-19 13:13:02 +10:00
# Verify the current user's group membership.
2024-07-23 17:14:43 +10:00
waCheckGroupMembership
2024-06-09 13:35:53 +02:00
2024-07-17 18:51:22 +10:00
# Check if the Windows VM is powered on.
waCheckVMRunning
2024-08-08 13:53:21 +02:00
elif [ " $WAFLAVOR " = "manual" ] ; then
2024-08-08 14:11:40 +02:00
waCheckPortOpen
2024-07-17 18:51:22 +10:00
else
2024-07-19 13:13:02 +10:00
# Display the error type.
echo -e " ${ ERROR_TEXT } ERROR: ${ CLEAR_TEXT } ${ BOLD_TEXT } INVALID WINAPPS BACKEND. ${ CLEAR_TEXT } "
# Display the error details.
echo -e " ${ INFO_TEXT } An invalid WinApps backend ' ${ WAFLAVOR } ' was specified. ${ CLEAR_TEXT } "
# Display the suggested action(s).
echo "--------------------------------------------------------------------------------"
echo -e "Please ensure 'WAFLAVOR' is set to 'docker', 'podman' or 'libvirt' in ${ COMMAND_TEXT }${ CONFIG_PATH }${ CLEAR_TEXT } ."
echo "--------------------------------------------------------------------------------"
# Terminate the script.
return " $EC_INVALID_FLAVOR "
2024-07-17 18:51:22 +10:00
fi
2024-07-14 23:10:10 +10:00
2026-08-09 17:48:48 +02:00
# Determine how FreeRDP can reach the RDP port of the Windows container.
if [ " $WAFLAVOR " = "podman" ] ; then
waSelectPodmanRoute
else
# Check if the RDP port on Windows is open.
waCheckPortOpen
fi
2024-07-18 18:27:07 +10:00
# Test RDP access to Windows.
2024-07-17 00:07:49 +10:00
waCheckRDPAccess
2024-07-14 23:10:10 +10:00
2024-07-17 00:07:49 +10:00
# Create required directories.
$SUDO mkdir -p " $BIN_PATH "
$SUDO mkdir -p " $APP_PATH "
$SUDO mkdir -p " $APPDATA_PATH /apps"
$SUDO mkdir -p " $APPDATA_PATH /icons"
2024-07-14 23:10:10 +10:00
2024-07-17 00:07:49 +10:00
# Check for installed applications.
waFindInstalled
2024-07-14 23:10:10 +10:00
2024-08-28 16:03:17 +02:00
# Install the WinApps bash scripts.
2024-09-08 23:19:32 -04:00
$SUDO ln -sf " ${ SOURCE_PATH } /bin/winapps" " ${ BIN_PATH } /winapps"
$SUDO ln -sf " ${ SOURCE_PATH } /setup.sh" " ${ BIN_PATH } /winapps-setup"
2024-07-14 23:10:10 +10:00
2024-07-18 18:27:07 +10:00
# Configure the Windows RDP session application launcher.
2024-07-17 00:07:49 +10:00
waConfigureWindows
2024-07-14 23:10:10 +10:00
2024-07-17 00:07:49 +10:00
if [ " $OPT_AOSA " -eq 1 ] ; then
# Automatically configure all officially supported applications.
waConfigureOfficiallySupported
else
# Configure officially supported applications.
waConfigureApps
2024-07-14 23:10:10 +10:00
2024-07-17 00:07:49 +10:00
# Configure other detected applications.
waConfigureDetectedApps
fi
2024-07-14 23:10:10 +10:00
2024-08-28 16:03:17 +02:00
# Ensure BIN_PATH is on PATH
waEnsureOnPath
2024-07-17 00:07:49 +10:00
# Print feedback.
echo -e " ${ SUCCESS_TEXT } INSTALLATION COMPLETE. ${ CLEAR_TEXT } "
2020-11-13 13:13:32 -05:00
}
2024-08-28 16:03:17 +02:00
# Name: 'waEnsureOnPath'
# Role: Ensures that $BIN_PATH is on $PATH.
function waEnsureOnPath() {
2025-01-15 23:20:17 +05:30
if [[ ": $PATH :" != *": $BIN_PATH :" * ]] ; then
2024-08-28 16:03:17 +02:00
echo -e " ${ WARNING_TEXT } [WARNING] ${ CLEAR_TEXT } It seems like ' ${ BIN_PATH } ' is not on PATH."
echo -e " ${ WARNING_TEXT } [WARNING] ${ CLEAR_TEXT } You can add it by running:"
# shellcheck disable=SC2086
2025-02-02 17:42:24 +11:00
echo -e " ${ WARNING_TEXT } [WARNING] ${ CLEAR_TEXT } - For Bash: ${ COMMAND_TEXT } echo 'export PATH=" ${ BIN_PATH } :\$ PATH"' >> ~/.bashrc && source ~/.bashrc ${ CLEAR_TEXT } "
2024-08-28 16:03:17 +02:00
# shellcheck disable=SC2086
2025-02-02 17:42:24 +11:00
echo -e " ${ WARNING_TEXT } [WARNING] ${ CLEAR_TEXT } - For ZSH: ${ COMMAND_TEXT } echo 'export PATH=" ${ BIN_PATH } :\$ PATH"' >> ~/.zshrc && source ~/.zshrc ${ CLEAR_TEXT } "
2024-08-28 16:03:17 +02:00
echo -e " ${ WARNING_TEXT } [WARNING] ${ CLEAR_TEXT } Make sure to restart your Terminal afterwards.\n"
fi
}
2024-07-14 23:10:10 +10:00
# Name: 'waUninstall'
# Role: Uninstalls WinApps.
function waUninstall() {
2025-05-15 14:26:57 +00:00
2024-07-17 00:07:49 +10:00
# Print feedback.
[ " $OPT_SYSTEM " -eq 1 ] && echo -e " ${ BOLD_TEXT } REMOVING SYSTEM INSTALLATION. ${ CLEAR_TEXT } "
[ " $OPT_USER " -eq 1 ] && echo -e " ${ BOLD_TEXT } REMOVING USER INSTALLATION. ${ CLEAR_TEXT } "
2024-06-09 13:35:53 +02:00
2025-05-15 14:01:17 +02:00
# Determine the target directory for the protocol handler based on the installation type.
if [[ " $OPT_SYSTEM " -eq 1 ]] ; then
TARGET_DIR = " $SYS_APP_PATH "
else
TARGET_DIR = " $USER_APP_PATH "
fi
# Remove the 'ms-office-protocol-handler.desktop' file if it exists.
$SUDO rm -f " $TARGET_DIR /ms-office-protocol-handler.desktop"
2024-07-17 00:07:49 +10:00
# Declare variables.
local WINAPPS_DESKTOP_FILES =() # Stores a list of '.desktop' file paths.
local WINAPPS_APP_BASH_SCRIPTS =() # Stores a list of bash script paths.
local DESKTOP_FILE_NAME = "" # Stores the name of the '.desktop' file for the application.
local BASH_SCRIPT_NAME = "" # Stores the name of the application.
2024-07-14 23:10:10 +10:00
2024-08-28 16:03:17 +02:00
# Remove the 'WinApps' bash scripts.
2024-07-17 00:07:49 +10:00
$SUDO rm -f " ${ BIN_PATH } /winapps"
2024-08-28 16:03:17 +02:00
$SUDO rm -f " ${ BIN_PATH } /winapps-setup"
2024-07-14 23:10:10 +10:00
2024-07-17 00:07:49 +10:00
# Remove WinApps configuration data, temporary files and logs.
rm -rf " $USER_APPDATA_PATH "
2024-07-14 23:10:10 +10:00
2024-07-17 00:07:49 +10:00
# Remove application icons and shortcuts.
$SUDO rm -rf " $APPDATA_PATH "
2024-07-14 23:10:10 +10:00
2024-07-17 00:07:49 +10:00
# Store '.desktop' files containing "${BIN_PATH}/winapps" in an array, returning an empty array if no such files exist.
readarray -t WINAPPS_DESKTOP_FILES < <( grep -l -d skip " ${ BIN_PATH } /winapps" " ${ APP_PATH } /" * 2>/dev/null || true )
2024-07-14 23:10:10 +10:00
2024-07-17 00:07:49 +10:00
# Remove each '.desktop' file.
for DESKTOP_FILE_PATH in " ${ WINAPPS_DESKTOP_FILES [@] } " ; do
# Trim leading and trailing whitespace from '.desktop' file path.
DESKTOP_FILE_PATH = $( echo " $DESKTOP_FILE_PATH " | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' )
2024-07-14 23:10:10 +10:00
2024-07-17 00:07:49 +10:00
# Extract the file name.
DESKTOP_FILE_NAME = $( basename " $DESKTOP_FILE_PATH " | sed 's/\.[^.]*$//' )
2024-07-14 23:10:10 +10:00
2024-07-17 00:07:49 +10:00
# Print feedback.
echo -n "Removing '.desktop' file for ' ${ DESKTOP_FILE_NAME } '... "
2024-07-15 23:44:16 +10:00
2024-07-17 00:07:49 +10:00
# Delete the file.
$SUDO rm " $DESKTOP_FILE_PATH "
2024-07-14 23:10:10 +10:00
2024-07-17 00:07:49 +10:00
# Print feedback.
echo -e " ${ DONE_TEXT } Done! ${ CLEAR_TEXT } "
done
2024-06-09 13:35:53 +02:00
2024-07-17 00:07:49 +10:00
# Store the paths of bash scripts calling 'WinApps' to launch specific applications in an array, returning an empty array if no such files exist.
readarray -t WINAPPS_APP_BASH_SCRIPTS < <( grep -l -d skip " ${ BIN_PATH } /winapps" " ${ BIN_PATH } /" * 2>/dev/null || true )
2024-07-14 23:10:10 +10:00
2024-07-17 00:07:49 +10:00
# Remove each bash script.
for BASH_SCRIPT_PATH in " ${ WINAPPS_APP_BASH_SCRIPTS [@] } " ; do
# Trim leading and trailing whitespace from bash script path.
BASH_SCRIPT_PATH = $( echo " $BASH_SCRIPT_PATH " | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' )
2024-07-14 23:10:10 +10:00
2024-07-17 00:07:49 +10:00
# Extract the file name.
BASH_SCRIPT_NAME = $( basename " $BASH_SCRIPT_PATH " | sed 's/\.[^.]*$//' )
2024-07-14 23:10:10 +10:00
2024-07-17 00:07:49 +10:00
# Print feedback.
echo -n "Removing bash script for ' ${ BASH_SCRIPT_NAME } '... "
2024-07-15 23:44:16 +10:00
2024-07-17 00:07:49 +10:00
# Delete the file.
$SUDO rm " $BASH_SCRIPT_PATH "
2024-07-14 23:10:10 +10:00
2024-07-17 00:07:49 +10:00
# Print feedback.
echo -e " ${ DONE_TEXT } Done! ${ CLEAR_TEXT } "
done
2020-11-13 13:13:32 -05:00
2024-07-17 00:07:49 +10:00
# Print caveats.
2024-08-28 16:03:17 +02:00
echo -e "\n ${ INFO_TEXT } Please note that your WinApps configuration and the WinApps source code were not removed. ${ CLEAR_TEXT } "
echo -e " ${ INFO_TEXT } You can remove these manually by running: ${ CLEAR_TEXT } "
echo -e " ${ COMMAND_TEXT } rm -r $( dirname " $CONFIG_PATH " ) ${ CLEAR_TEXT } "
echo -e " ${ COMMAND_TEXT } rm -r ${ SOURCE_PATH }${ CLEAR_TEXT } \n"
2026-01-25 12:40:33 +01:00
# Print feedback.
echo -e " ${ SUCCESS_TEXT } UNINSTALLATION COMPLETE. ${ CLEAR_TEXT } "
2026-01-24 17:03:17 +01:00
}
2020-11-19 08:17:44 -05:00
2026-01-24 17:03:17 +01:00
# Name: 'waAddApps'
# Role: Adds new applications to an existing WinApps installation.
function waAddApps() {
2024-07-17 00:07:49 +10:00
# Print feedback.
2026-01-24 17:03:17 +01:00
echo -e " ${ BOLD_TEXT } Adding new applications to existing WinApps installation. ${ CLEAR_TEXT } "
# Load the WinApps configuration file.
waLoadConfig
# Check for missing dependencies.
waCheckInstallDependencies
2026-10-27 10:16:40 -04:00
# Resolve RemoteApp and full-desktop scale settings.
waFixScale || return " $? "
2026-01-24 17:03:17 +01:00
# Append additional FreeRDP flags if required.
if [[ -n $RDP_FLAGS ]] ; then
FREERDP_COMMAND = " ${ FREERDP_COMMAND } ${ RDP_FLAGS } "
fi
# If using 'docker' or 'podman', set RDP_IP to localhost.
if [ " $WAFLAVOR " = "docker" ] || [ " $WAFLAVOR " = "podman" ] ; then
RDP_IP = " $DOCKER_IP "
fi
if [ " $WAFLAVOR " = "docker" ] || [ " $WAFLAVOR " = "podman" ] ; then
# Check if Windows is powered on.
waCheckContainerRunning
elif [ " $WAFLAVOR " = "libvirt" ] ; then
# Verify the current user's group membership.
waCheckGroupMembership
# Check if the Windows VM is powered on.
waCheckVMRunning
elif [ " $WAFLAVOR " = "manual" ] ; then
waCheckPortOpen
else
# Display the error type.
echo -e " ${ ERROR_TEXT } ERROR: ${ CLEAR_TEXT } ${ BOLD_TEXT } INVALID WINAPPS BACKEND. ${ CLEAR_TEXT } "
# Display the error details.
echo -e " ${ INFO_TEXT } An invalid WinApps backend ' ${ WAFLAVOR } ' was specified. ${ CLEAR_TEXT } "
# Display the suggested action(s).
echo "--------------------------------------------------------------------------------"
echo -e "Please ensure 'WAFLAVOR' is set to 'docker', 'podman' or 'libvirt' in ${ COMMAND_TEXT }${ CONFIG_PATH }${ CLEAR_TEXT } ."
echo "--------------------------------------------------------------------------------"
# Terminate the script.
return " $EC_INVALID_FLAVOR "
fi
2026-08-09 17:48:48 +02:00
# Determine how FreeRDP can reach the RDP port of the Windows container.
if [ " $WAFLAVOR " = "podman" ] ; then
waSelectPodmanRoute
else
# Check if the RDP port on Windows is open.
waCheckPortOpen
fi
2026-01-24 17:03:17 +01:00
# Test RDP access to Windows.
waCheckRDPAccess
# Check for installed applications.
waFindInstalled
# Configure officially supported applications.
waConfigureApps
# Configure other detected applications.
waConfigureDetectedApps
# Print feedback.
echo -e " ${ SUCCESS_TEXT } ADDING NEW APPS COMPLETE. ${ CLEAR_TEXT } "
2024-07-14 23:10:10 +10:00
}
2020-11-13 10:45:07 -05:00
2026-01-24 17:03:17 +01:00
2024-07-14 23:10:10 +10:00
### SEQUENTIAL LOGIC ###
# Welcome the user.
echo -e " ${ BOLD_TEXT } \
2024-07-16 00:30:17 +10:00
################################################################################
2024-07-14 23:10:10 +10:00
# #
# WinApps Install Wizard #
# #
################################################################################
${ CLEAR_TEXT } "
2020-11-13 13:13:32 -05:00
2024-07-23 17:14:43 +10:00
# Check dependencies for the script.
waCheckScriptDependencies
2024-07-14 23:10:10 +10:00
# Source the contents of 'inquirer.sh'.
2024-08-30 13:01:05 +02:00
waGetInquirer
2020-11-13 10:45:07 -05:00
2024-07-14 23:10:10 +10:00
# Sanitise and parse the user input.
waCheckInput " $@ "
2020-11-13 10:45:07 -05:00
2024-07-14 23:10:10 +10:00
# Configure paths and permissions.
waConfigurePathsAndPermissions
2020-11-07 16:25:05 -05:00
2024-08-30 13:01:05 +02:00
# Get the source code
waGetSourceCode
2024-07-14 23:10:10 +10:00
# Install or uninstall WinApps.
if [ " $OPT_UNINSTALL " -eq 1 ] ; then
2024-07-17 00:07:49 +10:00
waUninstall
2026-01-24 17:03:17 +01:00
elif [ " $OPT_ADD_APPS " -eq 1 ] ; then
waAddApps
2024-07-14 23:10:10 +10:00
else
2024-07-17 00:07:49 +10:00
waInstall
2024-07-14 23:10:10 +10:00
fi
2020-11-19 22:05:52 -05:00
2024-07-14 23:10:10 +10:00
exit 0