-
-
Save amake/e090d51fb894b401e2c140bed4a619b6 to your computer and use it in GitHub Desktop.
CLI tool-installing wrapper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
if [ $# -lt 1 ]; then | |
echo "Usage: $0 <tool> [args...]" | |
exit 1 | |
fi | |
tool="$1" | |
shift | |
if ! command -v "$tool" >/dev/null; then | |
(apt update && apt install -y --no-install-recommends "$tool") <&- | |
fi | |
exec "$tool" "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A wrapper for a tool that might not be installed, such as zstd. The tool will be installed if not present. Importantly, both args and stdin are properly passed to the wrapped tool even when installation happens. The magic is
<&-
which closes stdin for the installing subshell so that the original stdin is not consumed.Mostly useful for e.g. CI where you want a particular tool installed on-demand but don't want to have to provide your own runner image.
Assumes the tool binary name and the APT package name are the same.