From 04f201dc7d286c31bf6fb3ec94b52e06c28a5c18 Mon Sep 17 00:00:00 2001 From: Matthijs van der Wild Date: Fri, 13 Mar 2026 14:16:39 +0000 Subject: Publish input directory recursively I want to have some control over how the input directory is processed. publish() takes the input directory and scans its immediate contents. Files are copied to the output directory, and publish is applied to the subdirectories again. I added the convention that, if a subdirectory starts with an underscore, the contents are to be copied to the .well-known directory instead. The contents are assumed to be files and the script will fail if it contains a subdirectory. I have added a limit to how deep the script will recurse into the input directory. This is currently not exposed to the user. --- publish.sh | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/publish.sh b/publish.sh index d6d4797..1f10507 100755 --- a/publish.sh +++ b/publish.sh @@ -8,6 +8,29 @@ OUTDIR=${2} [ ! $# -eq 2 ] && echo "Usage: $0 " && exit 1 [ ! -d $INDIR ] && [ ! -d $OUTDIR ] && echo "Error: invalid input" && exit 1 -for dir in $(ls -d "$INDIR"/*/); do - cp -r $dir/* "$OUTDIR"/ -done +MAX_DEPTH=10 +publish() { + + [ $1 -gt $MAX_DEPTH ] && echo "Maximum depth exceeded." && exit 1 + + for file in $(find "$2" -maxdepth 1 -mindepth 1 -type f); do + cp $file $3/$(basename $file) + done + + for dir in $(find "$2" -maxdepth 1 -mindepth 1 -type d); do + dirname=$(basename $dir) + # If $dirname starts with an underscore the contents of + # $dir should be copied into the well-known directorie. + # It is assumed that $dir only contains files + if expr $dirname : "_"* 1> /dev/null; then + mkdir -p $OUTDIR/.well-known + cp $dir/* $OUTDIR/.well-known/ + else + output_dir=$3/$dirname + mkdir -p $output_dir + publish $(($1+1)) $dir $output_dir + fi + done +} + +publish 0 $INDIR $OUTDIR -- cgit v1.2.3