From 965db646662ff61668c71b9971aecc6ee2b3aa38 Mon Sep 17 00:00:00 2001 From: Peder Bergebakken Sundt Date: Thu, 27 Feb 2025 14:51:06 +0100 Subject: [PATCH] initial commit --- do.sh | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 do.sh diff --git a/do.sh b/do.sh new file mode 100644 index 0000000..bf228ea --- /dev/null +++ b/do.sh @@ -0,0 +1,55 @@ +#!/usr/bin/env nix-shell +#!nix-shell -i bash -p nar-serve wget nix-locate man xz gzip bzip2 +set -euo pipefail + +N_WORKERS=4 + +# TODO: allow to pick which nix-index to fetch and use + +# https://github.com/numtide/nar-serve +HTTP_ADDR=localhost:8383 nar-serve & +NAR_SERVE_PID=$! +trap "set -x; kill $NAR_SERVE_PID" EXIT SIGHUP SIGINT SIGQUIT +let N_WORKERS+=1 + +while read attrpath size type storepath _; do + outpath="data/$attrpath/$(cut -d/ -f7- <<<"$storepath")" + test -s "$outpath" || ( + mkdir -vp "$(dirname "$outpath")" + set -x + wget http://localhost:8383"$storepath" -O "$outpath" || true + ) + + if [[ ! -s "$outpath" ]]; then + continue + fi + + ( + if [[ "$outpath" =~ .*\.gz$ ]]; then + htmlpath="html/$attrpath/$(cut -d/ -f7- <<<"$storepath" | rev | cut -d. -f2- | rev).html" + test -s "$htmlpath" || ( set -x; + mkdir -p "$(dirname "$htmlpath")"; man --html=cat <(zcat "$outpath") > "$htmlpath" + ) + elif [[ "$outpath" =~ .*\.bz2$ ]]; then + htmlpath="html/$attrpath/$(cut -d/ -f7- <<<"$storepath" | rev | cut -d. -f2- | rev).html" + test -s "$htmlpath" || ( set -x; + mkdir -p "$(dirname "$htmlpath")"; man --html=cat <(bzcat "$outpath") > "$htmlpath" + ) + elif [[ "$outpath" =~ .*\.xz$ ]]; then + htmlpath="html/$attrpath/$(cut -d/ -f7- <<<"$storepath" | rev | cut -d. -f2- | rev).html" + test -s "$htmlpath" || ( set -x; + mkdir -p "$(dirname "$htmlpath")"; man --html=cat <(xzcat "$outpath") > "$htmlpath" + ) + else + htmlpath="html/$attrpath/$(cut -d/ -f7- <<<"$storepath").html" + test -s "$htmlpath" || ( set -x; + mkdir -p "$(dirname "$htmlpath")"; man --html=cat "$outpath" > "$htmlpath" + ) + fi + ) & + + while [[ $(jobs -p | wc -l) -ge $N_WORKERS ]]; do + wait -n < <(jobs -p) || true + done + +done < <(nix-locate --regex '^/share/man/man[0-9]*/.*' --top-level | tr -s ' ')