Created
October 14, 2018 20:09
-
-
Save khenidak/2a1ff075b0aa2aa6040b0466e3f7f31a to your computer and use it in GitHub Desktop.
Handy for preping whatever tools your script needs.
This file contains hidden or 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
# 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