Skip to content

Commit 1148cd5

Browse files
authored
Further updates to loadup scripts to make its easier to use Lisp-side copy functions to copy medley directories (#1718)
Update all loadup scripts so that 3 things are true: 1. all sub-scripts are called via `/bin/sh <subscript>` so that exec bit need not be set on any loadup script 2. medley is called via `scripts/medley/medley.command` rather than just `medley` so that the top-level medley symbolic link is not necessary for loadups 3. the loadup scripts do not have to be started while cwd is MEDLEYDIR; instead MEDLEYDIR is automatically computed based on where the loadup script is executed from (as the medley script does).
2 parents f44b96e + 40306a3 commit 1148cd5

14 files changed

+1674
-393
lines changed

scripts/copy-all.sh

+141-25
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,151 @@
11
#!/bin/sh
22

3-
if [ ! -x run-medley ] ; then
4-
echo run from MEDLEYDIR
5-
exit 1
6-
fi
3+
main() {
4+
# shellcheck source=./loadup-setup.sh
5+
. "${LOADUP_SCRIPTDIR}/loadup-setup.sh"
76

8-
. scripts/loadup-setup.sh
7+
echo ">>>>> START ${script_name}"
98

10-
echo ">>>>> START ${script_name}"
9+
/bin/sh "${LOADUP_SCRIPTDIR}/cpv" "${LOADUP_WORKDIR}"/full.sysout "${LOADUP_OUTDIR}" \
10+
| sed -e "s#${MEDLEYDIR}/##g"
11+
/bin/sh "${LOADUP_SCRIPTDIR}/cpv" "${LOADUP_WORKDIR}"/lisp.sysout "${LOADUP_OUTDIR}" \
12+
| sed -e "s#${MEDLEYDIR}/##g"
1113

12-
./scripts/cpv "${LOADUP_WORKDIR}"/full.sysout "${LOADUP_OUTDIR}" | sed -e "s#${MEDLEYDIR}/##g"
13-
./scripts/cpv "${LOADUP_WORKDIR}"/lisp.sysout "${LOADUP_OUTDIR}" | sed -e "s#${MEDLEYDIR}/##g"
14-
if [ "${1}" = "-apps" ]; then
15-
./scripts/cpv "${LOADUP_WORKDIR}"/apps.sysout "${LOADUP_OUTDIR}" | sed -e "s#${MEDLEYDIR}/##g"
16-
fi
14+
if [ "${1}" = "-apps" ]; then
15+
/bin/sh "${LOADUP_SCRIPTDIR}/cpv" "${LOADUP_WORKDIR}"/apps.sysout "${LOADUP_OUTDIR}" \
16+
| sed -e "s#${MEDLEYDIR}/##g"
17+
fi
1718

18-
./scripts/cpv "${LOADUP_WORKDIR}"/whereis.hash "${LOADUP_OUTDIR}" | sed -e "s#${MEDLEYDIR}/##g"
19-
./scripts/cpv "${LOADUP_WORKDIR}"/exports.all "${LOADUP_OUTDIR}" | sed -e "s#${MEDLEYDIR}/##g"
19+
/bin/sh "${LOADUP_SCRIPTDIR}/cpv" "${LOADUP_WORKDIR}"/whereis.hash "${LOADUP_OUTDIR}" \
20+
| sed -e "s#${MEDLEYDIR}/##g"
21+
/bin/sh "${LOADUP_SCRIPTDIR}/cpv" "${LOADUP_WORKDIR}"/exports.all "${LOADUP_OUTDIR}" \
22+
| sed -e "s#${MEDLEYDIR}/##g"
2023

21-
./scripts/cpv "${LOADUP_WORKDIR}"/init.dribble "${LOADUP_OUTDIR}" | sed -e "s#${MEDLEYDIR}/##g"
22-
./scripts/cpv "${LOADUP_WORKDIR}"/lisp.dribble "${LOADUP_OUTDIR}" | sed -e "s#${MEDLEYDIR}/##g"
23-
./scripts/cpv "${LOADUP_WORKDIR}"/full.dribble "${LOADUP_OUTDIR}" | sed -e "s#${MEDLEYDIR}/##g"
24-
./scripts/cpv "${LOADUP_WORKDIR}"/whereis.dribble "${LOADUP_OUTDIR}" | sed -e "s#${MEDLEYDIR}/##g"
25-
if [ "${1}" = "-apps" ]; then
26-
./scripts/cpv "${LOADUP_WORKDIR}"/apps.dribble "${LOADUP_OUTDIR}" | sed -e "s#${MEDLEYDIR}/##g"
27-
fi
24+
/bin/sh "${LOADUP_SCRIPTDIR}/cpv" "${LOADUP_WORKDIR}"/init.dribble "${LOADUP_OUTDIR}" \
25+
| sed -e "s#${MEDLEYDIR}/##g"
26+
/bin/sh "${LOADUP_SCRIPTDIR}/cpv" "${LOADUP_WORKDIR}"/lisp.dribble "${LOADUP_OUTDIR}" \
27+
| sed -e "s#${MEDLEYDIR}/##g"
28+
/bin/sh "${LOADUP_SCRIPTDIR}/cpv" "${LOADUP_WORKDIR}"/full.dribble "${LOADUP_OUTDIR}" \
29+
| sed -e "s#${MEDLEYDIR}/##g"
30+
/bin/sh "${LOADUP_SCRIPTDIR}/cpv" "${LOADUP_WORKDIR}"/whereis.dribble "${LOADUP_OUTDIR}" \
31+
| sed -e "s#${MEDLEYDIR}/##g"
32+
33+
if [ "${1}" = "-apps" ]; then
34+
/bin/sh "${LOADUP_SCRIPTDIR}/cpv" "${LOADUP_WORKDIR}"/apps.dribble "${LOADUP_OUTDIR}" \
35+
| sed -e "s#${MEDLEYDIR}/##g"
36+
fi
37+
38+
39+
/bin/sh "${LOADUP_SCRIPTDIR}/cpv" "${LOADUP_WORKDIR}"/RDSYS library \
40+
| sed -e "s#${MEDLEYDIR}/##g"
41+
/bin/sh "${LOADUP_SCRIPTDIR}/cpv" "${LOADUP_WORKDIR}"/RDSYS.LCOM library \
42+
| sed -e "s#${MEDLEYDIR}/##g"
43+
44+
45+
echo "<<<<< END ${script_name}"
46+
echo ""
47+
exit 0
48+
}
49+
50+
51+
52+
# shellcheck disable=SC2164,SC2034
53+
if [ -z "${LOADUP_SCRIPTDIR}" ]
54+
then
55+
#
56+
#
57+
# Some functions to determine what directory this script is being executed from
58+
#
59+
#
60+
get_abs_filename() {
61+
# $1 : relative filename
62+
echo "$(cd "$(dirname "$1")" && pwd)/$(basename "$1")"
63+
}
64+
65+
# This function taken from
66+
# https://stackoverflow.com/questions/29832037/how-to-get-script-directory-in-posix-sh
67+
rreadlink() (
68+
69+
# Execute this function in a *subshell* to localize variables and the effect of `cd`.
2870

71+
target=$1
72+
fname=
73+
targetDir=
74+
CDPATH=
2975

30-
./scripts/cpv "${LOADUP_WORKDIR}"/RDSYS library | sed -e "s#${MEDLEYDIR}/##g"
31-
./scripts/cpv "${LOADUP_WORKDIR}"/RDSYS.LCOM library | sed -e "s#${MEDLEYDIR}/##g"
76+
# Try to make the execution environment as predictable as possible:
77+
# All commands below are invoked via `command`, so we must make sure that `command`
78+
# itself is not redefined as an alias or shell function.
79+
# (Note that command is too inconsistent across shells, so we don't use it.)
80+
# `command` is a *builtin* in bash, dash, ksh, zsh, and some platforms do not even have
81+
# an external utility version of it (e.g, Ubuntu).
82+
# `command` bypasses aliases and shell functions and also finds builtins
83+
# in bash, dash, and ksh. In zsh, option POSIX_BUILTINS must be turned on for that
84+
# to happen.
85+
{ \unalias command; \unset -f command; } >/dev/null 2>&1
86+
[ -n "$ZSH_VERSION" ] && options[POSIX_BUILTINS]=on # make zsh find *builtins* with `command` too.
87+
88+
while :; do # Resolve potential symlinks until the ultimate target is found.
89+
[ -L "$target" ] || [ -e "$target" ] || { command printf '%s\n' "ERROR: '$target' does not exist." >&2; return 1; }
90+
command cd "$(command dirname -- "$target")" # Change to target dir; necessary for correct resolution of target path.
91+
fname=$(command basename -- "$target") # Extract filename.
92+
[ "$fname" = '/' ] && fname='' # !! curiously, `basename /` returns '/'
93+
if [ -L "$fname" ]; then
94+
# Extract [next] target path, which may be defined
95+
# *relative* to the symlink's own directory.
96+
# Note: We parse `ls -l` output to find the symlink target
97+
# which is the only POSIX-compliant, albeit somewhat fragile, way.
98+
target=$(command ls -l "$fname")
99+
target=${target#* -> }
100+
continue # Resolve [next] symlink target.
101+
fi
102+
break # Ultimate target reached.
103+
done
104+
targetDir=$(command pwd -P) # Get canonical dir. path
105+
# Output the ultimate target's canonical path.
106+
# Note that we manually resolve paths ending in /. and /.. to make sure we have a normalized path.
107+
if [ "$fname" = '.' ]; then
108+
command printf '%s\n' "${targetDir%/}"
109+
elif [ "$fname" = '..' ]; then
110+
# Caveat: something like /var/.. will resolve to /private (assuming /var@ -> /private/var), i.e. the '..' is applied
111+
# AFTER canonicalization.
112+
command printf '%s\n' "$(command dirname -- "${targetDir}")"
113+
else
114+
command printf '%s\n' "${targetDir%/}/$fname"
115+
fi
116+
)
117+
118+
get_script_dir() {
119+
120+
# call this with $0 (from main script) as its (only) parameter
121+
# if you need to preserve cwd, run this is a subshell since
122+
# it can change cwd
123+
124+
# set -x
125+
126+
local_SCRIPT_PATH="$( get_abs_filename "$1" )";
127+
128+
while [ -h "$local_SCRIPT_PATH" ];
129+
do
130+
cd "$( dirname -- "$local_SCRIPT_PATH"; )";
131+
local_SCRIPT_PATH="$( rreadlink "$local_SCRIPT_PATH" )";
132+
done
133+
134+
cd "$( dirname -- "$local_SCRIPT_PATH"; )" > '/dev/null';
135+
local_SCRIPT_PATH="$( pwd; )";
136+
137+
# set +x
138+
139+
echo "${local_SCRIPT_PATH}"
140+
}
141+
142+
# end of script directory functions
143+
###############################################################################
144+
145+
# figure out the script dir
146+
LOADUP_SCRIPTDIR="$(get_script_dir "$0")"
147+
export LOADUP_SCRIPTDIR
148+
149+
fi
32150

33-
echo "<<<<< END ${script_name}"
34-
echo ""
35-
exit 0
151+
main "$@"

scripts/copy-db.sh

+112-11
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,118 @@
11
#!/bin/sh
22

3-
if [ ! -x run-medley ] ; then
4-
echo run from MEDLEYDIR
5-
exit 1
6-
fi
3+
main() {
4+
5+
# shellcheck source=./loadup-setup.sh
6+
. "${LOADUP_SCRIPTDIR}/loadup-setup.sh"
7+
8+
echo ">>>>> START ${script_name}"
9+
10+
/bin/sh "${LOADUP_SCRIPTDIR}/cpv" "${LOADUP_WORKDIR}"/fuller.database "${LOADUP_OUTDIR}"
11+
/bin/sh "${LOADUP_SCRIPTDIR}/cpv" "${LOADUP_WORKDIR}"/fuller.dribble "${LOADUP_OUTDIR}"
12+
13+
echo "<<<<< END ${script_name}"
14+
echo ""
15+
exit 0
16+
}
17+
18+
19+
# shellcheck disable=SC2164,SC2034
20+
if [ -z "${LOADUP_SCRIPTDIR}" ]
21+
then
22+
#
23+
#
24+
# Some functions to determine what directory this script is being executed from
25+
#
26+
#
27+
get_abs_filename() {
28+
# $1 : relative filename
29+
echo "$(cd "$(dirname "$1")" && pwd)/$(basename "$1")"
30+
}
31+
32+
# This function taken from
33+
# https://stackoverflow.com/questions/29832037/how-to-get-script-directory-in-posix-sh
34+
rreadlink() (
35+
36+
# Execute this function in a *subshell* to localize variables and the effect of `cd`.
37+
38+
target=$1
39+
fname=
40+
targetDir=
41+
CDPATH=
42+
43+
# Try to make the execution environment as predictable as possible:
44+
# All commands below are invoked via `command`, so we must make sure that `command`
45+
# itself is not redefined as an alias or shell function.
46+
# (Note that command is too inconsistent across shells, so we don't use it.)
47+
# `command` is a *builtin* in bash, dash, ksh, zsh, and some platforms do not even have
48+
# an external utility version of it (e.g, Ubuntu).
49+
# `command` bypasses aliases and shell functions and also finds builtins
50+
# in bash, dash, and ksh. In zsh, option POSIX_BUILTINS must be turned on for that
51+
# to happen.
52+
{ \unalias command; \unset -f command; } >/dev/null 2>&1
53+
[ -n "$ZSH_VERSION" ] && options[POSIX_BUILTINS]=on # make zsh find *builtins* with `command` too.
754

8-
. scripts/loadup-setup.sh
55+
while :; do # Resolve potential symlinks until the ultimate target is found.
56+
[ -L "$target" ] || [ -e "$target" ] || { command printf '%s\n' "ERROR: '$target' does not exist." >&2; return 1; }
57+
command cd "$(command dirname -- "$target")" # Change to target dir; necessary for correct resolution of target path.
58+
fname=$(command basename -- "$target") # Extract filename.
59+
[ "$fname" = '/' ] && fname='' # !! curiously, `basename /` returns '/'
60+
if [ -L "$fname" ]; then
61+
# Extract [next] target path, which may be defined
62+
# *relative* to the symlink's own directory.
63+
# Note: We parse `ls -l` output to find the symlink target
64+
# which is the only POSIX-compliant, albeit somewhat fragile, way.
65+
target=$(command ls -l "$fname")
66+
target=${target#* -> }
67+
continue # Resolve [next] symlink target.
68+
fi
69+
break # Ultimate target reached.
70+
done
71+
targetDir=$(command pwd -P) # Get canonical dir. path
72+
# Output the ultimate target's canonical path.
73+
# Note that we manually resolve paths ending in /. and /.. to make sure we have a normalized path.
74+
if [ "$fname" = '.' ]; then
75+
command printf '%s\n' "${targetDir%/}"
76+
elif [ "$fname" = '..' ]; then
77+
# Caveat: something like /var/.. will resolve to /private (assuming /var@ -> /private/var), i.e. the '..' is applied
78+
# AFTER canonicalization.
79+
command printf '%s\n' "$(command dirname -- "${targetDir}")"
80+
else
81+
command printf '%s\n' "${targetDir%/}/$fname"
82+
fi
83+
)
984

10-
echo ">>>>> START ${script_name}"
85+
get_script_dir() {
1186

12-
./scripts/cpv "${LOADUP_WORKDIR}"/fuller.database "${LOADUP_OUTDIR}"
13-
./scripts/cpv "${LOADUP_WORKDIR}"/fuller.dribble "${LOADUP_OUTDIR}"
87+
# call this with $0 (from main script) as its (only) parameter
88+
# if you need to preserve cwd, run this is a subshell since
89+
# it can change cwd
90+
91+
# set -x
92+
93+
local_SCRIPT_PATH="$( get_abs_filename "$1" )";
94+
95+
while [ -h "$local_SCRIPT_PATH" ];
96+
do
97+
cd "$( dirname -- "$local_SCRIPT_PATH"; )";
98+
local_SCRIPT_PATH="$( rreadlink "$local_SCRIPT_PATH" )";
99+
done
100+
101+
cd "$( dirname -- "$local_SCRIPT_PATH"; )" > '/dev/null';
102+
local_SCRIPT_PATH="$( pwd; )";
103+
104+
# set +x
105+
106+
echo "${local_SCRIPT_PATH}"
107+
}
108+
109+
# end of script directory functions
110+
###############################################################################
111+
112+
# figure out the script dir
113+
LOADUP_SCRIPTDIR="$(get_script_dir "$0")"
114+
export LOADUP_SCRIPTDIR
115+
116+
fi
14117

15-
echo "<<<<< END ${script_name}"
16-
echo ""
17-
exit 0
118+
main "$@"

0 commit comments

Comments
 (0)