summaryrefslogtreecommitdiff
path: root/scripts/deps
diff options
context:
space:
mode:
authorLukasz Kasprzak <lukas@labunix.xyz>2026-09-13 02:31:32 +0200
committerLukasz Kasprzak <lukas@labunix.xyz>2026-09-13 02:31:32 +0200
commit26c94eb3db62ec6eebbf8d22c11afe691d9520c4 (patch)
tree165e5bf69234b4f96c9b74deb4898d7143ddf120 /scripts/deps
parenta6e442a645902011b2081c216daaec052cdc6ce6 (diff)
downloadkrino-26c94eb3db62ec6eebbf8d22c11afe691d9520c4.tar.gz
krino-26c94eb3db62ec6eebbf8d22c11afe691d9520c4.zip
krino: release 0.0.1 — man pages, install, examples, cross and release, README, changelogv0.0.1
Also: undo removes the directories its run created; a hardlink is never a duplicate of its own other name; a flag written before "undo" is honoured; --version prints no leading v. Duplicate conditions with different scopes not sharing an original is documented as a known limitation.
Diffstat (limited to 'scripts/deps')
-rwxr-xr-xscripts/deps99
1 files changed, 99 insertions, 0 deletions
diff --git a/scripts/deps b/scripts/deps
new file mode 100755
index 0000000..06faaa2
--- /dev/null
+++ b/scripts/deps
@@ -0,0 +1,99 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-3.0-or-later
+#
+# scripts/deps: install krino's optional content extractors with the host's
+# system package manager, per docs/design.md §14.
+#
+# --print prints the exact command this script would run (and the reason,
+# when one platform's package list differs from the others), then exits
+# without running anything and without asking for privileges. `make deps`
+# calls this script with no flag; plain `make`/`make build` never calls it
+# at all, so plain `make` never asks for privileges (§14).
+#
+# Detection:
+# - Debian family - /etc/os-release's ID *or* ID_LIKE names "debian" as
+# one of its (possibly multi-word) values. Devuan is ID=devuan,
+# ID_LIKE=debian: keying on ID=debian alone would leave it unrecognised.
+# -> apt-get install poppler-utils catdoc antiword
+# - FreeBSD (uname -s) -> pkg install poppler-utils antiword. catdoc is
+# left out on purpose: it pulls in tcl/tk.
+# - OpenBSD (uname -s) -> pkg_add poppler-utils catdoc antiword
+# - anything else: print what is needed and exit non-zero. This script
+# never guesses a package manager.
+#
+# Privileges: doas if present, else sudo; if neither exists (and we are not
+# already root), the command is printed for the user to run as root
+# themselves, rather than attempting it unprivileged and failing silently.
+
+set -eu
+
+print_only=0
+case "${1:-}" in
+ --print) print_only=1 ;;
+ "") ;;
+ *)
+ echo "usage: $0 [--print]" >&2
+ exit 2
+ ;;
+esac
+
+# is_debian_family: true if /etc/os-release's ID or ID_LIKE contains
+# "debian" as one of its space-separated words.
+is_debian_family() {
+ [ -r /etc/os-release ] || return 1
+ (
+ . /etc/os-release
+ for word in ${ID:-} ${ID_LIKE:-}; do
+ [ "$word" = "debian" ] && exit 0
+ done
+ exit 1
+ )
+}
+
+# privileged CMD...: CMD prefixed with doas or sudo, whichever is found
+# first; unprefixed if we are already root or if neither exists (the
+# caller decides what to do in that last case).
+privileged() {
+ if [ "$(id -u)" = 0 ]; then
+ printf '%s\n' "$*"
+ elif command -v doas >/dev/null 2>&1; then
+ printf 'doas %s\n' "$*"
+ elif command -v sudo >/dev/null 2>&1; then
+ printf 'sudo %s\n' "$*"
+ else
+ printf '%s\n' "$*"
+ fi
+}
+
+note=""
+if is_debian_family; then
+ pkgcmd="apt-get install poppler-utils catdoc antiword"
+elif [ "$(uname -s)" = "FreeBSD" ]; then
+ pkgcmd="pkg install poppler-utils antiword"
+ note="catdoc left out on FreeBSD: it pulls in tcl/tk."
+elif [ "$(uname -s)" = "OpenBSD" ]; then
+ pkgcmd="pkg_add poppler-utils catdoc antiword"
+else
+ echo "krino's optional extractors: poppler-utils (pdftotext), catdoc, antiword" >&2
+ echo "no supported package manager detected (uname -s: $(uname -s), no debian-family /etc/os-release)" >&2
+ echo "install them yourself with whatever this system uses" >&2
+ exit 1
+fi
+
+cmd=$(privileged $pkgcmd)
+
+[ -n "$note" ] && echo "$note"
+
+if [ "$print_only" = 1 ]; then
+ echo "$cmd"
+ exit 0
+fi
+
+if [ "$(id -u)" != 0 ] && ! command -v doas >/dev/null 2>&1 && ! command -v sudo >/dev/null 2>&1; then
+ echo "neither doas nor sudo found; run this yourself as root:" >&2
+ echo "$cmd" >&2
+ exit 1
+fi
+
+echo "$cmd"
+exec $cmd