From 462efef034bd874d2dd748597ac80a5c18ec60c0 Mon Sep 17 00:00:00 2001 From: fatalerrors Date: Tue, 2 Jun 2026 17:49:16 +0200 Subject: [PATCH] checked dependencies, made some optional, document optional dependencies --- README.md | 42 ++++++++++++++++++++++++++++++++++++++---- profile.d/filefct.sh | 6 ++++++ profile.d/fun.sh | 5 +++++ profile.d/processes.sh | 33 +++++++++++++++++++++++++-------- profile.sh | 5 ++++- 5 files changed, 78 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index c9a3bc2..5e26f70 100644 --- a/README.md +++ b/README.md @@ -445,15 +445,49 @@ Verify support with: printf '\e[38;2;38;139;210mTrue colour test\e[0m\n' ``` -## 5. Contact and more information +## 5. Optional dependencies -### 5.1. New users +profile is designed so that every external dependency is optional: all features +degrade gracefully (an error message is shown and the specific function returns +early) when a binary is absent. The table below lists packages that are **not** +part of a standard minimal Linux installation (might differ from your actual +distribution, some are still extremely common). Nothing in this list is required +to load profile or use its core functions. + +| Binary | Typical package name | Distr. | Function(s) | Behaviour when absent | +| --- | --- | --- | --- | --- | +| `figlet` | `figlet` | all | `showinfo` | ASCII banner skipped | +| `neofetch` | `neofetch` | all | `showinfo` | Falls back to `fastfetch`, then skipped | +| `fastfetch` | `fastfetch` | all | `showinfo` | Falls back if `neofetch` absent; then skipped | +| `jq` | `jq` | all | `myextip` | Raw JSON shown instead of formatted output | +| `hexdump` | `util-linux` / `bsdmainutils` | all | `busy` | Error message, function returns 1 | +| `numfmt` | `coreutils` ≥ 8.21 | all | `file_stats --min/--max` | Error message, function returns 1 | +| `envsubst` | `gettext` | all | config loading | `$VAR` references in `profile.conf` values left literal | +| `killall` | `psmisc` | all | `ku` | Falls back to `pkill` (procps); error if both absent | +| `pkill` / `pgrep` | `procps` / `procps-ng` | all | `ku`, `ppg`, `gpid` | `ku` falls back to `killall`; `ppg`/`gpid` fall back to `ps + awk` | +| `pigz` | `pigz` | all | `taz` (gzip) | Falls back to `gzip` (slower, single-thread) | +| `plzip` | `plzip` | all | `taz` (lzip) | Falls back to `lzip` | +| `lzip` / `plzip` | `lzip` | all | `taz`/`utaz` (.lz) | Error message if neither is available | +| `xz` | `xz-utils` / `xz` | all | `taz`/`utaz` (.xz) | Error message | +| `unrar` | `unrar` / `unrar-free` | all | `utaz` (.rar) | Error message | +| `unarj` | `arj` | all | `utaz` (.arj) | Error message | +| `lha` | `lhasa` | all | `utaz` (.lzh) | Error message | +| `unace` | `unace` | all | `utaz` (.ace) | Error message | +| `7z` | `p7zip-full` | all | `taz`/`utaz` (.7z) | Error message | +| `cabextract` | `cabextract` | all | `utaz` (.cab) | Error message | +| `rpm2cpio` | `rpm` | all | `utaz` (.rpm) | Error message | +| `nix-locate` | `nix-index` | NixOS | `pkgf` | Error: unsupported package manager | +| `qfile` | `gentoolkit` | Gentoo | `pkgf` | Error: unsupported package manager | + +## 6. Contact and more information + +### 6.1. New users If you use (or plan to use) `profile`, I'll be happy if you simply mail me to let me know, especially if you don't plan to contribute. If you plan to contribute, I'll be twice happier for sure! -### 5.2. Bugs +### 6.2. Bugs **profile** bug tracker is hosted on its Gitea instance. Check the page. If you find a bug, @@ -468,7 +502,7 @@ have not tested the same code under a real Unix environment. Check the [FAQ](./doc/FAQ.md) and the [to-do list](./doc/todo.md) before sending any feature request or bug report, as it might already be documented. -### 5.3. How to contribute? +### 6.3. How to contribute? You are free to improve and contribute as you wish. If you have no idea what to do or want some direction, you can check the [to-do list](./doc/todo.md), diff --git a/profile.d/filefct.sh b/profile.d/filefct.sh index 355dd0b..c37aa95 100644 --- a/profile.d/filefct.sh +++ b/profile.d/filefct.sh @@ -471,6 +471,12 @@ file_stats() fi # Minimum/maximum size filters (evaluated in bytes) + if [[ -n "$min_size" || -n "$max_size" ]]; then + if ! command -v numfmt >/dev/null 2>&1; then + disp E "file_stats: --min/--max require 'numfmt' (GNU coreutils). Please install it." + return 1 + fi + fi if [[ -n "$min_size" ]]; then find_cmd+=(-size +"$(numfmt --from=iec "$min_size")"c) fi diff --git a/profile.d/fun.sh b/profile.d/fun.sh index 53b65e7..41f5d87 100644 --- a/profile.d/fun.sh +++ b/profile.d/fun.sh @@ -94,6 +94,11 @@ busy() delay_s=$(awk "BEGIN{ printf \"%.3f\", $delay_ms / 1000 }") + command -v hexdump >/dev/null 2>&1 || { + disp E "busy: 'hexdump' is required but not installed (util-linux or bsdmainutils)." + return 1 + } + # Monitor /dev/urandom ( hexdump -C < /dev/urandom | grep -iF --line-buffered "$pattern" | \ diff --git a/profile.d/processes.sh b/profile.d/processes.sh index 1e89085..c74b47d 100644 --- a/profile.d/processes.sh +++ b/profile.d/processes.sh @@ -199,7 +199,7 @@ export -f ppn # ------------------------------------------------------------------------------ # Get PID list of the given process name -# Usage: ppid +# Usage: gpid gpid() { local PARSED @@ -361,16 +361,33 @@ ku() disp E "User '$u' does not exist." return 1 else - local cmd=(killall) + local cmd - if [[ ${#signal_opt[@]} -gt 0 ]]; then - cmd+=("${signal_opt[@]}") - elif [[ -n "${KU_DEFAULT_SIGNAL:-}" ]]; then - cmd+=("-${KU_DEFAULT_SIGNAL}") + # killall (psmisc) preferred; fall back to pkill (procps-ng). + if command -v killall >/dev/null 2>&1; then + cmd=(killall) + if [[ ${#signal_opt[@]} -gt 0 ]]; then + cmd+=("${signal_opt[@]}") + elif [[ -n "${KU_DEFAULT_SIGNAL:-}" ]]; then + cmd+=("-${KU_DEFAULT_SIGNAL}") + fi + cmd+=(-u "$u") + elif command -v pkill >/dev/null 2>&1; then + cmd=(pkill) + # Translate killall's -s SIGNAME form to pkill's -SIGNAME form. + if [[ ${#signal_opt[@]} -eq 2 && "${signal_opt[0]}" == "-s" ]]; then + cmd+=("-${signal_opt[1]}") + elif [[ ${#signal_opt[@]} -gt 0 ]]; then + cmd+=("${signal_opt[@]}") + elif [[ -n "${KU_DEFAULT_SIGNAL:-}" ]]; then + cmd+=("-${KU_DEFAULT_SIGNAL}") + fi + cmd+=(-u "$u") + else + disp E "ku: neither 'killall' (psmisc) nor 'pkill' (procps) is available." + return 1 fi - cmd+=(-u "$u") - if (( dry_run )); then printf "DRY-RUN: " printf "%q " "${cmd[@]}" diff --git a/profile.sh b/profile.sh index 8d8d12e..786aed4 100644 --- a/profile.sh +++ b/profile.sh @@ -244,7 +244,10 @@ parse_conf() # Correctly interpretet internal variables (e.g. $HOME) if [[ "$value" == *\$* ]]; then - value=$(envsubst <<< "$value") + if command -v envsubst >/dev/null 2>&1; then + value=$(envsubst <<< "$value") + fi + # If envsubst is unavailable, $VAR references are left as-is. fi # Strip quotes (handling both " and ')