diff --git a/setup-ngxblocker b/setup-ngxblocker index 86e341cc4..94124b5bc 100755 --- a/setup-ngxblocker +++ b/setup-ngxblocker @@ -22,21 +22,21 @@ INC_DDOS="Y" ####### end user configuration ########################### usage() { - local script=$(basename $0) - cat </dev/null; then + printf "$msg absolute path.\n" + exit 1 + fi + ;; + none) printf "$msg argument.\n"; exit 1;; + esac +} + get_options() { - local options=$(getopt -o w:e:v:b:c:m:ndhx --long \ - www:,ext:,vhost:,bots:,conf:,main:,names,ddos,help,exec -- "$@" 2>/dev/null) + local arg= opts= - if [ $? -ne 0 ]; then - usage - exit 1 - fi + while getopts :w:e:v:b:c:m:ndxh opts "$@" + do + if [ -n "${OPTARG}" ]; then + case "$opts" in + e) arg=$(sanitize_ext ${OPTARG});; + *) arg=$(sanitize_path ${OPTARG});; + esac + fi - eval set -- "$options" - - while :; do - case "$1" in - -h | --help) usage && exit 1;; - -x | --exec) DRY_RUN=N; shift;; - -w | --www) WWW=$2; shift 2;; - -e | --ext) VHOST_EXT=$2; shift 2;; - -v | --vhost) VHOST_DIR=$2; shift 2;; - -b | --bots) BOTS_DIR=$2; shift 2;; - -c | --conf) CONF_DIR=$2; shift 2;; - -m | --main) MAIN_CONF=$2; shift 2;; - -n | --names) DOT_NAMES=N; shift;; - -d | --ddos) INC_DDOS=N; shift;; - *) break;; + case "$opts" in + w) WWW=$arg; check_args $opts path $arg ;; + e) VHOST_EXT=$arg;; + v) VHOST_DIR=$arg; check_args $opts path $arg ;; + b) BOTS_DIR=$arg; check_args $opts path $arg ;; + c) CONF_DIR=$arg; check_args $opts path $arg ;; + m) MAIN_CONF=$arg; check_args $opts path $arg ;; + n) DOT_NAMES=N ;; + d) INC_DDOS=N ;; + x) DRY_RUN=N ;; + h) usage ;; + \?) usage ;; + :) check_args $OPTARG none none ;; esac done }