Skip to content

Instantly share code, notes, and snippets.

@chernjie
Last active December 27, 2015 08:49
Show Gist options
  • Save chernjie/7299330 to your computer and use it in GitHub Desktop.
Save chernjie/7299330 to your computer and use it in GitHub Desktop.
find programme, if not found attempts to install
#!/bin/bash
function autoinst()
{
declare -a _list=()
for i
do
command -v "$i" > /dev/null || _list[${#_list[@]}]="$i"
done
test ${#_list[@]} -eq 0 && return
local _attempt=0
for j in brew apt-get port yum
do
command -v "$j" > /dev/null || continue
local _attempt=1
sudo "$j" install -y -q ${_list[@]}
return
done
test $_attempt -eq 1 &&
echo "Unable to find or install ${_list[@]}" >&2 &&
exit 1
}
@chernjie
Copy link
Author

There's a bug where if neither of brew apt-get port yum exists, it will skip with a exit code of 0

@chernjie
Copy link
Author

brew does not allow sudo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment