1
0
mirror of synced 2026-04-28 04:55:54 +00:00

First pass - adding linux support to --vnc arg to medley script

This commit is contained in:
Frank Halasz
2024-09-08 22:08:43 -07:00
parent f03a2fb4cb
commit ca03e7f930
6 changed files with 202 additions and 82 deletions

View File

@@ -318,15 +318,20 @@ IL_DIR="$(cd "${MEDLEYDIR}/.."; pwd)"
wsl=false wsl=false
darwin=false darwin=false
cygwin=false cygwin=false
linux=false
platform=unknown
if [ "$(uname)" = "Darwin" ] if [ "$(uname)" = "Darwin" ]
then then
darwin=true darwin=true
platform=darwin
elif [ "$(uname -s | head --bytes 6)" = "CYGWIN" ] elif [ "$(uname -s | head --bytes 6)" = "CYGWIN" ]
then then
cygwin=true cygwin=true
platform=cgwin
elif [ -e "/proc/version" ] && grep --ignore-case --quiet Microsoft /proc/version elif [ -e "/proc/version" ] && grep --ignore-case --quiet Microsoft /proc/version
then then
platform=wsl
wsl=true wsl=true
wsl_ver=0 wsl_ver=0
# WSL2 # WSL2
@@ -351,7 +356,19 @@ Exiting"
fi fi
fi fi
fi fi
else
linux=true
platform=linux
fi fi
#################### TEST CODE ####################
#wsl=false
#darwin=false
#cygwin=false
#linux=true
#platform=linux
#################### TEST CODE ####################
# process config file and args # process config file and args
# shellcheck source=./medley_configfile.sh # shellcheck source=./medley_configfile.sh
@@ -552,8 +569,8 @@ flags:
-t STRING | --title STRING : use STRING as title of window -t STRING | --title STRING : use STRING as title of window
-d :N | --display :N : use X display :N -d :N | --display :N : use X display :N
+w
+w -v | --vnc : (WSL only) Use a VNC window instead of an X window -v | --vnc : Use a VNC window instead of an X window (Not available: MacOS & Windows/Cygwin)
-i STRING | --id STRING : use STRING as the id for this run of Medley (default: default) -i STRING | --id STRING : use STRING as the id for this run of Medley (default: default)
@@ -805,13 +822,32 @@ do
use_vnc=true use_vnc=true
;; ;;
esac esac
if [ "${use_vnc}" = true ] && { [ ! "${wsl}" = true ] || [ ! "$(uname -m)" = x86_64 ] ; } if [ "${use_vnc}" = true ]
then then
echo "Warning: The -v or --vnc flag was set." case ${platform} in
echo "But the vnc option is only available when running on " darwin)
echo "Windows System for Linux (wsl) on x86_64 machines." echo "Warning The -v (--vnc) flag was set, but the vnc option is"
echo "Ignoring the -v or --vnc flag." echo "not available on MacOS. Ignoring the -v (--vnc) flag."
use_vnc=false use_vnc=false
;;
cygwin)
echo "Warning The -v (--vnc) flag was set, but the vnc option is"
echo "not available on Windows (Cygwin). Ignoring the -v (--vnc) flag."
use_vnc=false
;;
wsl)
if [ ! "$(uname -m)" = x86_64 ]
then
echo "Warning: The -v or --vnc flag was set."
echo "But the vnc option is only available when running on "
echo "Windows System for Linux (wsl) on x86_64 machines."
echo "Ignoring the -v or --vnc flag."
use_vnc=false
fi
;;
linux)
;;
esac
fi fi
;; ;;
-x | --logindir) -x | --logindir)
@@ -1380,9 +1416,9 @@ fi
# Run maiko either directly or with vnc # Run maiko either directly or with vnc
if [ "${wsl}" = true ] && [ "${use_vnc}" = true ] if [ "${use_vnc}" = true ]
then then
# do the vnc thing on wsl (if called for) # do the vnc thing - if called for
# shellcheck source=./medley_vnc.sh # shellcheck source=./medley_vnc.sh
# . "${SCRIPTDIR}/medley_vnc.sh" # . "${SCRIPTDIR}/medley_vnc.sh"
# shellcheck shell=sh # shellcheck shell=sh
@@ -1402,9 +1438,14 @@ then
# Copyright 2023 Interlisp.org # Copyright 2023 Interlisp.org
# #
############################################################################### ###############################################################################
#set -x
ip_addr() { ip_addr() {
ip -4 -br address show dev eth0 | awk '{print $3}' | sed 's-/.*$--' if [ "${wsl}" = true ]
then
ip -4 -br address show dev eth0 | awk '{print $3}' | sed 's-/.*$--'
else
echo "127.0.0.1"
fi
} }
find_open_display() { find_open_display() {
@@ -1446,21 +1487,39 @@ then
} }
# #
# Make sure prequisites for vnc support in wsl are in place # Make sure prequisites for vnc support are in place
# #
if [ "${use_vnc}" = "true" ]; if [ -z "$(which Xvnc)" ] || [ "$(Xvnc -version 2>&1 | grep -iq tigervnc; echo $?)" -eq 1 ]
then
echo "Error: The -v or --vnc flag was set."
echo "But it appears that that TigerVNC server \(Xvnc\) has not been installed."
echo "Please install the TigerVNC server and try again. On Debian and Ubuntu, use:"
echo "\"sudo apt install tigervnc-standalone-server\". On most other Linux distros, use the"
echo "distro's package manager to install the \"tigervnc-server\" package."
echo "Exiting."
exit 4
fi
if [ "${linux}" = "true" ]
then
if [ -z "$(which vncviewer)" ] || [ "$(vncviewer -v 2>&1 | head -2 | grep -iq tigervnc; echo $?)" -eq 1 ]
then
echo "Error: The -v or --vnc flag was set."
echo "But it appears that that the TigerVNC viewer \(vncviewer\) is not installed on your system."
echo "Please install the TigerVNC viewer and try again. On Debian and Ubuntu, use:"
echo "\"sudo apt install tigervnc-viewer\". On most other Linux distros, use the"
echo "the distro's package manager to install the \"tigervnc-viewer\" (or sometimes just \"tigervnc\")"
echo "package."
echo "Exiting."
exit 5
else
vncviewer="$(which vncviewer)"
fi
elif [ "${wsl}" = "true" ]
then then
win_userprofile="$(cmd.exe /c "<nul set /p=%UserProfile%" 2>/dev/null)" win_userprofile="$(cmd.exe /c "<nul set /p=%UserProfile%" 2>/dev/null)"
vnc_dir="$(wslpath "${win_userprofile}")/AppData/Local/Interlisp" vnc_dir="$(wslpath "${win_userprofile}")/AppData/Local/Interlisp"
vnc_exe="vncviewer64-1.12.0.exe" vnc_exe="vncviewer64-1.12.0.exe"
if [ "$(which Xvnc)" = "" ] || [ "$(Xvnc -version 2>&1 | grep -iq tigervnc; echo $?)" -eq 1 ] if [ ! -e "${vnc_dir}/${vnc_exe}" ];
then
echo "Error: The -v or --vnc flag was set."
echo "But it appears that that TigerVNC \(Xvnc\) has not been installed."
echo "Please install TigerVNC using \"sudo apt install tigervnc-standalone-server tigervnc-xorg-extension\""
echo "Exiting."
exit 4
elif [ ! -e "${vnc_dir}/${vnc_exe}" ];
then then
if [ -e "${IL_DIR}/wsl/${vnc_exe}" ]; if [ -e "${IL_DIR}/wsl/${vnc_exe}" ];
then then
@@ -1494,6 +1553,7 @@ then
done done
fi fi
fi fi
vncviewer="${vnc_dir}/${vnc_exe}"
fi fi
# #
# Start the log file so we can trace any issues with vnc, etc # Start the log file so we can trace any issues with vnc, etc
@@ -1513,6 +1573,7 @@ then
# find an unused display and an available port # find an unused display and an available port
# #
#set -x #set -x
ORIGINAL_DISPLAY="${DISPLAY}"
OPEN_DISPLAY="$(find_open_display)" OPEN_DISPLAY="$(find_open_display)"
if [ "${OPEN_DISPLAY}" -eq -1 ]; if [ "${OPEN_DISPLAY}" -eq -1 ];
then then
@@ -1539,15 +1600,15 @@ then
# Start the Xvnc server # Start the Xvnc server
# #
mkdir -p "${LOGINDIR}"/logs mkdir -p "${LOGINDIR}"/logs
/usr/bin/Xvnc "${DISPLAY}" \ Xvnc "${DISPLAY}" \
-rfbport "${VNC_PORT}" \ -rfbport "${VNC_PORT}" \
-geometry "${geometry}" \ -geometry "${geometry}" \
-SecurityTypes None \ -SecurityTypes None \
-NeverShared \ -NeverShared \
-DisconnectClients=0 \ -DisconnectClients=0 \
-desktop "${title}" \ -desktop "${title}" \
--MaxDisconnectionTime=10 \ --MaxDisconnectionTime=10 \
>> "${LOG}" 2>&1 & >> "${LOG}" 2>&1 &
sleep .5 sleep .5
# #
@@ -1557,25 +1618,24 @@ then
start_maiko "$@" start_maiko "$@"
if [ -n "$(pgrep -f "${vnc_exe}.*:${VNC_PORT}")" ]; then vncconfig -disconnect; fi if [ -n "$(pgrep -f "${vnc_exe}.*:${VNC_PORT}")" ]; then vncconfig -disconnect; fi
} & } &
# #
# Start the vncviewer on the windows side # Start the vncviewer
# #
# First give medley time to startup # First give medley time to startup
# sleep .25 # sleep .25
# SLeep appears not to be needed, but faster/slower machines ???? # Sleep appears not to be needed, but faster/slower machines ????
# FGH 2023-02-08 # FGH 2023-02-08
# Then start vnc viewer on Windows side # Then start vnc viewer
vncv_loc=$(( OPEN_DISPLAY * 50 )) vncv_loc=$(( OPEN_DISPLAY * 50 ))
start_time=$(date +%s) start_time=$(date +%s)
"${vnc_dir}"/${vnc_exe} \ export DISPLAY="${ORIGINAL_DISPLAY}"
-geometry "+${vncv_loc}+${vncv_loc}" \ "${vncviewer}" -geometry "+${vncv_loc}+${vncv_loc}" \
-ReconnectOnError=off \ AlertOnFatalError=0 \
AlertOnFatalError=off \ -ReconnectOnError=0 \
"$(ip_addr)":"${VNC_PORT}" \ "$(ip_addr)":"${VNC_PORT}" \
>>"${LOG}" 2>&1 & >>"${LOG}" 2>&1 &
wait $! wait $!
if [ $(( $(date +%s) - start_time )) -lt 5 ] if [ $(( $(date +%s) - start_time )) -lt 5 ]
then then

