1
0
mirror of synced 2026-01-12 00:42:56 +00:00
Interlisp.medley/scripts/loadups/loadup-setup.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

272 lines
6.3 KiB
Bash

#!to_be_sourced_only
# shellcheck shell=sh
MEDLEYDIR=$(cd "${LOADUP_SCRIPTDIR}/../.." || exit; pwd)
export MEDLEYDIR
export LOADUP_CPV="${MEDLEYDIR}/scripts/cpv"
if [ -z "${LOADUP_SOURCEDIR}" ]
then
LOADUP_SOURCEDIR="${MEDLEYDIR}/internal/loadups"
export LOADUP_SOURCEDIR
fi
if [ -z "${LOADUP_OUTDIR}" ]
then
LOADUP_OUTDIR="${MEDLEYDIR}/loadups"
export LOADUP_OUTDIR
fi
if [ ! -d "${LOADUP_OUTDIR}" ];
then
if [ ! -e "${LOADUP_OUTDIR}" ];
then
mkdir -p "${LOADUP_OUTDIR}"
else
echo "Error: ${LOADUP_OUTDIR} exists but is not a directory. Exiting."
exit 1
fi
fi
if [ -z "${LOADUP_WORKDIR}" ]
then
LOADUP_WORKDIR="${LOADUP_OUTDIR}/build"
export LOADUP_WORKDIR
fi
if [ ! -d "${LOADUP_WORKDIR}" ];
then
if [ ! -e "${LOADUP_WORKDIR}" ];
then
mkdir -p "${LOADUP_WORKDIR}"
else
echo "Error: ${LOADUP_WORKDIR} exists but is not a directory. Exiting."
exit 1
fi
fi
if [ -z "${LOADUP_LOGINDIR}" ]
then
LOADUP_LOGINDIR="${LOADUP_WORKDIR}/logindir"
export LOADUP_LOGINDIR
fi
if [ ! -d "${LOADUP_LOGINDIR}" ];
then
if [ ! -e "${LOADUP_LOGINDIR}" ];
then
mkdir -p "${LOADUP_LOGINDIR}"
else
echo "Error: ${LOADUP_LOGINDIR} exists but is not a directory. Exiting."
exit 1
fi
fi
if [ -f "$(command -v git)" ] && [ -x "$(command -v git)" ]
then
export HAS_GIT=true
else
export HAS_GIT=false
fi
is_git_dir () {
if [ "${HAS_GIT}" = true ]
then
return "$(git -C "$1" rev-parse >/dev/null 2>/dev/null; echo $?)"
else
return 1
fi
}
git_commit_ID () {
if [ "${HAS_GIT}" = true ]
then
if is_git_dir "$1"
then
# This does NOT indicate if there are any modified files!
COMMIT_ID="$(git -C "$1" rev-parse --short HEAD)"
fi
fi
}
git_commit_ID "${LOADUP_SOURCEDIR}"
LOADUP_COMMIT_ID="${COMMIT_ID}"
export LOADUP_COMMIT_ID
# obsolete? scr="-sc 1024x768 -g 1042x790"
geometry=1024x768
touch "${LOADUP_WORKDIR}"/loadup.timestamp
script_name=$(basename "$0" ".sh")
cmfile="${LOADUP_WORKDIR}/${script_name}.cm"
initfile="${LOADUP_WORKDIR}/${script_name}.init"
# Select whether we use NLSETQ or ERSETQ to wrap the loadup
# cm files depending on whether we want to allow breaks or not.
# shellcheck disable=SC2034
if [ -n "${LOADUP_NOBREAK}" ]
then
HELPFLAG=NIL
NL_ER_SETQ=IL:NLSETQ
else
HELPFLAG="(QUOTE IL:BREAK!)"
NL_ER_SETQ=IL:ERSETQ
fi
######################################################################
loadup_start () {
touch "${LOADUP_WORKDIR}"/timestamp
sleep 1
echo ">>>>> START ${script_name}"
}
loadup_finish () {
if [ ! "${cmfile}" = "-" ]; then rm -f "${cmfile}"; fi
if [ ! "${initfile}" = "-" ]; then rm -f "${initfile}"; fi
if [ "${exit_code}" -ne 0 ] || [ ! -f "${LOADUP_WORKDIR}/$1" ] \
|| [ ! "$( find "${LOADUP_WORKDIR}/$1" -newer "${LOADUP_WORKDIR}"/timestamp )" ]
then
output_error_msg "----- FAILURE ${script_name}-----"
exit_code=1
else
echo "+++++ SUCCESS +++++"
exit_code=0
fi
echo "..... files created ....."
if [ -f "${LOADUP_WORKDIR}/$1" ]
then
shift;
for f in "$@"
do
# shellcheck disable=SC2045,SC2086
for ff in $(ls -1 "${LOADUP_WORKDIR}"/$f);
do
# shellcheck disable=SC2010
if [ "$( find "${ff}" -newer "${LOADUP_WORKDIR}"/timestamp )" ]
then
ls -l "${ff}" 2>/dev/null | grep -v "^.*~[0-9]\+~$"
fi
done
done
fi
echo "<<<<< END ${script_name}"
echo ""
exit ${exit_code}
}
run_medley () {
/bin/sh "${MEDLEYDIR}/scripts/medley/medley.command" \
--config - \
--id loadup_+ \
--geometry "${geometry}" \
--noscroll \
--logindir "${LOADUP_LOGINDIR}" \
--rem.cm "${cmfile}" \
--greet "${initfile}" \
--sysout "$1" \
"$2" "$3" "$4" "$5" "$6" "$7" ;
exit_code=$?
}
is_tput="$(command -v tput)"
if [ -z "${is_tput}" ]
then
is_tput="$(command -v true)"
fi
EOL="
"
output_error_msg() {
local_oem_file="${TMPDIR:-/tmp}"/oem_$$
echo "$1" >"${local_oem_file}"
while read -r line
do
echo "$(${is_tput} setab 1)$(${is_tput} setaf 7)${line}$(${is_tput} sgr0)"
done <"${local_oem_file}"
rm -f "${local_oem_file}"
}
output_warn_msg() {
local_oem_file="${TMPDIR:-/tmp}"/oem_$$
echo "$1" >"${local_oem_file}"
while read -r line
do
echo "$(${is_tput} setab 3)$(${is_tput} setaf 4)${line}$(${is_tput} sgr0)"
done <"${local_oem_file}"
rm -f "${local_oem_file}"
}
exit_if_failure() {
if [ "$1" -ne 0 ]
then
if [ ! "$2" = "true" ]
then
output_error_msg "----- ${script_name}: FAILURE -----${EOL}"
fi
remove_run_lock
exit 1
fi
}
process_maikodir() {
# process --maikodir argument. Only use when --maikodir is only possible argument
while [ "$#" -ne 0 ];
do
case "$1" in
-d | -maikodir | --maikodir)
if [ -n "$2" ]
then
maikodir=$(cd "$2" 2>/dev/null && pwd)
if [ -z "${maikodir}" ] || [ ! -d "${maikodir}" ]
then
output_error_msg "Error: In --maikodir (-d) command line argument, \"$2\" is not an existing directory.${EOL}Exiting"
exit 1
fi
else
output_error_msg "Error: Missing value for the --maikodir (-d) command line argument.${EOL}Exiting"
exit 1
fi
export MAIKODIR="${maikodir}"
shift
;;
*)
output_error_msg "Error: unknown flag: $1${EOL}Exiting"
exit 1
;;
esac
shift
done
}
export LOADUP_LOCKFILE="${LOADUP_WORKDIR}"/lock
check_run_lock() {
if [ -e "${LOADUP_LOCKFILE}" ]
then
output_error_msg "Error: Another loadup is already running with PID $(cat "${LOADUP_LOCKFILE}")${EOL}Exiting."
exit 1
fi
echo "$$" > "${LOADUP_LOCKFILE}"
LOADUP_LOCK="$$"
}
remove_run_lock() {
if [ -n "${LOADUP_LOCK}" ]
then
rm -f "${LOADUP_LOCKFILE}"
fi
}
######################################################################