1
0
mirror of synced 2026-04-19 01:37:23 +00:00
Files
Interlisp.medley/scripts/medley/medley_args.sh
Frank Halasz a4b9099b80 Extensive loadup scripts revamp (#2111)
This PR is an extensive revamp of the loadup scripts including the following changes:

New omnibus script scripts/loadup which is meant to be the single interface to the loadup system. The man page for this script can be found here: https://online.interlisp.org/downloads/man_loadup.html

The new loadup script allows you to restart the loadup process from any particular stage - init, mid, lisp, full, etc. For example, you can start the loadup from an existing init-mid.sysout and have it run thru creating the full.sysout. The call for this would be: ./scripts/loadup --target full --start mid. (See man page for all options to the loadup script as well as examples of their use.)

In order to facilitate this target/start feature, the loadup workdir has been moved to a single location per MEDLEYDIR, specifically to MEDLEDIR/loadups/build. (Previously, it was different for every invocation in /tmp/loadups-$$)

When restarting the loadup from, say, lisp.sysout, the script will look for the lisp.sysout to start from first in MEDLEYDIR/loadups and then in MEDLEYDIR/loadups/build. If the starting sysout is found in loadups, it will be copied (non-versioned) into the workdir before doing the loadup, overwriting whatever is already there.

There is now a lock (MEDLEYDIR/loadups/build/lock) that prevents concurrent loadups from running (and very occassionally needs to be manually removed).

At successful completion of a loadup run, the created .sysouts and other files are moved into the loadups directory as before (unless the --nocopy option is specified). BUT the build files - including the dribble files - are left in the working directory (i.e., in loadups/build)

The loadup script now supersedes the former loadup-all.sh, loadup-full.sh and loadup-db.sh scripts. But I have left in their place scripts that call the new loadup script with the right options. loadup-all.sh is now just a link to the single loadup script, who's options are (hopefully) a superset of loadup-all.sh.

All of the worker scripts (e.g., loadup-full-from-lisp.sh) have been updated to use better mechanisms to catch and report errors, including the new (LOGOUT T EXITCODE) feature. The main script has been updated to better catch errors in these worker scripts when they do happen.

You can now specify a MAIKODIR for the loadup, either using the MAIKODIR env variable or thru the --maikodir command line option.

All of the loadup scripts have been moved down one level into scripts/loadups. But there are links from the scripts/ directory into the scripts/loadups directory for all of the top-level legacy scripts - loadup-all.sh, loadup-db.sh, loadup-full.sh so that you do not have to change your own scripts unless you need to use some of the new features. More importantly, none of the github workflows need to change right now.

The SYSOUTCOMMITS mechanism had to be changed since there is no guarantee that e.g., lisp.sysout and full.sysout are built on the same commit. So (ASSOC 'MEDLEY SYSOUTCOMMITS) now returns an assoc list of sysouts, e.g., ((INIT "aaa")(LISP "bbb")(FULL "ccc")(APPS "ddd")), showing the commits for the various layers of the loadup.

The new loadup scheme allows different sysouts to be created from different commits, so there is an issue with RDSYS (and RDSYS.LCOM) being out of sync with one or more of the sysout in loadups. RDSYS(.LCOM) are copied into library when ever a loadup of the Init stage completes successfully (unless the -nocopy option is specified). The only way to solve this issue when it arises is to do a complete loadup from starter.sysout to full.sysout (or apps.sysout) to ensure evrything is built on the same commit.
2025-04-26 16:24:04 -07:00

421 lines
9.8 KiB
Bash
Executable File

#!only-to-be-sourced
# shellcheck shell=sh
# shellcheck disable=SC2034,SC2154,SC2164
###############################################################################
#
# medley_args.sh - script for processing the args to medley.sh script.
#
# !!!! 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
#
###############################################################################
# load usage function
# shellcheck source=./medley_usage.sh
. "${SCRIPTDIR}/medley_usage.sh"
args_stage="config file"
# Defaults
geometry=""
greet_specified=false
pass_args=false
run_id="default"
screensize=""
sysout_arg=""
sysout_stage=""
title=""
use_vnc=false
windows=false
maikodir_arg="${MAIKODIR}"
maikodir_stage="MAIKODIR env variable"
maikoprog_arg=""
greet_arg=""
noscroll=false
display_arg=""
vmem_arg=""
mem_arg=""
maiko_args=""
logindir_arg=""
nh_host_arg=""
nh_port_arg=""
nh_mac_arg=""
nh_debug_arg=""
pixelscale_arg=""
borderwidth_arg=""
remcm_arg="${LDEREMCM}"
repeat_cm=""
# Add marker at end of args so we can accumulate pass-on args in args array
set -- "$@" "--start_of_pass_args"
# Loop thru args and process
while [ "$#" -ne 0 ];
do
if [ "${pass_args}" = false ];
then
case "$1" in
-a | --apps)
sysout_arg="apps"
sysout_stage="${args_stage}"
;;
-c | --config)
# already handled so just skip both flag and value
shift;
;;
-cm | --rem.cm | --remcm)
if [ "$2" = "-" ] || [ "$2" = "--" ]
then
remcm_arg=""
else
check_for_dash_or_end "$1" "$2"
check_file_readable "$1" "$2"
remcm_arg="$2"
fi
shift
;;
-cc | --repeat.cm | --repeat)
if [ "$2" = "-" ] || [ "$2" = "--" ]
then
repeat_cm=""
else
check_for_dash_or_end "$1" "$2"
# check_file_readable "$1" "$2"
repeat_cm="$2"
fi
shift
;;
-d | --display)
if [ "$2" = "-" ]
then
display=""
else
check_for_dash_or_end "$1" "$2"
display_arg="$2"
fi
shift
;;
-e | --interlisp)
case "$2" in
-)
MEDLEY_EXEC=""
shift
;;
+)
export MEDLEY_EXEC="inter"
shift
;;
*)
export MEDLEY_EXEC="inter"
;;
esac
;;
-f | --full)
sysout_arg="full"
sysout_stage="${args_stage}"
;;
-g | --geometry)
if [ "$2" = "-" ]
then
geometry=""
else
check_for_dash_or_end "$1" "$2"
geometry="$2"
fi
shift
;;
-h | --help)
usage
;;
-i | --id)
if [ "$2" = "-" ]
then
run_id="default"
elif [ "$2" = "--" ]
then
run_id="$( basename "${MEDLEYDIR}" )"
elif [ "$2" = "---" ]
then
run_id="$(cd "${MEDLEYDIR}/.."; basename "$(pwd)")"
else
check_for_dash_or_end "$1" "$2"
run_id=$(echo "$2" | sed -e "s/++*\(.\)/\\1/g" -e "s/[^A-Za-z0-9+_]//g")
fi
shift
;;
-k | --vmem)
if [ "$2" = "-" ]
then
vmem_arg=""
else
check_for_dash_or_end "$1" "$2"
check_file_writeable_or_creatable "$1" "$2"
vmem_arg="$2"
fi
shift
;;
-l | --lisp)
sysout_arg="lisp"
sysout_stage="${args_stage}"
;;
-m | --mem)
if [ "$2" = "-" ]
then
mem_arg=""
else
check_for_dash_or_end "$1" "$2"
mem_arg="$2"
fi
shift
;;
-n | --noscroll)
case "$2" in
-)
noscroll=false
shift
;;
+)
noscroll=true
shift
;;
*)
noscroll=true
;;
esac
;;
-nh | --nethub)
case "$2" in
-:* | - )
true
;;
*)
check_for_dash_or_end "$1" "$2"
;;
esac
parse_nethub_data "$2"
if [ "${nh_host}" = "-" ]; then nh_host_arg=""; else nh_host_arg="${nh_host}"; fi
if [ "${nh_port}" = "-" ]; then nh_port_arg=""; else nh_port_arg="${nh_port}"; fi
if [ "${nh_mac}" = "-" ]; then nh_mac_arg=""; else nh_mac_arg="${nh_mac}"; fi
if [ "${nh_debug}" = "-" ]; then nh_debug_arg=""; else nh_debug_arg="${nh_debug}"; fi
shift
;;
-ps | --pixelscale)
if [ "$2" = "-" ]
then
pixelscale_arg=""
else
check_for_dash_or_end "$1" "$2"
pixelscale_arg="$2"
fi
shift
;;
-r | --greet)
if [ "$2" = "-" ] || [ "$2" = "--" ]
then
greet_arg="--nogreet--"
else
check_for_dash_or_end "$1" "$2"
check_file_readable "$1" "$2"
greet_arg="$2"
fi
greet_specified='true'
shift
;;
-s | --screensize)
if [ "$2" = "-" ]
then
screensize=""
else
check_for_dash_or_end "$1" "$2"
screensize="$2"
fi
shift
;;
-t | --title)
if [ "$2" = "-" ]
then
title=""
else
check_for_dash_or_end "$1" "$2"
if [ -n "$2" ]; then title="$2"; fi
fi
shift
;;
-u | --continue)
sysout_arg=""
sysout_stage="${args_stage}"
;;
-v | --vnc)
case "$2" in
-)
use_vnc=false
shift
;;
+)
use_vnc=true
shift
;;
*)
use_vnc=true
;;
esac
if [ "${use_vnc}" = true ]
then
case ${platform} in
darwin)
echo "Warning The -v (--vnc) flag was set, but the vnc option is"
echo "not available on MacOS. Ignoring the -v (--vnc) flag."
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
;;
-x | --logindir)
if [ "$2" = "-" ]
then
logindir_arg=""
elif [ "$2" = "--" ]
then
check_dir_writeable_or_creatable "$1" "${MEDLEYDIR}/logindir"
logindir_arg="${MEDLEYDIR}/logindir"
else
check_for_dash_or_end "$1" "$2"
check_dir_writeable_or_creatable "$1" "$2"
logindir_arg="$2"
fi
shift
;;
-y | --sysout)
if [ "$2" = "-" ]
then
sysout_arg=""
else
check_for_dash_or_end "$1" "$2"
sysout_arg="$2"
fi
sysout_stage="${args_stage}"
shift
;;
-z | --man)
if [ "${darwin}" = true ]
then
/usr/bin/man "${MEDLEYDIR}/docs/man-page/medley.1.gz"
else
/usr/bin/man -l "${MEDLEYDIR}/docs/man-page/medley.1.gz"
fi
exit 0
;;
-nf | -NF | --nofork)
# for use in loadups
case $2 in
-)
nofork_arg=""
;;
+)
nofork_arg="-NF"
;;
*)
nofork_arg="-NF"
;;
esac
;;
--maikodir)
# for use in loadups
if [ "$2" = "-" ] || [ "$2" == "--" ]
then
maikodir_arg=""
maikodir_stage=""
else
check_for_dash_or_end "$1" "$2"
check_dir_exists "$1" "2"
maikodir_arg="$2"
maikodir_stage="${args_stage}"
fi
shift;
;;
-prog | --maikoprog)
# for use in loadups
check_for_dash_or_end "$1" "$2"
maikoprog_arg="$2"
shift
;;
--windows)
# internal: called from Windows medley.ps1 (via docker)
windows=true
;;
--start_cl_args)
# internal: used to separate config file args from command line args
args_stage="command line arguments"
pass_args=false
;;
--start_of_pass_args)
# internal: used to mark end of args and start of accumulated pass-on args
shift
break
;;
--)
pass_args=true
;;
-*)
usage "ERROR: Unknown flag: $1"
;;
*)
# if matched the empty string, just ignore
if [ -n "$1" ];
then
if [ $# -eq 1 ] || [ "$2" = "--" ]
then
sysout_arg="$1"
sysout_stage="${args_stage}"
else
err_msg="ERROR: unexpected argument \"$1\""
usage "${err_msg}"
fi
fi
;;
esac
else
if [ "$1" = "--start_cl_args" ]
then
args_stage="command line arguments"
pass_args=false
elif [ "$1" = "--start_of_pass_args" ]
then
shift
break
else
# add pass-on args to end of args array
set -- "$@" "$1"
# maiko_args="${maiko_args} \"$1\""
fi
fi
shift
done
# if running on WSL1, force use_vnc
if [ "${wsl}" = true ] && [ "${wsl_ver}" -eq 1 ]
then
use_vnc=true
fi