View File

@@ -239,13 +239,32 @@ do
use_vnc=true use_vnc=true
;; ;;
esac esac
if [ "${use_vnc}" = true ] && { [ ! "${wsl}" = true ] || [ ! "$(uname -m)" = x86_64 ] ; } if [ "${use_vnc}" = true ]
then then
echo "Warning: The -v or --vnc flag was set." case ${platform} in
echo "But the vnc option is only available when running on " darwin)
echo "Windows System for Linux (wsl) on x86_64 machines." echo "Warning The -v (--vnc) flag was set, but the vnc option is"
echo "Ignoring the -v or --vnc flag." echo "not available on MacOS. Ignoring the -v (--vnc) flag."
use_vnc=false use_vnc=false
;;
cygwin)
echo "Warning The -v (--vnc) flag was set, but the vnc option is"
echo "not available on Windows (Cygwin). Ignoring the -v (--vnc) flag."
use_vnc=false
;;
wsl)
if [ ! "$(uname -m)" = x86_64 ]
then
echo "Warning: The -v or --vnc flag was set."
echo "But the vnc option is only available when running on "
echo "Windows System for Linux (wsl) on x86_64 machines."
echo "Ignoring the -v or --vnc flag."
use_vnc=false
fi
;;
linux)
;;
esac
fi fi
;; ;;
-x | --logindir) -x | --logindir)

