From a035401f2eac40b9562cf3db30612ba9d77dfc11 Mon Sep 17 00:00:00 2001 From: vector-of-bool Date: Wed, 29 Oct 2025 17:39:51 -0600 Subject: [PATCH 01/12] Consolidate several small scripts into a single __tool --- tools/__alias | 85 ------------- tools/__boolstr | 15 --- tools/__fail | 6 - tools/__install | 48 -------- tools/__str | 101 ---------------- tools/__tool | 311 ++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 311 insertions(+), 255 deletions(-) delete mode 100644 tools/__alias delete mode 100644 tools/__boolstr delete mode 100644 tools/__fail delete mode 100755 tools/__install delete mode 100755 tools/__str create mode 100644 tools/__tool diff --git a/tools/__alias b/tools/__alias deleted file mode 100644 index 4799ea66654..00000000000 --- a/tools/__alias +++ /dev/null @@ -1,85 +0,0 @@ -#!/usr/bin/env sh - -# Create an alias in /usr/local/bin/ for the command given by the arguments -# Usage: -# -# __alias [ [...]] -# -# The generated alias can be invoked via , and any subsequent arguments -# are appended to the argument list that were given when __alias was invoked. - -# shellcheck disable=SC3043,SC3044 - -set -eu - -# Usage: __readvar -# Read the value of the variable named by into a variable -__readvar() { - local __readvar_tmp - eval "__readvar_tmp=\$(printf %s. \"\${$2}\"); $1=\${__readvar_tmp%.}" -} - -__fail() { - printf %s "$@" - return 1 -} - -# $ __strsub_inplace -# Replace each occurrence of with within the string variable -__strsub_inplace() { - test $# -eq 3 || __fail "__strsub_inplace expects three arguments (Got %s)" $# || return - local __strsub_varname="$1" __strsub_needle="$2" __strsub_repl="$3" - # Read the value of into __strsub_remaining - __readvar __strsub_remaining "$__strsub_varname" - # Accumulate into __strsub_acc - local __strsub_head __strsub_acc='' - while true; do - # Grab all content until the next needle: - __strsub_head=${__strsub_remaining%%"$__strsub_needle"*} - if test "$__strsub_head" = "$__strsub_remaining"; then - # Nothing match the needle, so we are done - __strsub_acc="$__strsub_acc$__strsub_remaining" - break - fi - # Everything after the needle: - __strsub_remaining=${__strsub_remaining#*"$__strsub_needle"} - # Accumulate the result: - __strsub_acc="$__strsub_acc$__strsub_head$__strsub_repl" - done - # Read the accumulated string back into the output variable: - __readvar "$__strsub_varname" __strsub_acc -} - -_ESCAPES="$(printf '[][ \t\n\r\a*?!\\\$;()\\{\\}'"'"']')" -__quote() { - local __quote_input="$1" - # shellcheck disable=SC2295 - local __quote_tmp="${__quote_input#*$_ESCAPES}" || return - if test "$__quote_input" = ""; then - # Empty string: Just emit empty quotes - printf '""' - return - elif test "$__quote_tmp" = "$__quote_input"; then - # No special chars, so don't quote it: - printf %s "$__quote_input" - return - else - # Special chars. Escape any inner quotes, then wrap in quotes - __strsub_inplace __quote_input "'" "'\\''" - printf "'%s'" "$__quote_input" - fi -} - -command='' name="$1" -shift -for x in "$@"; do - x=$(__quote "$x") - command="$command$x " -done -command="$command\"\$@\"" -filename="/usr/local/bin/$name" - -echo "#!/usr/bin/env sh" > "$filename" -echo "$command" >> "$filename" -chmod a+x "$filename" -echo "Created command alias '$filename' of [$command]" 1>&2 diff --git a/tools/__boolstr b/tools/__boolstr deleted file mode 100644 index 63e16256791..00000000000 --- a/tools/__boolstr +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env sh - -# Execute the given argument list as a command. If exits zero, prints "true", -# otherwise "false". stdout from the subcommand will be supressed. stderr will -# be forwarded. This script itself will always exit zero. - -# Usage: __boolstr [cmd...] - -"$@" 1>/dev/null - -if test $? = 0; then - printf "true" -else - printf "false" -fi diff --git a/tools/__fail b/tools/__fail deleted file mode 100644 index 01daecd68d0..00000000000 --- a/tools/__fail +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env sh - -# shellcheck disable=SC2059 -printf "$@" 1>&2 - -exit 1 diff --git a/tools/__install b/tools/__install deleted file mode 100755 index bfd93496e8b..00000000000 --- a/tools/__install +++ /dev/null @@ -1,48 +0,0 @@ -#!/usr/bin/env sh - -# Install the named packages using the platform's package manager. -# This script "just does the right thing" to install a package as a step in a -# caching container build, as a bare "pkg-tool install" might be insufficient -# or subtly broken, and we only really care about installing a list of packages -# -# Usage: