Minor optimisations to 'waCheckContainerRunning'.

This commit is contained in:
Rohan Barar 2024-07-24 16:33:05 +10:00
parent 25b241b12d
commit ba86f338bf

View File

@ -72,16 +72,17 @@ readonly INQUIRER_PATH="./install/inquirer.sh" # UNIX path to the 'inquirer' scr
readonly VM_NAME="RDPWindows" # Name of the Windows VM (FOR 'libvirt' ONLY). readonly VM_NAME="RDPWindows" # Name of the Windows VM (FOR 'libvirt' ONLY).
readonly RDP_PORT=3389 # Port used for RDP on Windows. readonly RDP_PORT=3389 # Port used for RDP on Windows.
readonly DOCKER_IP="127.0.0.1" # Localhost. readonly DOCKER_IP="127.0.0.1" # Localhost.
RDP_USER="" readonly WINAPPS_CONFIG="\
RDP_PASS="" RDP_USER=\"MyWindowsUser\"
#RDP_DOMAIN="MYDOMAIN" RDP_PASS=\"MyWindowsPassword\"
#RDP_IP="192.168.123.111" #RDP_DOMAIN=\"MYDOMAIN\"
#WAFLAVOR="docker" # Acceptable values are 'docker', 'podman' and 'libvirt'. #RDP_IP=\"192.168.123.111\"
#WAFLAVOR=\"docker\" # Acceptable values are 'docker', 'podman' and 'libvirt'.
#RDP_SCALE=100 # Acceptable values are 100, 140, and 180. #RDP_SCALE=100 # Acceptable values are 100, 140, and 180.
#RDP_FLAGS="" #RDP_FLAGS=\"\"
#MULTIMON="true" #MULTIMON=\"true\"
#DEBUG="true" #DEBUG=\"true\"
#FREERDP_COMMAND="xfreerdp"' # Default WinApps configuration file content. #FREERDP_COMMAND=\"xfreerdp\""
### GLOBAL VARIABLES ### ### GLOBAL VARIABLES ###
# USER INPUT # USER INPUT
@ -807,16 +808,19 @@ function waCheckContainerRunning() {
# Declare variables. # Declare variables.
local CONTAINER_STATE="" local CONTAINER_STATE=""
local COMPOSE_COMMAND=""
if [[ "$WAFLAVOR" == "docker" ]]; then # Determine the state of the container.
CONTAINER_STATE=$(docker ps --filter name="WinApps" --format '{{.Status}}') CONTAINER_STATE=$("$WAFLAVOR" ps --all --filter name="WinApps" --format '{{.Status}}')
elif [[ "$WAFLAVOR" == "podman" ]]; then
CONTAINER_STATE=$(podman ps --filter name="WinApps" --format '{{.Status}}')
fi
CONTAINER_STATE=${CONTAINER_STATE,,} # Convert the string to lowercase. CONTAINER_STATE=${CONTAINER_STATE,,} # Convert the string to lowercase.
CONTAINER_STATE=${CONTAINER_STATE%% *} # Extract the first word. CONTAINER_STATE=${CONTAINER_STATE%% *} # Extract the first word.
# Determine the compose command.
case "$WAFLAVOR" in
"docker") COMPOSE_COMMAND="docker compose" ;;
"podman") COMPOSE_COMMAND="podman-compose" ;;
esac
# Check container state. # Check container state.
if [[ "$CONTAINER_STATE" != "up" ]]; then if [[ "$CONTAINER_STATE" != "up" ]]; then
# Complete the previous line. # Complete the previous line.
@ -831,8 +835,7 @@ function waCheckContainerRunning() {
# Display the suggested action(s). # Display the suggested action(s).
echo "--------------------------------------------------------------------------------" echo "--------------------------------------------------------------------------------"
echo "Please ensure Windows is powered on:" echo "Please ensure Windows is powered on:"
echo -e "${COMMAND_TEXT}docker compose --file ~/.config/winapps/winapps.conf start${CLEAR_TEXT} # Docker" echo -e "${COMMAND_TEXT}${COMPOSE_COMMAND} --file ~/.config/winapps/winapps.conf start${CLEAR_TEXT}"
echo -e "${COMMAND_TEXT}podman-compose --file ~/.config/winapps/winapps.conf start${CLEAR_TEXT} # Podman"
echo "--------------------------------------------------------------------------------" echo "--------------------------------------------------------------------------------"
# Terminate the script. # Terminate the script.