Skip to content

Instantly share code, notes, and snippets.

@khenidak
Created October 14, 2018 20:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save khenidak/2a1ff075b0aa2aa6040b0466e3f7f31a to your computer and use it in GitHub Desktop.
Save khenidak/2a1ff075b0aa2aa6040b0466e3f7f31a to your computer and use it in GitHub Desktop.
Handy for preping whatever tools your script needs.
# on a debian system
# expects $1 as "<binary>:<package> <binary>:<package>"
# example "qemu-img:qemu-utils nslookup:dnsutils"
# if you are not sure which package has your binary
# use apt-file search <binary name>
# we don't handle error here. so make sure you are
# using the correct binary and package names in design time
ensure_tooling(){
local req_tools=($1)
for tool in "${req_tools[@]}"; do
local package_name="${tool#*:}"
local binary_name="${tool%:*}"
if ! which ${binary_name} >> /dev/null 2>&1 ; then
echo "${binary_name} is not found, installing ${package_name}"
sudo apt install -y "${package_name}" >> /dev/null 2>&1
echo "${package_name} installed"
fi
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment