1
0
mirror of synced 2026-01-13 15:37:38 +00:00
Interlisp.medley/scripts/clean_hcfiles.sh
Frank Halasz 04d98d232f
Fix Issue 2139 (large parts of Medley tree not showing up in files.interlisp.org) and more improvements to files.interlisp.org (#2156)
Here is what this PR does:

Fix Issue 2139: (MAKE-INDEX-HTMLS) was not handling pseudohosts correctly and an errant LI pseudohost was causing MAKE-INDEX-HTMLS to terminate early. Adjusted MAKE-INDEX-HTML so it uses psuedohosts only for the top level directory and everything further down in the tree uses the truenames relative to the top-level pseudohost, Results in a MAKE-INDEX-HTMLS run that works in the presence of random pseudohosts and in a collection of index.html files without difficult to understand and out of context references to pseudohosts.

Remove loadups/build directory from all HCFILES runs (on desktop and via github actions)

Added maiko source code and removed maiko lde executables from HCFILES outputs for github actions - thus adding maiko code and removing maiki executables @ files.interlisp.org.

Fixed scripts/clean_hcfiles.sh so that it actually cleans off all of the index.html files - was missing some.

.github/workflow directory was being left out of HCFILES. Put it back it.
2025-05-26 10:18:10 -07:00

144 lines
4.4 KiB
Bash
Executable File

#!/bin/sh
#
# clean_hcfiles.sh
#
# Script to clean Medley directory after running do_hcfiles.sh.
# Removes pdf files and index.html files created by do_hcfiles.sh.
#
# Caution: uses git clean - so it will delete any untracked files in
# the Medley directory tree.
#
# FGH 2024-07-15
#
# Copyright 2024 Interlisp.org
#
main() {
MEDLEYDIR=$(cd "${SCRIPTDIR}/.." && pwd)
export MEDLEYDIR
cd "${MEDLEYDIR}" || exit
shellfile=/tmp/checkgit-$$.sh
cat >"${shellfile}" <<-'EOF'
#!/bin/sh
x=$(git ls-files "$1" 2>/dev/null)
if [ -z "$x" ]
then
rm -f "$1"
rm -f "$1".~*~
fi
EOF
chmod +x "${shellfile}"
find . -iname index.html -exec "${shellfile}" {} \;
find . -iname \*.pdf -exec "${shellfile}" {} \;
rm -f "${shellfile}"
}
# shellcheck disable=SC2164,SC2034
if [ -z "${SCRIPTDIR}" ]
then
#
#
# Some functions to determine what directory this script is being executed from
#
#
get_abs_filename() {
# $1 : relative filename
echo "$(cd "$(dirname "$1")" && pwd)/$(basename "$1")"
}
# This function taken from
# https://stackoverflow.com/questions/29832037/how-to-get-script-directory-in-posix-sh
rreadlink() (
# Execute this function in a *subshell* to localize variables and the effect of `cd`.
target=$1
fname=
targetDir=
CDPATH=
# Try to make the execution environment as predictable as possible:
# All commands below are invoked via `command`, so we must make sure that `command`
# itself is not redefined as an alias or shell function.
# (Note that command is too inconsistent across shells, so we don't use it.)
# `command` is a *builtin* in bash, dash, ksh, zsh, and some platforms do not even have
# an external utility version of it (e.g, Ubuntu).
# `command` bypasses aliases and shell functions and also finds builtins
# in bash, dash, and ksh. In zsh, option POSIX_BUILTINS must be turned on for that
# to happen.
{ \unalias command; \unset -f command; } >/dev/null 2>&1
[ -n "$ZSH_VERSION" ] && options[POSIX_BUILTINS]=on # make zsh find *builtins* with `command` too.
while :; do # Resolve potential symlinks until the ultimate target is found.
[ -L "$target" ] || [ -e "$target" ] || { command printf '%s\n' "ERROR: '$target' does not exist." >&2; return 1; }
command cd "$(command dirname -- "$target")" # Change to target dir; necessary for correct resolution of target path.
fname=$(command basename -- "$target") # Extract filename.
[ "$fname" = '/' ] && fname='' # !! curiously, `basename /` returns '/'
if [ -L "$fname" ]; then
# Extract [next] target path, which may be defined
# *relative* to the symlink's own directory.
# Note: We parse `ls -l` output to find the symlink target
# which is the only POSIX-compliant, albeit somewhat fragile, way.
target=$(command ls -l "$fname")
target=${target#* -> }
continue # Resolve [next] symlink target.
fi
break # Ultimate target reached.
done
targetDir=$(command pwd -P) # Get canonical dir. path
# Output the ultimate target's canonical path.
# Note that we manually resolve paths ending in /. and /.. to make sure we have a normalized path.
if [ "$fname" = '.' ]; then
command printf '%s\n' "${targetDir%/}"
elif [ "$fname" = '..' ]; then
# Caveat: something like /var/.. will resolve to /private (assuming /var@ -> /private/var), i.e. the '..' is applied
# AFTER canonicalization.
command printf '%s\n' "$(command dirname -- "${targetDir}")"
else
command printf '%s\n' "${targetDir%/}/$fname"
fi
)
get_script_dir() {
# call this with $0 (from main script) as its (only) parameter
# if you need to preserve cwd, run this is a subshell since
# it can change cwd
# set -x
local_SCRIPT_PATH="$( get_abs_filename "$1" )";
while [ -h "$local_SCRIPT_PATH" ];
do
cd "$( dirname -- "$local_SCRIPT_PATH"; )";
local_SCRIPT_PATH="$( rreadlink "$local_SCRIPT_PATH" )";
done
cd "$( dirname -- "$local_SCRIPT_PATH"; )" > '/dev/null';
local_SCRIPT_PATH="$( pwd; )";
# set +x
echo "${local_SCRIPT_PATH}"
}
# end of script directory functions
###############################################################################
# figure out the script dir
SCRIPTDIR="$(get_script_dir "$0")"
export SCRIPTDIR
fi
main "$@"