From 0fe7b296eca0c1c8dae8d125acc743e614245c8d Mon Sep 17 00:00:00 2001 From: danieli Date: Mon, 9 Sep 2019 13:33:28 +0200 Subject: [PATCH] add curl dependency check, fixes #311 use the same find_binary() function used in update and setup scripts --- install-ngxblocker | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/install-ngxblocker b/install-ngxblocker index 03ba620e0..af6479182 100755 --- a/install-ngxblocker +++ b/install-ngxblocker @@ -243,10 +243,28 @@ wget_opts() { echo $opts } +find_binary() { + local x= path= binary=$1 bin_paths='/bin /usr/bin /usr/local/bin /usr/sbin /usr/local/sbin /root/bin /root/.bin' + + for x in $bin_paths; do + path="$x/$binary" + + if [ -x $path ]; then + echo $path + return + fi + done +} + check_depends() { - # centos does not have wget installed by default - if ! wget --help >/dev/null 2>&1; then - printf "$0 requires: wget \n" + # some distros do not have these tools installed by default + if [ -z $(find_binary wget) ]; then + printf "$0 requires: 'wget' \n" + exit 1 + fi + + if [ -z $(find_binary curl) ]; then + printf "$0 requires 'curl' \n" exit 1 fi }