1
0
mirror of synced 2026-01-27 04:41:54 +00:00
Files
Interlisp.medley/scripts/medley/medley_vnc.sh
Frank Halasz 415a698df5 Overhaul of loadup scripts (#1699)
* Make medley.sh and its associated scripts POSIX compliant - i.e., debashify them

* Added config file for medley script, medley now reads from config file and prepends arguemnts from file to the copmmand line arguments

* WIP. Updates to medley.sh scripts.

* WIP.  More on medley.sh and friends update.

* WIP. Medley redo

* WIP.  Debugging new medley scripts

* Renamed medley.sh/medley.command to be medley_main.sh.  Added code to compile single medley.sh/medley.command script by inlining all of the source'd medley_*.sh files.

* Add temp fix for cygwin Issue #1685

* Minor fixup to medley_utils.sh; take debug code out out of run_medley

* Add README to medley directory to explain how to compile medley.sh (medley.command).

* Ooops. This time really adding the README file to the medley directory explaining how to compile medley.sh (medley.command)

* Update loadup- scripts to use updated medley scripts rather than run-medley

* Fix default setting of $config_file in medley_configfile.sh

* Redo medley compile to pick up last commikt

* Fixing how maiko exe is found and sysout argument error processing - both issues discovered testing on MAcOS

* In medley_configfile, replace echo with printf %s because echo - does not work in zsh

* Supress config file on loadups calls to Medley

* Add oldschool support (use original run-medley) to loadup scripts; improve FAILURE detection so loadup-all won't proceed once one of the components fails

* Add in medley_args.sh add -prog as synonym to --maikoprog to aid in loadup scripts; in medley_run.sh script try to get a good exit code for call to maiko, especially useful for loadup scripts

* Run loadup scripts thru shellcheck and update as necessary to make Posix compliant

* Get rid of -nt comparisons in loadup-setup.sh because they are not posix-complaint.  They were not really needed anyway.

* Removing (for now) use of lde exit codes to decide FAILURE case in loadup-setup.sh since exit codes from lde apperar to be inverted on MacOS.

* Update medley man page.  Add - functionality to more args is medley_args.sh

* Compile medley.sh with changes from last commit

* Ooops.  Left medley_args.sh changes out of last commit.  Rectifying here.

* Added support for LDEKEYBOARDTYPE to medley_run to match run-medley

* Add to medley.sh: auto numbered id's and titles with id's inserted

* Cleanup some shellcheck issues in medley_main.sh

* fix maiko args -nh-xxx.  were -nethub-xxxx. In medley_run.sh

* Overhaul handling of pass-on args to manage the quoting issues prevelant in the previous implementation

* Cleanup minor shellcheck issues in medley_*.sh scripts

* Add underscore as character allowed in ids - makes things clearer when id used with +

* Add a self-numbering id to medley calls in loadup scripts

* Put workaround in medley_run.sh for Issue #1702 - issues with sysout arg processing in Maiko

* Oops.  messed up LDESRCSYSOUT in last commit.  should be LDESOURCESYSOUT

* compile medley.sh
2024-05-09 21:31:27 -07:00

215 lines
6.1 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!only-to-be-sourced
# shellcheck shell=sh
# shellcheck disable=SC2154,SC2162
###############################################################################
#
# medley_vnc.sh - script for running Medley Interlisp on WSL using Xvnc
# on the Linux side and a vncviewer on the Windows side.
# This script run under Linux will start the right apps
# on both the Linux and Windows sides.
#
# !!!! This script is meant to be SOURCEd from the scripts/medley.sh script.
# !!!! It should not be run as a standlone script.
#
# 2023-01-12 Frank Halasz
#
# Copyright 2023 Interlisp.org
#
###############################################################################
ip_addr() {
ip -4 -br address show dev eth0 | awk '{print $3}' | sed 's-/.*$--'
}
find_open_display() {
local_ctr=1
local_result=-1
while [ ${local_ctr} -lt 64 ];
do
if [ ! -e /tmp/.X${local_ctr}-lock ];
then
local_result=${local_ctr}
break
else
local_ctr=$(( local_ctr+1 ))
fi
done
echo ${local_result}
}
find_open_port() {
local_ctr=5900
local_result=-1
while [ ${local_ctr} -lt 6000 ];
do
if [ "${wsl}" = true ] && [ "${wsl_ver}" -eq 1 ]
then
netstat.exe -a -n | awk '{ print $2 }' | grep -q ":${local_ctr}\$"
else
ss -a | grep -q "LISTEN.*:${local_ctr}[^0-9]"
fi
if [ $? -eq 1 ];
then
local_result=${local_ctr}
break
else
local_ctr=$(( local_ctr+1 ))
fi
done
echo ${local_result}
}
#
# Make sure prequisites for vnc support in wsl are in place
#
if [ "${use_vnc}" = "true" ];
then
win_userprofile="$(cmd.exe /c "<nul set /p=%UserProfile%" 2>/dev/null)"
vnc_dir="$(wslpath "${win_userprofile}")/AppData/Local/Interlisp"
vnc_exe="vncviewer64-1.12.0.exe"
if [ "$(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 \(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
if [ -e "${IL_DIR}/wsl/${vnc_exe}" ];
then
# make sure TigerVNC viewer is in a Windows (not Linux) directory. If its in a Linux directory
# there will be a long delay when it starts up
mkdir -p "${vnc_dir}"
cp -p "${IL_DIR}/wsl/${vnc_exe}" "${vnc_dir}/${vnc_exe}"
else
loop_done=false
while [ "${loop_done}" = "false" ]
do
echo "TigerVnc viewer is required by the -vnc option but is not installed."
echo "Ok to download from SourceForge? [y, Y, n or N, default n] "
read resp
if [ -z "${resp}" ]; then resp=n; fi
case "${resp}" in
n* | N* )
echo "Ok. You can download the Tiger VNC viewer \(v1.12.0\) .exe yourself and "
echo "place it in ${vnc_dir}/${vnc_exe}. Then retry."
echo "Exiting."
exit 5
;;
y* | Y* )
wget -P "${vnc_dir}" https://sourceforge.net/projects/tigervnc/files/stable/1.12.0/vncviewer64-1.12.0.exe
loop_done=true
;;
* )
echo "Answer not one of Y, y, N, or n. Retry."
;;
esac
done
fi
fi
fi
#
# Start the log file so we can trace any issues with vnc, etc
#
LOG="${LOGINDIR}/logs/medley_${run_id}.log"
mkdir -p "$(dirname -- "${LOG}")"
echo "START" >"${LOG}"
#
#
#set -x
# are we running in background - used for pretty-fying the echos
case $(ps -o stat= -p $$) in
*+*) bg=false ;;
*) bg=true ;;
esac
#
# find an unused display and an available port
#
#set -x
OPEN_DISPLAY="$(find_open_display)"
if [ "${OPEN_DISPLAY}" -eq -1 ];
then
echo "Error: cannot find an unused DISPLAY between 1 and 63"
echo "Exiting"
exit 33
else
if [ "${bg}" = true ]; then echo; fi
echo "Using DISPLAY=:${OPEN_DISPLAY}"
fi
DISPLAY=":${OPEN_DISPLAY}"
export DISPLAY
VNC_PORT="$(find_open_port)"
export VNC_PORT
if [ "${VNC_PORT}" -eq -1 ];
then
echo "Error: cannot find an unused port between 5900 and 5999"
echo "Exiting"
exit 33
else
echo "Using VNC_PORT=${VNC_PORT}"
fi
#
# Start the Xvnc server
#
mkdir -p "${LOGINDIR}"/logs
/usr/bin/Xvnc "${DISPLAY}" \
-rfbport "${VNC_PORT}" \
-geometry "${geometry}" \
-SecurityTypes None \
-NeverShared \
-DisconnectClients=0 \
-desktop "${title}" \
--MaxDisconnectionTime=10 \
>> "${LOG}" 2>&1 &
sleep .5
#
# Run Maiko in background, handing over the pass-on args which are all thats left in the main args array
#
{
start_maiko "$@"
if [ -n "$(pgrep -f "${vnc_exe}.*:${VNC_PORT}")" ]; then vncconfig -disconnect; fi
} &
#
# Start the vncviewer on the windows side
#
# First give medley time to startup
# sleep .25
# SLeep appears not to be needed, but faster/slower machines ????
# FGH 2023-02-08
# Then start vnc viewer on Windows side
vncv_loc=$(( OPEN_DISPLAY * 50 ))
start_time=$(date +%s)
"${vnc_dir}"/${vnc_exe} \
-geometry "+${vncv_loc}+${vncv_loc}" \
-ReconnectOnError=off \
AlertOnFatalError=off \
"$(ip_addr)":"${VNC_PORT}" \
>>"${LOG}" 2>&1 &
wait $!
if [ $(( $(date +%s) - start_time )) -lt 5 ]
then
if [ -z "$(pgrep -f "Xvnc ${DISPLAY}")" ]
then
echo "Xvnc server failed to start."
echo "See log file at ${LOG}"
echo "Exiting"
exit 3
else
echo "VNC viewer failed to start.";
echo "See log file at ${LOG}";
echo "Exiting" ;
exit 4;
fi
fi
#
# Done, "Go back" to medley_run.sh
#
true
#######################################