initial commit
This commit is contained in:
55
do.sh
Normal file
55
do.sh
Normal file
@@ -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 ' ')
|
||||
Reference in New Issue
Block a user