|
1 | 1 | #!/bin/sh
|
2 | 2 |
|
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" |
7 | 6 |
|
8 |
| -. scripts/loadup-setup.sh |
| 7 | + echo ">>>>> START ${script_name}" |
9 | 8 |
|
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" |
11 | 13 |
|
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 |
17 | 18 |
|
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" |
20 | 23 |
|
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`. |
28 | 70 |
|
| 71 | + target=$1 |
| 72 | + fname= |
| 73 | + targetDir= |
| 74 | + CDPATH= |
29 | 75 |
|
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 |
32 | 150 |
|
33 |
| -echo "<<<<< END ${script_name}" |
34 |
| -echo "" |
35 |
| -exit 0 |
| 151 | +main "$@" |
0 commit comments