View File

@@ -128,15 +128,20 @@ IL_DIR="$(cd "${MEDLEYDIR}/.."; pwd)"
wsl=false wsl=false
darwin=false darwin=false
cygwin=false cygwin=false
linux=false
platform=unknown
if [ "$(uname)" = "Darwin" ] if [ "$(uname)" = "Darwin" ]
then then
darwin=true darwin=true
platform=darwin
elif [ "$(uname -s | head --bytes 6)" = "CYGWIN" ] elif [ "$(uname -s | head --bytes 6)" = "CYGWIN" ]
then then
cygwin=true cygwin=true
platform=cgwin
elif [ -e "/proc/version" ] && grep --ignore-case --quiet Microsoft /proc/version elif [ -e "/proc/version" ] && grep --ignore-case --quiet Microsoft /proc/version
then then
platform=wsl
wsl=true wsl=true
wsl_ver=0 wsl_ver=0
# WSL2 # WSL2
@@ -161,7 +166,19 @@ Exiting"
fi fi
fi fi
fi fi
else
linux=true
platform=linux
fi fi
#################### TEST CODE ####################
#wsl=false
#darwin=false
#cygwin=false
#linux=true
#platform=linux
#################### TEST CODE ####################
# process config file and args # process config file and args
# shellcheck source=./medley_configfile.sh # shellcheck source=./medley_configfile.sh

