mirror of
https://github.com/kmein/niveum
synced 2026-03-16 10:11:08 +01:00
use lib.getExe and lib.getExe' in packaged scripts
Replace all ${pkg}/bin/name patterns with:
- lib.getExe pkg (for main executables: curl, jq, gnused, ffmpeg, etc.)
- lib.getExe' pkg "name" (for specific binaries: coreutils, util-linux, etc.)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
# Transliterate Latin-script Avestan to Avestan Unicode script
|
||||
{
|
||||
lib,
|
||||
writers,
|
||||
gnused,
|
||||
}:
|
||||
@@ -61,5 +62,5 @@ let
|
||||
'';
|
||||
in
|
||||
writers.writeDashBin "avesta" ''
|
||||
exec ${gnused}/bin/sed -f ${sedScript} "$@"
|
||||
exec ${lib.getExe gnused} -f ${sedScript} "$@"
|
||||
''
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
# Berlin BVG transit disruption checker
|
||||
{
|
||||
lib,
|
||||
writers,
|
||||
curl,
|
||||
jq,
|
||||
}:
|
||||
writers.writeDashBin "bvg" ''
|
||||
interesting="U6 N6 140 M46 184 N84"
|
||||
|
||||
${curl}/bin/curl -sSL 'https://www.bvg.de/disruption-reports/q' \
|
||||
${lib.getExe curl} -sSL 'https://www.bvg.de/disruption-reports/q' \
|
||||
--data-raw '{"variables":{},"query":"{
|
||||
allDisruptions {
|
||||
disruptions {
|
||||
@@ -40,7 +39,7 @@ writers.writeDashBin "bvg" ''
|
||||
__typename
|
||||
}
|
||||
}"}' \
|
||||
| ${jq}/bin/jq --arg interesting "$interesting" '
|
||||
| ${lib.getExe jq} --arg interesting "$interesting" '
|
||||
.data.allDisruptions.disruptions
|
||||
| map(select(
|
||||
(.linie as $linie
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
# Split a PDF into chunks of N pages
|
||||
{
|
||||
lib,
|
||||
writers,
|
||||
pdftk,
|
||||
gnugrep,
|
||||
@@ -16,15 +17,15 @@ writers.writeDashBin "chunk-pdf" ''
|
||||
exit 1
|
||||
fi
|
||||
|
||||
TOTAL_PAGES="$(${pdftk}/bin/pdftk "$INPUT_FILE" dump_data | ${gnugrep}/bin/grep NumberOfPages | ${coreutils}/bin/cut -f2 -d' ')"
|
||||
TOTAL_PAGES="$(${lib.getExe pdftk} "$INPUT_FILE" dump_data | ${lib.getExe gnugrep} NumberOfPages | ${lib.getExe' coreutils "cut"} -f2 -d' ')"
|
||||
|
||||
RUNS=$((TOTAL_PAGES/PAGES_PER_REPORT))
|
||||
|
||||
for run in $(${coreutils}/bin/seq 0 "$((RUNS-1))"); do
|
||||
for run in $(${lib.getExe' coreutils "seq"} 0 "$((RUNS-1))"); do
|
||||
start_page=$((run*PAGES_PER_REPORT+1))
|
||||
end_page=$(((run+1)*PAGES_PER_REPORT))
|
||||
output_file="chunk_$((run+1)).pdf"
|
||||
echo "splitting $INPUT_FILE from $start_page to $end_page into $output_file"
|
||||
${pdftk}/bin/pdftk "$INPUT_FILE" cat "$start_page-$end_page" output "$output_file"
|
||||
${lib.getExe pdftk} "$INPUT_FILE" cat "$start_page-$end_page" output "$output_file"
|
||||
done
|
||||
''
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
# Recover files from a corrupted exFAT SD card
|
||||
{
|
||||
lib,
|
||||
writers,
|
||||
exfatprogs,
|
||||
util-linux,
|
||||
@@ -11,24 +12,24 @@ writers.writeDashBin "fix-sd" ''
|
||||
set -efu
|
||||
|
||||
drive="''${1:?Usage: fix-sd /dev/sdX [output-dir]}"
|
||||
output_dir="''${2:-$(${coreutils}/bin/mktemp -d "''${TMPDIR:-/tmp}/fix-sd-XXXXXX")}"
|
||||
mountpoint="$(${coreutils}/bin/mktemp -d "''${TMPDIR:-/tmp}/fix-sd-mount-XXXXXX")"
|
||||
output_dir="''${2:-$(${lib.getExe' coreutils "mktemp"} -d "''${TMPDIR:-/tmp}/fix-sd-XXXXXX")}"
|
||||
mountpoint="$(${lib.getExe' coreutils "mktemp"} -d "''${TMPDIR:-/tmp}/fix-sd-mount-XXXXXX")"
|
||||
|
||||
trap clean EXIT
|
||||
clean() {
|
||||
${util-linux}/bin/umount "$mountpoint" 2>/dev/null || true
|
||||
${coreutils}/bin/rmdir "$mountpoint" 2>/dev/null || true
|
||||
${lib.getExe' util-linux "umount"} "$mountpoint" 2>/dev/null || true
|
||||
${lib.getExe' coreutils "rmdir"} "$mountpoint" 2>/dev/null || true
|
||||
}
|
||||
|
||||
filenames="$(${exfatprogs}/bin/fsck.exfat "$drive" 2>&1 | ${gnused}/bin/sed -nE "s/.* file '(.*?)' is not allocated.*/\1/p")"
|
||||
${coreutils}/bin/mkdir -p "$mountpoint" "$output_dir"
|
||||
${util-linux}/bin/mount "$drive" "$mountpoint"
|
||||
filenames="$(${lib.getExe' exfatprogs "fsck.exfat"} "$drive" 2>&1 | ${lib.getExe gnused} -nE "s/.* file '(.*?)' is not allocated.*/\1/p")"
|
||||
${lib.getExe' coreutils "mkdir"} -p "$mountpoint" "$output_dir"
|
||||
${lib.getExe' util-linux "mount"} "$drive" "$mountpoint"
|
||||
|
||||
echo "$filenames" | while read -r filename; do
|
||||
[ -n "$filename" ] || continue
|
||||
${findutils}/bin/find "$mountpoint" -type f -name "$filename" -exec ${coreutils}/bin/cp {} "$output_dir" \;
|
||||
${lib.getExe' findutils "find"} "$mountpoint" -type f -name "$filename" -exec ${lib.getExe' coreutils "cp"} {} "$output_dir" \;
|
||||
done
|
||||
|
||||
echo "Recovered files saved to $output_dir"
|
||||
${exfatprogs}/bin/fsck.exfat "$drive"
|
||||
${lib.getExe' exfatprogs "fsck.exfat"} "$drive"
|
||||
''
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
# Convert and transfer audio files to an MP3 player
|
||||
{
|
||||
lib,
|
||||
writers,
|
||||
ffmpeg,
|
||||
coreutils,
|
||||
gnugrep,
|
||||
bash,
|
||||
gnused,
|
||||
}:
|
||||
writers.writeBashBin "mp3player-write" ''
|
||||
set -e
|
||||
@@ -40,11 +41,11 @@ writers.writeBashBin "mp3player-write" ''
|
||||
echo "Warning: File '$f' does not exist, skipping."
|
||||
continue
|
||||
fi
|
||||
FILE_SIZE=$(${coreutils}/bin/stat --printf="%s" "$f")
|
||||
FILE_SIZE=$(${lib.getExe' coreutils "stat"} --printf="%s" "$f")
|
||||
TOTAL_SIZE=$((TOTAL_SIZE + FILE_SIZE / 2))
|
||||
done
|
||||
|
||||
AVAILABLE=$(${coreutils}/bin/df --output=avail "$MOUNT_POINT" | ${coreutils}/bin/tail -n 1)
|
||||
AVAILABLE=$(${lib.getExe' coreutils "df"} --output=avail "$MOUNT_POINT" | ${lib.getExe' coreutils "tail"} -n 1)
|
||||
AVAILABLE=$((AVAILABLE * 1024))
|
||||
|
||||
if [ "$TOTAL_SIZE" -gt "$AVAILABLE" ]; then
|
||||
@@ -56,18 +57,18 @@ writers.writeBashBin "mp3player-write" ''
|
||||
|
||||
sanitize_filename() {
|
||||
local name
|
||||
name=$(${coreutils}/bin/basename "$1")
|
||||
name=$(${lib.getExe' coreutils "basename"} "$1")
|
||||
name=''${name%.*}
|
||||
name=$(echo "$name" | ${coreutils}/bin/tr ' ' '_' | ${coreutils}/bin/tr -cd '[:alnum:]_-')
|
||||
name=$(echo "$name" | ${lib.getExe' coreutils "tr"} ' ' '_' | ${lib.getExe' coreutils "tr"} -cd '[:alnum:]_-')
|
||||
echo "''${name:0:50}"
|
||||
}
|
||||
|
||||
for f in "''${FILES[@]}"; do
|
||||
[ -f "$f" ] || continue
|
||||
|
||||
existing_prefixes=$(${coreutils}/bin/ls "$MOUNT_POINT" | ${gnugrep}/bin/grep -E '^[0-9].*\.mp3$' | ${coreutils}/bin/sed -E 's/^([0-9]).*/\1/' | ${coreutils}/bin/sort -n | ${coreutils}/bin/uniq)
|
||||
existing_prefixes=$(${lib.getExe' coreutils "ls"} "$MOUNT_POINT" | ${lib.getExe gnugrep} -E '^[0-9].*\.mp3$' | ${lib.getExe gnused} -E 's/^([0-9]).*/\1/' | ${lib.getExe' coreutils "sort"} -n | ${lib.getExe' coreutils "uniq"})
|
||||
for i in {0..9}; do
|
||||
if ! echo "$existing_prefixes" | ${gnugrep}/bin/grep -q "^$i$"; then
|
||||
if ! echo "$existing_prefixes" | ${lib.getExe gnugrep} -q "^$i$"; then
|
||||
PREFIX=$i
|
||||
break
|
||||
fi
|
||||
@@ -78,7 +79,7 @@ writers.writeBashBin "mp3player-write" ''
|
||||
|
||||
echo "Converting '$f' to '$OUT_PATTERN' at speed $SPEED..."
|
||||
|
||||
${ffmpeg}/bin/ffmpeg -nostdin -i "$f" \
|
||||
${lib.getExe ffmpeg} -nostdin -i "$f" \
|
||||
-filter:a "atempo=$SPEED" \
|
||||
-ar 22050 -ac 1 -c:a libmp3lame -b:a 32k \
|
||||
-f segment -segment_time 300 \
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
# Add Arabic diacritics (tashkeel) to text via alsharekh.org
|
||||
{
|
||||
lib,
|
||||
writers,
|
||||
curl,
|
||||
jq,
|
||||
}:
|
||||
writers.writeDashBin "mushakkil" ''
|
||||
${curl}/bin/curl -sSL 'https://diac.alsharekh.org/Diac/DiacText' \
|
||||
${lib.getExe curl} -sSL 'https://diac.alsharekh.org/Diac/DiacText' \
|
||||
-H "Content-Type: application/json" \
|
||||
--data-raw "$(${jq}/bin/jq --raw-input '{word: ., type: 1}')" \
|
||||
--data-raw "$(${lib.getExe jq} --raw-input '{word: ., type: 1}')" \
|
||||
--compressed \
|
||||
| ${jq}/bin/jq -r .diacWord
|
||||
| ${lib.getExe jq} -r .diacWord
|
||||
''
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
# Generate a Haddock index page for all packages visible to the current GHC
|
||||
{
|
||||
lib,
|
||||
writers,
|
||||
coreutils,
|
||||
gnugrep,
|
||||
gnused,
|
||||
graphviz,
|
||||
bash,
|
||||
}:
|
||||
writers.writeBashBin "nix-haddock-index" ''
|
||||
set -efux
|
||||
|
||||
if test -z "''${NIX_GHC-}"; then
|
||||
NIX_GHC=$(${coreutils}/bin/readlink -f "$(type -P ghc)")
|
||||
NIX_GHC=$(${lib.getExe' coreutils "readlink"} -f "$(type -P ghc)")
|
||||
fi
|
||||
|
||||
if ! echo $NIX_GHC | ${gnugrep}/bin/grep -q '^/nix/store/'; then
|
||||
if ! echo $NIX_GHC | ${lib.getExe gnugrep} -q '^/nix/store/'; then
|
||||
printf '%s: error: unsupported GHC executable path (not in Nix store): %q\n' \
|
||||
"$0" \
|
||||
"$NIX_GHC" \
|
||||
@@ -22,11 +22,11 @@ writers.writeBashBin "nix-haddock-index" ''
|
||||
exit 1
|
||||
fi
|
||||
|
||||
NIX_GHC_PREFIX=$(${coreutils}/bin/dirname "$(${coreutils}/bin/dirname "$NIX_GHC")")
|
||||
NIX_GHC_PREFIX=$(${lib.getExe' coreutils "dirname"} "$(${lib.getExe' coreutils "dirname"} "$NIX_GHC")")
|
||||
NIX_GHC_DOCDIR=$NIX_GHC_PREFIX/share/doc/ghc/html
|
||||
|
||||
main() {
|
||||
hash=$(echo $NIX_GHC_PREFIX | ${gnused}/bin/sed -n 's|^/nix/store/\([a-z0-9]\+\).*|\1|p')
|
||||
hash=$(echo $NIX_GHC_PREFIX | ${lib.getExe gnused} -n 's|^/nix/store/\([a-z0-9]\+\).*|\1|p')
|
||||
title="Haddock index for $NIX_GHC_PREFIX"
|
||||
|
||||
header=$(
|
||||
@@ -42,7 +42,7 @@ writers.writeBashBin "nix-haddock-index" ''
|
||||
eval "$(
|
||||
echo 'gen_index() {'
|
||||
echo ' html_head'
|
||||
"$NIX_GHC_PREFIX"/bin/ghc-pkg dump | ${gnused}/bin/sed -n '
|
||||
"$NIX_GHC_PREFIX"/bin/ghc-pkg dump | ${lib.getExe gnused} -n '
|
||||
s/^---$/ reset/p
|
||||
s/^\(name\|version\):\s*\([-A-Za-z0-9_.]\+\)$/ \1=\2/p
|
||||
s/^haddock-html:\s*\([-A-Za-z0-9_./]\+\)$/ haddock_html \1/p
|
||||
@@ -53,7 +53,7 @@ writers.writeBashBin "nix-haddock-index" ''
|
||||
|
||||
gen_index > $index_file
|
||||
|
||||
"$NIX_GHC_PREFIX"/bin/ghc-pkg dot | ${graphviz}/bin/tred | ${graphviz}/bin/dot -Tsvg | ${gnused}/bin/sed '
|
||||
"$NIX_GHC_PREFIX"/bin/ghc-pkg dot | ${lib.getExe' graphviz "tred"} | ${lib.getExe' graphviz "dot"} -Tsvg | ${lib.getExe gnused} '
|
||||
s/<svg width="[0-9]\+pt" height="[0-9]\+pt"/<svg width="3600px" height="100%"/
|
||||
' > $svg_file
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
# OCR a PDF file to text using tesseract
|
||||
{
|
||||
lib,
|
||||
writers,
|
||||
poppler_utils,
|
||||
tesseract,
|
||||
@@ -8,21 +9,21 @@
|
||||
writers.writeDashBin "pdf-ocr" ''
|
||||
set -efu
|
||||
|
||||
pdf_path="$(${coreutils}/bin/realpath "$1")"
|
||||
pdf_path="$(${lib.getExe' coreutils "realpath"} "$1")"
|
||||
|
||||
[ -f "$pdf_path" ] || {
|
||||
echo "Usage: pdf-ocr FILE.pdf" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
tmpdir="$(${coreutils}/bin/mktemp -d)"
|
||||
tmpdir="$(${lib.getExe' coreutils "mktemp"} -d)"
|
||||
trap 'rm -rf $tmpdir' EXIT
|
||||
|
||||
cd "$tmpdir"
|
||||
|
||||
${poppler_utils}/bin/pdftoppm -png "$pdf_path" pdf-ocr
|
||||
${lib.getExe' poppler_utils "pdftoppm"} -png "$pdf_path" pdf-ocr
|
||||
for png in pdf-ocr*.png; do
|
||||
${tesseract}/bin/tesseract "$png" "$png.txt" 2>/dev/null
|
||||
${lib.getExe tesseract} "$png" "$png.txt" 2>/dev/null
|
||||
done
|
||||
|
||||
cat pdf-ocr-*.txt
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
# Render a GitHub repo's README.md as a man page
|
||||
{
|
||||
lib,
|
||||
writers,
|
||||
curl,
|
||||
pandoc,
|
||||
man,
|
||||
}:
|
||||
writers.writeDashBin "readme" ''
|
||||
${curl}/bin/curl -sSL "https://raw.githubusercontent.com/$*/master/README.md" \
|
||||
| ${pandoc}/bin/pandoc -f gfm -t man -s \
|
||||
| ${man}/bin/man -l -
|
||||
${lib.getExe curl} -sSL "https://raw.githubusercontent.com/$*/master/README.md" \
|
||||
| ${lib.getExe pandoc} -f gfm -t man -s \
|
||||
| ${lib.getExe man} -l -
|
||||
''
|
||||
|
||||
Reference in New Issue
Block a user