From 5dd24c395808d68d2877406cc27f9601a8f0e6b5 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sun, 28 Feb 2021 16:51:28 +0100 Subject: [PATCH] bin: process-batch: implement startbot for webhook --- bashbot.sh | 3 ++- bin/process_batch.sh | 22 ++++++++++++++++++---- modules/processUpdates.sh | 5 ++--- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index e704ac3..b8a8b79 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -30,7 +30,7 @@ BOTCOMMANDS="-h help init start stop status suspendback resumeback killb # 8 - curl/wget missing # 10 - not bash! # -#### $$VERSION$$ v1.45-dev-48-gf4d45d8 +#### $$VERSION$$ v1.45-dev-54-gdda86e3 ################################################################## # are we running in a terminal? @@ -830,6 +830,7 @@ if [ -z "${SOURCE}" ]; then # finally starts the read update loop, internal use only "startbot" ) _exec_if_function start_bot "$2" + _exec_if_function get_updates "$2" debug_checks "end startbot" "$@" exit ;; diff --git a/bin/process_batch.sh b/bin/process_batch.sh index dd40d28..fcbc2c0 100755 --- a/bin/process_batch.sh +++ b/bin/process_batch.sh @@ -4,10 +4,11 @@ # # FILE: bin/process_batch.sh # -USAGE='process_update.sh [-h|--help] -w|--watch [-n|--lines n] [file] [debug]' +USAGE='process_update.sh [-h|--help] [-s|--startbot] [-w|--watch] [-n|--lines n] [file] [debug]' # # DESCRIPTION: processes last 10 telegram updates in file, one update per line # +# -s --startbot load addons, start TIMER, trigger startup actions # -w --watch watch for new updates added to file # -n --lines read only last "n" lines # file to read updates from @@ -20,7 +21,7 @@ USAGE='process_update.sh [-h|--help] -w|--watch [-n|--lines n] [file] [debug]' # AUTHOR: KayM (gnadelwartz), kay@rrr.de # CREATED: 27.02.2021 13:14 # -#### $$VERSION$$ v1.45-dev-53-g941598d +#### $$VERSION$$ v1.45-dev-54-gdda86e3 #=============================================================================== #### @@ -29,6 +30,10 @@ COMMAND="process_multi_updates" lines="-n 10" case "$1" in + "-s"|"--startbot") + startbot="yes" + shift + ;; "-f"|"--follow") follow="-f" shift @@ -43,20 +48,29 @@ esac source "${0%/*}/bashbot_env.inc.sh" "debug" # debug print_help "${1:-nix}" - # empty file is webhook file="${WEBHOOK}" [ -n "$1" ] && file="$1" +# start bot +if [ -n "${startbot}" ]; then + # warn when starting bot without pipe + [ -p "${WEBHOOK}" ] || printf "%b\n" "${ORANGE}Warning${NC}: File is not a pipe:${GREY} ${file##*/}${NC}" + start_bot "$2" +fi +# check file exist if [[ ! -r "${file}" || -d "${file}" ]]; then - printf "%b\n" "File ${GREY}${file}${NC} is not readable or is a directory." + printf "%b\n" "${RED}Error${NC}: File not readable:${GREY} ${file}${NC}." exit 1 fi #### # ready, do stuff here ----- + +# kill all sub processes on exit trap 'kill $(jobs -p) 2>/dev/null' EXIT HUP QUIT +# use tail to read appended updates # shellcheck disable=SC2086,SC2248 tail ${follow} ${lines} "${file}" |\ while IFS="" read -r input diff --git a/modules/processUpdates.sh b/modules/processUpdates.sh index 9638740..5c188b2 100644 --- a/modules/processUpdates.sh +++ b/modules/processUpdates.sh @@ -4,7 +4,7 @@ # File: processUpdates.sh # Note: DO NOT EDIT! this file will be overwritten on update # -#### $$VERSION$$ v1.45-dev-38-g882efa8 +#### $$VERSION$$ v1.45-dev-54-gdda86e3 ################################################################## ############## @@ -301,7 +301,7 @@ start_bot() { log_debug "${DEBUGMSG}"; DEBUGMSG="$1" [[ "${DEBUGMSG}" == "xdebug"* ]] && set -x # cleaup old pipes and empty logfiles - find "${DATADIR}" -type p -delete + find "${DATADIR}" -type p -not -name "webhook-fifo-*" -delete find "${DATADIR}" -size 0 -name "*.log" -delete # load addons on startup for addons in "${ADDONDIR:-.}"/*.sh ; do @@ -330,7 +330,6 @@ start_bot() { send_normal_message "$(getConfigKey "botadmin")" "Bot $(getConfigKey "botname") started ..." & ########## # bot is ready, start processing updates ... - get_updates "${DEBUGMSG}" }