* 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
165 lines
4.0 KiB
Bash
165 lines
4.0 KiB
Bash
#!only-to-be-sourced
|
|
# shellcheck shell=sh
|
|
###############################################################################
|
|
#
|
|
# medley_utils.sh - script containing various useful functions for 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-23 Frank Halasz
|
|
#
|
|
# Copyright 2023 Interlisp.org
|
|
#
|
|
###############################################################################
|
|
|
|
is_tput="$(which tput)"
|
|
|
|
output_error_msg() {
|
|
local_oem_file="${TMPDIR:-/tmp}"/oem_$$
|
|
echo "$1" >"${local_oem_file}"
|
|
while read -r line
|
|
do
|
|
if [ -n "${is_tput}" ];
|
|
then
|
|
echo "$(${is_tput} setab 1)$(${is_tput} setaf 7)${line}$(${is_tput} sgr0)"
|
|
else
|
|
echo "$1"
|
|
fi
|
|
done <"${local_oem_file}"
|
|
rm -f "${local_oem_file}"
|
|
}
|
|
|
|
check_for_dash_or_end() {
|
|
local_err_msg="";
|
|
if [ -z "$2" ] || [ "$2" = "--" ]
|
|
then
|
|
local_err_msg="Error: the flag \"$1\" requires a value.
|
|
Value is missing."
|
|
usage "${local_err_msg}"
|
|
else
|
|
case "$2" in
|
|
-*)
|
|
local_err_msg="Error: either the value for flag \"${1}\" is missing OR
|
|
the value begins with a \"-\", which is not allowed."
|
|
usage "${local_err_msg}"
|
|
;;
|
|
esac
|
|
fi
|
|
}
|
|
|
|
check_file_writeable_or_creatable() {
|
|
local_msg_core="\"$2\" given as the value of the \"$1\" flag"
|
|
local_err_msg=""
|
|
if [ -e "$%2" ]
|
|
then
|
|
if [ ! -f "$2" ]
|
|
then
|
|
local_err_msg="Error: File ${local_msg_core} is not a regular file.
|
|
It is either a directory or a device file of some sort.
|
|
Exiting"
|
|
output_error_msg "${local_err_msg}"
|
|
exit 1
|
|
elif [ ! -w "$2" ]
|
|
then
|
|
local_err_msg="Error: File ${local_msg_core} exists but is not writeable
|
|
Exiting"
|
|
output_error_msg "${local_err_msg}"
|
|
exit 1
|
|
fi
|
|
else
|
|
if [ ! -w "$(dirname -- "$2")" ]
|
|
then
|
|
local_err_msg="Error: File ${local_msg_core} cannot be created because
|
|
its directory either doen't exist or is not writeable.
|
|
Exiting"
|
|
output_error_msg "${local_err_msg}"
|
|
exit 1
|
|
fi
|
|
fi
|
|
}
|
|
|
|
check_dir_writeable_or_creatable() {
|
|
local_msg_core="\"$2\" given as the value of the \"$1\" flag"
|
|
local_err_msg=""
|
|
if [ -e "$%2" ]
|
|
then
|
|
if [ ! -d "$2" ]
|
|
then
|
|
local_err_msg="Error: ${local_msg_core} exists but is not a directory.
|
|
Exiting"
|
|
output_error_msg "${local_err_msg}"
|
|
exit 1
|
|
elif [ ! -w "$2" ]
|
|
then
|
|
local_err_msg="Error: Directory ${local_msg_core} exists but is not writeable
|
|
Exiting"
|
|
output_error_msg "${local_err_msg}"
|
|
exit 1
|
|
fi
|
|
else
|
|
if [ ! -w "$(dirname -- "$2")" ]
|
|
then
|
|
local_err_msg="Error: Directory ${local_msg_core} cannot be created because
|
|
its directory either doesn't exist or is not writeable.
|
|
Exiting"
|
|
output_error_msg "${local_err_msg}"
|
|
exit 1
|
|
fi
|
|
fi
|
|
}
|
|
|
|
|
|
check_file_readable() {
|
|
local_msg_core="\"$2\" given as the value of the \"$1\" flag"
|
|
if [ ! -r "$2" ]
|
|
then
|
|
local_err_msg="Error: File ${local_msg_core}
|
|
either doesn't exist or is not readable.
|
|
Exiting"
|
|
output_error_msg "${local_err_msg}"
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
check_dir_exists() {
|
|
local_msg_core="\"$2\" given as the value of the \"$1\" flag"
|
|
if [ -e "$2" ]
|
|
then
|
|
if [ ! -d "$2" ]
|
|
then
|
|
local_err_msg="Error: Pathname ${local_msg_core} exists but is not a directory.
|
|
Exiting"
|
|
output_error_msg "${local_err_msg}"
|
|
exit 1
|
|
elif [ ! -r "$2" ]
|
|
then
|
|
local_err_msg="Error: Directory ${local_msg_core} exists but is not readable.
|
|
Exiting"
|
|
output_error_msg "${local_err_msg}"
|
|
exit 1
|
|
fi
|
|
fi
|
|
}
|
|
|
|
parse_nethub_data() {
|
|
nh_host=""
|
|
nh_port=""
|
|
nh_mac=""
|
|
nh_debug=""
|
|
#
|
|
x="${1%:}:"
|
|
nh_host="${x%%:*}"
|
|
x="${x#"${nh_host}":*}"
|
|
nh_port="${x%%:*}"
|
|
if [ "${nh_port}" = "${x}" ]; then nh_port=""; return 0; fi
|
|
x="${x#"${nh_port}":*}"
|
|
nh_mac="${x%%:*}"
|
|
if [ "${nh_mac}" = "${x}" ]; then nh_mac=""; return 0; fi
|
|
nh_debug="${x#"${nh_mac}":*}"
|
|
if [ "${nh_debug}" = "${x}" ]; then nh_debug=""; return 0; fi
|
|
nh_debug="${nh_debug%:}"
|
|
return 0
|
|
}
|
|
|