View File

@@ -327,9 +327,9 @@ fi
# Run maiko either directly or with vnc # Run maiko either directly or with vnc
if [ "${wsl}" = true ] && [ "${use_vnc}" = true ] if [ "${use_vnc}" = true ]
then then
# do the vnc thing on wsl (if called for) # do the vnc thing - if called for
# shellcheck source=./medley_vnc.sh # shellcheck source=./medley_vnc.sh
. "${SCRIPTDIR}/medley_vnc.sh" . "${SCRIPTDIR}/medley_vnc.sh"
else else

View File

@@ -98,8 +98,8 @@ flags:
-t STRING | --title STRING : use STRING as title of window -t STRING | --title STRING : use STRING as title of window
-d :N | --display :N : use X display :N -d :N | --display :N : use X display :N
+w
+w -v | --vnc : (WSL only) Use a VNC window instead of an X window -v | --vnc : Use a VNC window instead of an X window (Not available: MacOS & Windows/Cygwin)
-i STRING | --id STRING : use STRING as the id for this run of Medley (default: default) -i STRING | --id STRING : use STRING as the id for this run of Medley (default: default)

View File

@@ -16,9 +16,14 @@
# Copyright 2023 Interlisp.org # Copyright 2023 Interlisp.org
# #
############################################################################### ###############################################################################
#set -x
ip_addr() { ip_addr() {
ip -4 -br address show dev eth0 | awk '{print $3}' | sed 's-/.*$--' if [ "${wsl}" = true ]
then
ip -4 -br address show dev eth0 | awk '{print $3}' | sed 's-/.*$--'
else
echo "127.0.0.1"
fi
} }
find_open_display() { find_open_display() {
@@ -60,21 +65,39 @@
} }
# #
# Make sure prequisites for vnc support in wsl are in place # Make sure prequisites for vnc support are in place
# #
if [ "${use_vnc}" = "true" ]; if [ -z "$(which Xvnc)" ] || [ "$(Xvnc -version 2>&1 | grep -iq tigervnc; echo $?)" -eq 1 ]
then
echo "Error: The -v or --vnc flag was set."
echo "But it appears that that TigerVNC server \(Xvnc\) has not been installed."
echo "Please install the TigerVNC server and try again. On Debian and Ubuntu, use:"
echo "\"sudo apt install tigervnc-standalone-server\". On most other Linux distros, use the"
echo "distro's package manager to install the \"tigervnc-server\" package."
echo "Exiting."
exit 4
fi
if [ "${linux}" = "true" ]
then
if [ -z "$(which vncviewer)" ] || [ "$(vncviewer -v 2>&1 | head -2 | grep -iq tigervnc; echo $?)" -eq 1 ]
then
echo "Error: The -v or --vnc flag was set."
echo "But it appears that that the TigerVNC viewer \(vncviewer\) is not installed on your system."
echo "Please install the TigerVNC viewer and try again. On Debian and Ubuntu, use:"
echo "\"sudo apt install tigervnc-viewer\". On most other Linux distros, use the"
echo "the distro's package manager to install the \"tigervnc-viewer\" (or sometimes just \"tigervnc\")"
echo "package."
echo "Exiting."
exit 5
else
vncviewer="$(which vncviewer)"
fi
elif [ "${wsl}" = "true" ]
then then
win_userprofile="$(cmd.exe /c "<nul set /p=%UserProfile%" 2>/dev/null)" win_userprofile="$(cmd.exe /c "<nul set /p=%UserProfile%" 2>/dev/null)"
vnc_dir="$(wslpath "${win_userprofile}")/AppData/Local/Interlisp" vnc_dir="$(wslpath "${win_userprofile}")/AppData/Local/Interlisp"
vnc_exe="vncviewer64-1.12.0.exe" vnc_exe="vncviewer64-1.12.0.exe"
if [ "$(which Xvnc)" = "" ] || [ "$(Xvnc -version 2>&1 | grep -iq tigervnc; echo $?)" -eq 1 ] if [ ! -e "${vnc_dir}/${vnc_exe}" ];
then
echo "Error: The -v or --vnc flag was set."
echo "But it appears that that TigerVNC \(Xvnc\) has not been installed."
echo "Please install TigerVNC using \"sudo apt install tigervnc-standalone-server tigervnc-xorg-extension\""
echo "Exiting."
exit 4
elif [ ! -e "${vnc_dir}/${vnc_exe}" ];
then then
if [ -e "${IL_DIR}/wsl/${vnc_exe}" ]; if [ -e "${IL_DIR}/wsl/${vnc_exe}" ];
then then
@@ -108,6 +131,7 @@
done done
fi fi
fi fi
vncviewer="${vnc_dir}/${vnc_exe}"
fi fi
# #
# Start the log file so we can trace any issues with vnc, etc # Start the log file so we can trace any issues with vnc, etc
@@ -127,6 +151,7 @@
# find an unused display and an available port # find an unused display and an available port
# #
#set -x #set -x
ORIGINAL_DISPLAY="${DISPLAY}"
OPEN_DISPLAY="$(find_open_display)" OPEN_DISPLAY="$(find_open_display)"
if [ "${OPEN_DISPLAY}" -eq -1 ]; if [ "${OPEN_DISPLAY}" -eq -1 ];
then then
@@ -153,15 +178,15 @@
# Start the Xvnc server # Start the Xvnc server
# #
mkdir -p "${LOGINDIR}"/logs mkdir -p "${LOGINDIR}"/logs
/usr/bin/Xvnc "${DISPLAY}" \ Xvnc "${DISPLAY}" \
-rfbport "${VNC_PORT}" \ -rfbport "${VNC_PORT}" \
-geometry "${geometry}" \ -geometry "${geometry}" \
-SecurityTypes None \ -SecurityTypes None \
-NeverShared \ -NeverShared \
-DisconnectClients=0 \ -DisconnectClients=0 \
-desktop "${title}" \ -desktop "${title}" \
--MaxDisconnectionTime=10 \ --MaxDisconnectionTime=10 \
>> "${LOG}" 2>&1 & >> "${LOG}" 2>&1 &
sleep .5 sleep .5
# #
@@ -171,25 +196,24 @@
start_maiko "$@" start_maiko "$@"
if [ -n "$(pgrep -f "${vnc_exe}.*:${VNC_PORT}")" ]; then vncconfig -disconnect; fi if [ -n "$(pgrep -f "${vnc_exe}.*:${VNC_PORT}")" ]; then vncconfig -disconnect; fi
} & } &
# #
# Start the vncviewer on the windows side # Start the vncviewer
# #
# First give medley time to startup # First give medley time to startup
# sleep .25 # sleep .25
# SLeep appears not to be needed, but faster/slower machines ???? # Sleep appears not to be needed, but faster/slower machines ????
# FGH 2023-02-08 # FGH 2023-02-08
# Then start vnc viewer on Windows side # Then start vnc viewer
vncv_loc=$(( OPEN_DISPLAY * 50 )) vncv_loc=$(( OPEN_DISPLAY * 50 ))
start_time=$(date +%s) start_time=$(date +%s)
"${vnc_dir}"/${vnc_exe} \ export DISPLAY="${ORIGINAL_DISPLAY}"
-geometry "+${vncv_loc}+${vncv_loc}" \ "${vncviewer}" -geometry "+${vncv_loc}+${vncv_loc}" \
-ReconnectOnError=off \ AlertOnFatalError=0 \
AlertOnFatalError=off \ -ReconnectOnError=0 \
"$(ip_addr)":"${VNC_PORT}" \ "$(ip_addr)":"${VNC_PORT}" \
>>"${LOG}" 2>&1 & >>"${LOG}" 2>&1 &
wait $! wait $!
if [ $(( $(date +%s) - start_time )) -lt 5 ] if [ $(( $(date +%s) - start_time )) -lt 5 ]
then then