Merge pull request #99 from itoffshore/alpine

Various small fixes
This commit is contained in:
Mitchell Krog 2017-09-20 15:58:33 +02:00 committed by GitHub
commit 12509b9d2d
3 changed files with 24 additions and 13 deletions

View file

@ -141,6 +141,16 @@ download_files() {
fi
}
set_mode() {
local mode=$1 dir=$2 file=
local file_list="$(echo $@ | awk '{$1=$2=""; print}' | sed -e 's/^[ \t]*//')"
for file in $file_list; do
printf "Setting mode: $mode => $dir/$file\n"
chmod $mode $dir/$file
done
}
check_config() {
local x= dirs="$*"
@ -283,6 +293,11 @@ main() {
download_files conf.d $CONF_DIR $CONF_FILES
download_files bots.d $BOTS_DIR $BOT_FILES
download_files / $SCRIPT_DIR $SCRIPT_FILES
# ensures scripts are executable
if [ "$DRY_RUN" = "N" ]; then
set_mode 700 $SCRIPT_DIR $SCRIPT_FILES
fi
}
## START ##

View file

@ -186,8 +186,9 @@ find_line() {
local file=$1 find_str=$2 first_last=$3
case "$first_last" in
first) awk "/$find_str/{ print NR; exit }" $file;;
last) awk "/$find_str/{ print NR }" $file | tail -n1;;
# ignore file #comments
first) grep -nE "^[ ]+$find_str" $file | head -n1 | awk -F: '{print $1}';;
last) grep -nE "^[ ]+$find_str" $file | tail -n1 | awk -F: '{print $1}';;
esac
}

View file

@ -53,7 +53,7 @@ Usage: $script [OPTIONS]
[ -b ] : NGINX bots directory (default: $BOTS_DIR)
[ -i ] : Change installer path (default: $INSTALLER)
[ -r ] : Change repo url (default: $REPO)
[ -e ] : Change email address (default: $EMAIL)
[ -m ] : Change email address (default: $EMAIL)
[ -n ] : Do not send email report (default: $SEND_EMAIL)
[ -v ] : Print blacklist version
[ -h ] : this help message
@ -194,20 +194,14 @@ check_args() {
}
check_mail_depends() {
if [ ! -f /usr/bin/mail ]; then # mailx + ssmtp are enough to send emails
printf "${BOLDYELLOW}WARN${RESET}: missing /usr/bin/mail => ${BOLDWHITE}disabling emails${RESET}.\n\n"
if [ ! -f /usr/bin/mail ] && [ ! -f /bin/mail ]; then # mailx + ssmtp are enough to send emails
printf "${BOLDYELLOW}WARN${RESET}: missing mail command => ${BOLDWHITE}disabling emails${RESET}.\n\n"
SEND_EMAIL="N"
fi
}
check_depends() {
# centos does not have wget installed by default
if ! wget --help >/dev/null 2>&1; then
printf "${BOLDRED}ERROR${RESET}: $0 requires: 'wget' => ${BOLDWHITE}cannot download files.${RESET}\n"
exit 1
fi
# centos also does not have which by default
# centos does not have which by default
if [ ! -x /usr/bin/curl ]; then
printf "${BOLDRED}ERROR${RESET}: $0 requires: 'curl' => ${BOLDWHITE}cannot check remote version.${RESET}\n"
exit 1
@ -223,7 +217,7 @@ check_depends() {
get_options() {
local arg= opts=
while getopts :c:b:u:r:e:nvh opts "$@"
while getopts :c:b:u:r:e:m:nvh opts "$@"
do
if [ -n "${OPTARG}" ]; then
case "$opts" in
@ -239,6 +233,7 @@ get_options() {
i) INSTALLER=$arg; check_args $opts script $arg ;;
r) REPO=$arg; check_args $opts url $arg ;;
e) EMAIL=$arg; check_args $opts email $arg ;;
m) EMAIL=$arg; check_args $opts email $arg ;;
n) SEND_EMAIL=N ;;
v) check_depends; check_version ;;
h) usage ;;