Ver Fonte

track dependencies

Daniel Sheffield há 3 meses atrás
pai
commit
98bfbcf5b3
2 ficheiros alterados com 38 adições e 0 exclusões
  1. 33 0
      helpers/common.sh
  2. 5 0
      recall.sh

+ 33 - 0
helpers/common.sh

@@ -1,3 +1,22 @@
+#!/bin/bash
+ESSENTIAL_GENERIC=(
+	cat
+	echo
+	ls
+	sort
+)
+ESSENTIAL_SYSTEM_SPECIFIC=(
+	awk
+	find
+	head
+	tail
+	xargs
+)
+NONESSENTIAL=(
+	# TODO: add built-in minimal replacement for fzf
+	fzf
+)
+
 get_subprog () {
 	# NOTE: for progams that wrap calls to others
 	#       such as sudo, and time, the actual
@@ -10,3 +29,17 @@ get_subprog () {
 		echo "$2" # naive - what if sudo is invoked with options?
 	fi
 }
+
+check_deps () {
+	for dep in "${ESSENTIAL_GENERIC[@]}" "${ESSENTIAL_SYSTEM_SPECIFIC[@]}"
+	do
+		which "$dep" || {
+			echo "essential dependencies missing: $dep" >&3
+			exit 1
+		}
+	done
+	for dep in "${NONESSENTIAL[@]}"
+	do
+		which "$dep" || echo "non-essential dependencies missing: $dep" >&2
+	done
+}

+ 5 - 0
recall.sh

@@ -8,6 +8,11 @@ fi
 
 . "${BASH_SOURCE[0]%/*}"/helpers/common.sh
 
+stderr_deps=/dev/null
+# NOTE: uncomment to see err output from `which` (if any)
+#stderr_deps='/proc/self/fd/2'
+check_deps 3>&2 2>"$stderr_deps" 1>/dev/null
+
 LOG_ROOT="$HOME"/.local/var/log/shell # source this
 
 EXIT_SUCCESS=false