From 99950e6518b4acbebd72d90f3358478d16ea8865 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Wed, 17 Mar 2021 19:46:31 +0100 Subject: [PATCH 01/24] modules: jsshDB: fix removal of unwanted characters from untrusted input --- modules/jsonDB.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/jsonDB.sh b/modules/jsonDB.sh index 9c2d4be..6b7501e 100644 --- a/modules/jsonDB.sh +++ b/modules/jsonDB.sh @@ -5,7 +5,7 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ v1.5-0-g8adca9b +#### $$VERSION$$ v1.51-dev-0-g369124b # # source from commands.sh to use jsonDB functions # @@ -358,7 +358,7 @@ Json2Array() { # match ["....."]\t and replace \t with = and print delete ` quote true false escape not escaped $ # shellcheck disable=SC1091,SC1090 [ -z "$1" ] || source <( printf "$1"'=( %s )'\ - "$(sed -E -n -e '/\["[-0-9a-zA-Z_,."]+"\]\+*\t/ s/\t/=/p' -e 's/[`ยด]//g' -e 's/=(true|false)/="\1"/' -e 's/([^\]|^)\$/\1\\$/g')" ) + "$(sed -E -n -e 's/[`ยด]//g' -e 's/\]\t(true|false)/="\1"/' -e 's/([^\]|^)\$/\1\\$/g' -e '/\["[-0-9a-zA-Z_,."]+"\]\+*\t/ s/\t/=/p')" ) } # get Config Key from jssh file without jsshDB # output ARRAY as JSON.sh style data From 43cab461f8d1dc1ace0c69d55f25329c63376aae Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Wed, 17 Mar 2021 20:02:17 +0100 Subject: [PATCH 02/24] modules: sendMessage: send_dice add bowling --- bin/send_dice.sh | 6 +++--- modules/sendMessage.sh | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/bin/send_dice.sh b/bin/send_dice.sh index d71dae8..28c1d47 100755 --- a/bin/send_dice.sh +++ b/bin/send_dice.sh @@ -9,8 +9,8 @@ USAGE='send_dice.sh [-h|--help] "CHAT[ID]" "emoji" [debug]' # DESCRIPTION: send an animated emoji (dice) to given chat # # OPTIONS: CHAT[ID] - ID number of CHAT or BOTADMIN to send to yourself -# emoji - must be one of: โ€œ๐ŸŽฒโ€, โ€œ๐ŸŽฏโ€, โ€œ๐Ÿ€โ€, โ€œโšฝโ€, or โ€œ๐ŸŽฐโ€ -# ":game_die:" ":dart:" ":basketball:" ":soccer:" :slot_machine:" +# emoji - must be one of: โ€œ๐ŸŽฒโ€, โ€œ๐ŸŽฏโ€, โ€œ๐Ÿ€โ€, โ€œโšฝโ€ โ€œ๐ŸŽฐโ€ "๐ŸŽณ" +# :game_die: :dart: :basketball: :soccer: :slot_machine: :bowling: # # -h - display short help # --help - this help @@ -21,7 +21,7 @@ USAGE='send_dice.sh [-h|--help] "CHAT[ID]" "emoji" [debug]' # AUTHOR: KayM (gnadelwartz), kay@rrr.de # CREATED: 07.02.2021 18:45 # -#### $$VERSION$$ v1.5-0-g8adca9b +#### $$VERSION$$ v1.51-dev-1-g99950e6 #=============================================================================== #### diff --git a/modules/sendMessage.sh b/modules/sendMessage.sh index b6e2df3..913cdb1 100644 --- a/modules/sendMessage.sh +++ b/modules/sendMessage.sh @@ -6,7 +6,7 @@ # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # # shellcheck disable=SC1117 -#### $$VERSION$$ v1.5-0-g8adca9b +#### $$VERSION$$ v1.51-dev-1-g99950e6 # will be automatically sourced from bashbot @@ -333,7 +333,7 @@ send_action() { [ -n "${BOTSENT[ERROR]}" ] && processError "${FUNCNAME[0]}" "${BOTSENT[ERROR]}" "$1" "" "${BOTSENT[DESCRIPTION]}" "$2" } -# $1 chat $2 emoji โ€œ๐ŸŽฒโ€, โ€œ๐ŸŽฏโ€, โ€œ๐Ÿ€โ€, โ€œโšฝโ€, โ€œ๐ŸŽฐ" +# $1 chat $2 emoji โ€œ๐ŸŽฒโ€, โ€œ๐ŸŽฏโ€, โ€œ๐Ÿ€โ€, โ€œโšฝโ€, โ€œ๐ŸŽฐ" "๐ŸŽณ" # code: "\ud83c\udfb2" "\ud83c\udfaf" "\ud83c\udfc0" "\u26bd" "\ud83c\udfb0" # text: ":game_die:" ":dart:" ":basketball:" ":soccer:" :slot_machine:" # $3 reply_to_id @@ -346,6 +346,7 @@ send_dice() { *๐Ÿ€*|*basket*|*'dfc0'*|*'DFC0'*) emoji='\ud83c\udfc0' ;; *โšฝ*|*soccer*|*'26bd'*|*'26BD'*) emoji='\u26bd' ;; *๐ŸŽฐ*|*slot* |*'dfb0'*|*'DFB0'*) emoji='\ud83c\udfb0' ;; + *๐ŸŽณ*|*bowl* |*'dfb3'*|*'DFB3'*) emoji='\ud83c\udfb3' ;; esac sendJson "$1" '"emoji": "'"${emoji}"'"'"${reply}" "${URL}/sendDice" if [ "${BOTSENT[OK]}" = "true" ]; then From 85f7c074f45b383e84cbbcee3a7d54494ccfd4df Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Thu, 18 Mar 2021 10:48:43 +0100 Subject: [PATCH 03/24] bin: process_batch: output logmsg first on kill --- bin/process_batch.sh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/bin/process_batch.sh b/bin/process_batch.sh index 22c2e25..85d5f94 100755 --- a/bin/process_batch.sh +++ b/bin/process_batch.sh @@ -21,13 +21,14 @@ USAGE='process_update.sh [-h|--help] [-s|--startbot] [-w|--watch] [-n|--lines n] # AUTHOR: KayM (gnadelwartz), kay@rrr.de # CREATED: 27.02.2021 13:14 # -#### $$VERSION$$ v1.5-0-g8adca9b +#### $$VERSION$$ v1.51-dev-2-g43cab46 #=============================================================================== #### # parse args COMMAND="process_multi_updates" lines="-n 10" +mode="batch" opt=0 while [[ "${opt}" -lt 5 && "$1" == "-"* ]] @@ -40,6 +41,7 @@ do ;; "-w"|"--watch") follow="-f" + mode="webhook" shift ;; "-n"|"--lines") @@ -61,8 +63,8 @@ file="${WEBHOOK}" if [ -n "${startbot}" ]; then # warn when starting bot without pipe [ -p "${file}" ] || printf "%(%c)T: %b\n" -1 "${ORANGE}Warning${NC}: File is not a pipe:${GREY} ${file##*/}${NC}" - start_bot "$2" "webhook" - printf "%(%c)T: %b\n" -1 "${GREEN}Bot start actions done, start reading updates ....${NC}" + start_bot "$2" "${mode}" + printf "%(%c)T: %b\n" -1 "${GREEN}Bot start actions done, start ${mode} updates ....${NC}" fi # check file exist if [[ ! -r "${file}" || -d "${file}" ]]; then @@ -74,7 +76,7 @@ fi # ready, do stuff here ----- # kill all sub processes on exit -trap 'kill $(jobs -p) 2>/dev/null; send_normal_message "'"${BOTADMIN}"'" "Bot '"${BOTNAME}"' webhook stopped ..."; printf "%(%c)T: %s\n" -1 "Bot in batch mode stopped!"' EXIT HUP QUIT +trap 'printf "%(%c)T: %s\n" -1 "Bot in '"${mode}"' mode stopped!"; kill $(jobs -p) 2>/dev/null; send_normal_message "'"${BOTADMIN}"'" "Bot '"${BOTNAME} ${mode}"' stopped ..."' EXIT HUP QUIT # wait after (first) update to avoid processing to many in parallel UPDWAIT="0.5" From e60ada0bfed4d734a821e4aba3d739799baf31b4 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Thu, 18 Mar 2021 11:30:53 +0100 Subject: [PATCH 04/24] revert modules: jsshDB: fix removal of unwanted characters from untrusted input --- modules/jsonDB.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/jsonDB.sh b/modules/jsonDB.sh index 6b7501e..ecc73d2 100644 --- a/modules/jsonDB.sh +++ b/modules/jsonDB.sh @@ -5,7 +5,7 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ v1.51-dev-0-g369124b +#### $$VERSION$$ v1.51-dev-3-g85f7c07 # # source from commands.sh to use jsonDB functions # @@ -358,7 +358,7 @@ Json2Array() { # match ["....."]\t and replace \t with = and print delete ` quote true false escape not escaped $ # shellcheck disable=SC1091,SC1090 [ -z "$1" ] || source <( printf "$1"'=( %s )'\ - "$(sed -E -n -e 's/[`ยด]//g' -e 's/\]\t(true|false)/="\1"/' -e 's/([^\]|^)\$/\1\\$/g' -e '/\["[-0-9a-zA-Z_,."]+"\]\+*\t/ s/\t/=/p')" ) + "$(sed -E -n -e '/\["[-0-9a-zA-Z_,."]+"\]\+*\t/ s/\t/=/p' -e 's/[`ยด]//g' -e 's/=(true|false)/="\1"/' -e 's/([^\]|^)\$/\1\\$/g')" ) } # get Config Key from jssh file without jsshDB # output ARRAY as JSON.sh style data From f1ea49426bbebd29baf25e6d03f8c955a48a17b8 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Thu, 18 Mar 2021 11:50:44 +0100 Subject: [PATCH 05/24] fix modules: jsshDB: fix removal of unwanted characters from untrusted input --- modules/jsonDB.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/jsonDB.sh b/modules/jsonDB.sh index ecc73d2..3605386 100644 --- a/modules/jsonDB.sh +++ b/modules/jsonDB.sh @@ -5,7 +5,7 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ v1.51-dev-3-g85f7c07 +#### $$VERSION$$ v1.51-dev-4-ge60ada0 # # source from commands.sh to use jsonDB functions # @@ -355,10 +355,10 @@ function jssh_updateArray_async() { # read JSON.sh style data and asssign to an ARRAY # $1 ARRAY name, must be declared with "declare -A ARRAY" before calling Json2Array() { - # match ["....."]\t and replace \t with = and print delete ` quote true false escape not escaped $ # shellcheck disable=SC1091,SC1090 + # step 1: output only basic pattern [ -z "$1" ] || source <( printf "$1"'=( %s )'\ - "$(sed -E -n -e '/\["[-0-9a-zA-Z_,."]+"\]\+*\t/ s/\t/=/p' -e 's/[`ยด]//g' -e 's/=(true|false)/="\1"/' -e 's/([^\]|^)\$/\1\\$/g')" ) + "$(sed -E -n -e 's/[`ยด]//g' -e 's/\t(true|false)/\t"\1"/' -e 's/([^\]|^)\$/\1\\$/g' -e '/\["[-0-9a-zA-Z_,."]+"\]\+*\t/ s/\t/=/p')" ) } # get Config Key from jssh file without jsshDB # output ARRAY as JSON.sh style data From cbde841bae8dd6cf52b5a9d31ad2f66ee4208c5d Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Thu, 18 Mar 2021 12:35:14 +0100 Subject: [PATCH 06/24] bashbot.rc: factor out status, warn if wrong status --- bashbot.rc | 50 ++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 14 deletions(-) diff --git a/bashbot.rc b/bashbot.rc index 9334286..e4cc717 100755 --- a/bashbot.rc +++ b/bashbot.rc @@ -5,7 +5,7 @@ # # tested on: ubuntu, opensuse, debian # -#### $$VERSION$$ v1.5-0-g8adca9b +#### $$VERSION$$ v1.51-dev-5-gf1ea494 # shellcheck disable=SC2009 # shellcheck disable=SC2181 # shellcheck disable=SC2250 @@ -49,14 +49,34 @@ mode="" # END Configuration ####################### -[ "${name}" = "" ] && name="${runas}" +[ -z "${name}" ] && name="unknown" + +# check for bot status +ps -f -u "${runas}" | grep "${name}" | grep -qF "bashbot.sh startbot" +if [ "$?" = "0" ]; then + # printf "bashbot (%s) is running in poll mode\n" "${name}" + stat="poll" +else + ps -f -u "${runas}" | grep "${name}" | grep -qF "process_batch.sh --startbot" + if [ "$?" = "0" ]; then + #printf "bashbot (%s) is running in webhook mode\n" "${name}" + stat="hook" + elif [ "${name}" != "unknown" ]; then + #printf "bashbot (%s) is stopped\n" "${name}" + stat="stop" + else + stat="unknown" + fi +fi case "$1" in 'start') + [ "${stat}" != "stop" ] && printf "Warning, bot is not stopped: %s\n" "${stat}" $runcmd "$bashbot start $mode" # >/dev/null 2>&1 >${bashbotdir}/logs/WEBHOOK.log &" # >/dev/null 2>&1 Date: Thu, 18 Mar 2021 12:44:17 +0100 Subject: [PATCH 07/24] bashbot.rc: make log for hook configurable --- bashbot.rc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/bashbot.rc b/bashbot.rc index e4cc717..f6fd38e 100755 --- a/bashbot.rc +++ b/bashbot.rc @@ -5,7 +5,7 @@ # # tested on: ubuntu, opensuse, debian # -#### $$VERSION$$ v1.51-dev-5-gf1ea494 +#### $$VERSION$$ v1.51-dev-6-gcbde841 # shellcheck disable=SC2009 # shellcheck disable=SC2181 # shellcheck disable=SC2250 @@ -46,6 +46,10 @@ webhook="cd ${bashbotdir}; nohup ${bashbotdir}/bin/process_batch.sh --startbot - # set additionl parameter, e.g. debug mode="" +# select logfile for webhook start stop and script errors +hooklog="DEBUG" +hooklog="WEBHOOK" + # END Configuration ####################### @@ -78,7 +82,7 @@ case "$1" in 'starthook') [ "${stat}" != "stop" ] && printf "Warning, bot is not stopped: %s\n" "${stat}" printf "Starting bashbot in webhook mode ... " - $runcmd "$webhook $mode >${bashbotdir}/logs/WEBHOOK.log &" # >/dev/null 2>&1 >${bashbotdir}/logs/${hooklog}.log &" # >/dev/null 2>&1 Date: Thu, 18 Mar 2021 14:09:42 +0100 Subject: [PATCH 08/24] bashbot.rc: more/better run mode warnings --- bashbot.rc | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/bashbot.rc b/bashbot.rc index f6fd38e..91b4fba 100755 --- a/bashbot.rc +++ b/bashbot.rc @@ -5,7 +5,7 @@ # # tested on: ubuntu, opensuse, debian # -#### $$VERSION$$ v1.51-dev-6-gcbde841 +#### $$VERSION$$ v1.51-dev-7-g721e433 # shellcheck disable=SC2009 # shellcheck disable=SC2181 # shellcheck disable=SC2250 @@ -38,7 +38,7 @@ runas="nobody" # your bot name as given to botfather, e.g. mysomething_bot name="" # your bot installation dir -bashbotdir="/usr/local/telegram-bot-bash" +bashbotdir="/usr/local/github/telegram-bot-bash-develop/DIST/telegram-bot-bash" databotdir="${bashbotdir}/data-bot-bash" # programs to run bashbot="cd ${bashbotdir}; ${bashbotdir}/bashbot.sh" @@ -54,6 +54,7 @@ hooklog="WEBHOOK" ####################### [ -z "${name}" ] && name="unknown" +FIFO="i${bashbotdir}/data-bot-bash/webhook-fifo-${name}" # check for bot status ps -f -u "${runas}" | grep "${name}" | grep -qF "bashbot.sh startbot" @@ -75,12 +76,13 @@ fi case "$1" in 'start') - [ "${stat}" != "stop" ] && printf "Warning, bot is not stopped: %s\n" "${stat}" + [ "${stat}" != "stop" ] && printf "Warning, bot is running in mode: %s\n" "${stat}" $runcmd "$bashbot start $mode" # >/dev/null 2>&1 >${bashbotdir}/logs/${hooklog}.log &" # >/dev/null 2>&1 Date: Thu, 18 Mar 2021 14:12:48 +0100 Subject: [PATCH 09/24] bashbot.rc: fix default bashbot path --- bashbot.rc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bashbot.rc b/bashbot.rc index 91b4fba..e7f6f64 100755 --- a/bashbot.rc +++ b/bashbot.rc @@ -5,7 +5,7 @@ # # tested on: ubuntu, opensuse, debian # -#### $$VERSION$$ v1.51-dev-7-g721e433 +#### $$VERSION$$ v1.51-dev-8-gdedcc00 # shellcheck disable=SC2009 # shellcheck disable=SC2181 # shellcheck disable=SC2250 @@ -38,7 +38,7 @@ runas="nobody" # your bot name as given to botfather, e.g. mysomething_bot name="" # your bot installation dir -bashbotdir="/usr/local/github/telegram-bot-bash-develop/DIST/telegram-bot-bash" +bashbotdir="/usr/local/telegram-bot-bash/telegram-bot-bash" databotdir="${bashbotdir}/data-bot-bash" # programs to run bashbot="cd ${bashbotdir}; ${bashbotdir}/bashbot.sh" From 12157b380d5e6758d39d05c36e8da60a62ae0eaa Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Thu, 18 Mar 2021 14:58:18 +0100 Subject: [PATCH 10/24] bashbot.rc: fix hook status, harmonize messages for hook and poll --- bashbot.rc | 14 ++++++++------ bin/process_batch.sh | 4 ++-- modules/processUpdates.sh | 5 +++-- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/bashbot.rc b/bashbot.rc index e7f6f64..67026cd 100755 --- a/bashbot.rc +++ b/bashbot.rc @@ -5,7 +5,7 @@ # # tested on: ubuntu, opensuse, debian # -#### $$VERSION$$ v1.51-dev-8-gdedcc00 +#### $$VERSION$$ v1.51-dev-9-gcbd74a7 # shellcheck disable=SC2009 # shellcheck disable=SC2181 # shellcheck disable=SC2250 @@ -37,12 +37,16 @@ runas="nobody" # edit the values of the following lines to fit your config: # your bot name as given to botfather, e.g. mysomething_bot name="" +[ -z "${name}" ] && name="unknown" + # your bot installation dir -bashbotdir="/usr/local/telegram-bot-bash/telegram-bot-bash" +bashbotdir="/usr/local/telegram-bot-bash" databotdir="${bashbotdir}/data-bot-bash" +FIFO="$databotdir}/webhook-fifo-${name}" + # programs to run bashbot="cd ${bashbotdir}; ${bashbotdir}/bashbot.sh" -webhook="cd ${bashbotdir}; nohup ${bashbotdir}/bin/process_batch.sh --startbot --watch ${databotdir}/webhook-fifo-${name}" +webhook="cd ${bashbotdir}; nohup ${bashbotdir}/bin/process_batch.sh --startbot --watch ${FIFO}" # set additionl parameter, e.g. debug mode="" @@ -53,8 +57,6 @@ hooklog="WEBHOOK" # END Configuration ####################### -[ -z "${name}" ] && name="unknown" -FIFO="i${bashbotdir}/data-bot-bash/webhook-fifo-${name}" # check for bot status ps -f -u "${runas}" | grep "${name}" | grep -qF "bashbot.sh startbot" @@ -110,7 +112,7 @@ case "$1" in "poll"*) printf "bashbot (%s) is running in poll mode\n" "${name}" RETVAL=0 ;; - "webh"*) printf "bashbot (%s) is running in webhook mode\n" "${name}" + "hook"*) printf "bashbot (%s) is running in webhook mode\n" "${name}" RETVAL=0 ;; "stop"*) printf "bashbot (%s) is not running\n" "${name}" diff --git a/bin/process_batch.sh b/bin/process_batch.sh index 85d5f94..da3ac88 100755 --- a/bin/process_batch.sh +++ b/bin/process_batch.sh @@ -21,7 +21,7 @@ USAGE='process_update.sh [-h|--help] [-s|--startbot] [-w|--watch] [-n|--lines n] # AUTHOR: KayM (gnadelwartz), kay@rrr.de # CREATED: 27.02.2021 13:14 # -#### $$VERSION$$ v1.51-dev-2-g43cab46 +#### $$VERSION$$ v1.51-dev-9-gcbd74a7 #=============================================================================== #### @@ -64,7 +64,7 @@ if [ -n "${startbot}" ]; then # warn when starting bot without pipe [ -p "${file}" ] || printf "%(%c)T: %b\n" -1 "${ORANGE}Warning${NC}: File is not a pipe:${GREY} ${file##*/}${NC}" start_bot "$2" "${mode}" - printf "%(%c)T: %b\n" -1 "${GREEN}Bot start actions done, start ${mode} updates ....${NC}" + printf "%(%c)T: %b\n" -1 "${GREEN}Bot startup actions done, start ${mode} updates ...${NC}" fi # check file exist if [[ ! -r "${file}" || -d "${file}" ]]; then diff --git a/modules/processUpdates.sh b/modules/processUpdates.sh index c5286bb..7c96706 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.5-0-g8adca9b +#### $$VERSION$$ v1.51-dev-9-gcbd74a7 ################################################################## ############## @@ -293,7 +293,7 @@ declare -A BASHBOTBLOCKED start_bot() { local DEBUGMSG # startup message - DEBUGMSG="Start BASHBOT updates in Mode \"${1:-normal}\" ==========" + DEBUGMSG="BASHBOT startup actions, debug mode set to \"${1:-normal}\" ==========" log_update "${DEBUGMSG}" # redirect to Debug.log if [[ "$1" == *"debug" ]]; then @@ -336,6 +336,7 @@ get_updates(){ local nextsleep="100" local stepsleep="${BASHBOT_SLEEP_STEP:-100}" local maxsleep="${BASHBOT_SLEEP:-5000}" + printf "%(%c)T: %b\n" -1 "Bot startup actions done, start polling updates ..." while true; do # adaptive sleep in ms rounded to next 0.1 s sleep "$(_round_float "${nextsleep}e-3" "1")" From 3501318d847b1fa94c5a548b58b98d22f44ec3e3 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Fri, 19 Mar 2021 14:01:30 +0100 Subject: [PATCH 11/24] bashbot.rc: fix missing open { in pipe name --- bashbot.rc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bashbot.rc b/bashbot.rc index 67026cd..5cb3802 100755 --- a/bashbot.rc +++ b/bashbot.rc @@ -5,7 +5,7 @@ # # tested on: ubuntu, opensuse, debian # -#### $$VERSION$$ v1.51-dev-9-gcbd74a7 +#### $$VERSION$$ v1.51-dev-10-g12157b3 # shellcheck disable=SC2009 # shellcheck disable=SC2181 # shellcheck disable=SC2250 @@ -42,7 +42,7 @@ name="" # your bot installation dir bashbotdir="/usr/local/telegram-bot-bash" databotdir="${bashbotdir}/data-bot-bash" -FIFO="$databotdir}/webhook-fifo-${name}" +FIFO="${databotdir}/webhook-fifo-${name}" # programs to run bashbot="cd ${bashbotdir}; ${bashbotdir}/bashbot.sh" From f790d73e66711664c695dcec3d887cda577a4e79 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Tue, 23 Mar 2021 17:25:10 +0100 Subject: [PATCH 12/24] modules: process_update: ignore unknown update types --- bin/process_batch.sh | 4 ++-- modules/processUpdates.sh | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/bin/process_batch.sh b/bin/process_batch.sh index da3ac88..f313619 100755 --- a/bin/process_batch.sh +++ b/bin/process_batch.sh @@ -21,7 +21,7 @@ USAGE='process_update.sh [-h|--help] [-s|--startbot] [-w|--watch] [-n|--lines n] # AUTHOR: KayM (gnadelwartz), kay@rrr.de # CREATED: 27.02.2021 13:14 # -#### $$VERSION$$ v1.51-dev-9-gcbd74a7 +#### $$VERSION$$ v1.50-13-g79fc511 #=============================================================================== #### @@ -76,7 +76,7 @@ fi # ready, do stuff here ----- # kill all sub processes on exit -trap 'printf "%(%c)T: %s\n" -1 "Bot in '"${mode}"' mode stopped!"; kill $(jobs -p) 2>/dev/null; send_normal_message "'"${BOTADMIN}"'" "Bot '"${BOTNAME} ${mode}"' stopped ..."' EXIT HUP QUIT +trap 'printf "%(%c)T: %s\n" -1 "Bot in '"${mode}"' mode stopped"; kill $(jobs -p) 2>/dev/null; send_normal_message "'"${BOTADMIN}"'" "Bot '"${BOTNAME} ${mode}"' stopped ..."' EXIT HUP QUIT # wait after (first) update to avoid processing to many in parallel UPDWAIT="0.5" diff --git a/modules/processUpdates.sh b/modules/processUpdates.sh index 7c96706..15e4d13 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.51-dev-9-gcbd74a7 +#### $$VERSION$$ v1.50-13-g79fc511 ################################################################## ############## @@ -91,6 +91,10 @@ process_update() { printf "%(%c)T: update received FROM=%s CHAT=%s CMD=%s\n" -1 "${USER[USERNAME]:0:20} (${USER[ID]})"\ "${CHAT[USERNAME]:0:20}${CHAT[TITLE]:0:30} (${CHAT[ID]})"\ "${MESSAGE:0:30}${CAPTION:0:30}${URLS[*]}" >>"${UPDATELOG}" + if [[ -z "${USER[ID]}" || -z "${CHAT[ID]}" ]]; then + printf "%(%c)T: IGNORE unknown update type: %s\n" -1 "$(grep '\["result",'"${num}"'.*,"id"\]' <<<"${UPDATE}")" >>"${UPDATELOG}" + return 1 + fi fi ##### # process inline and message events From 4c4ba0ba5efb1703452974b13435d5edf9be441f Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Wed, 24 Mar 2021 11:06:30 +0100 Subject: [PATCH 13/24] bashbot: add error Pocessing to SendJsonRetry --- bashbot.sh | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index 095acff..b2e86b0 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.5-0-g8adca9b +#### $$VERSION$$ v1.50-14-gf790d73 ################################################################## # are we running in a terminal? @@ -675,25 +675,25 @@ sendJsonResult(){ # timeout, failed connection or blocked if [ "${BOTSENT[ERROR]}" == "999" ];then # check if default curl and args are OK - if ! curl -sL -k -m 2 "${URL}" >/dev/null 2>&1 ; then - printf "%(%c)T: BASHBOT IP Address seems blocked!\n" -1 - # user provided function to recover or notify block - if _exec_if_function bashbotBlockRecover; then - BASHBOT_RETRY="2" - printf "bashbotBlockRecover returned true, retry %s ...\n" "$2" - sendJsonRetry "$2" "${BASHBOT_RETRY}" "${@:3}" - unset BASHBOT_RETRY - fi - return - fi - # are not blocked, default curl and args are working - if [ -n "${BASHBOT_CURL_ARGS}" ] || [ "${BASHBOT_CURL}" != "curl" ]; then - printf "Problem with \"%s %s\"? retry %s with default config ...\n"\ - "${BASHBOT_CURL}" "${BASHBOT_CURL_ARGS}" "$2" - BASHBOT_RETRY="2"; BASHBOT_CURL="curl"; BASHBOT_CURL_ARGS="" + if ! curl -sL -k -m 2 "${URL}" >/dev/null 2>&1 ; then + printf "%(%c)T: BASHBOT IP Address seems blocked!\n" -1 + # user provided function to recover or notify block + if _exec_if_function bashbotBlockRecover; then + BASHBOT_RETRY="2" + printf "bashbotBlockRecover returned true, retry %s ...\n" "$2" sendJsonRetry "$2" "${BASHBOT_RETRY}" "${@:3}" unset BASHBOT_RETRY fi + # seems not blocked, try if blockrecover and default curl args working + elif [ -n "${BASHBOT_CURL_ARGS}" ] || [ "${BASHBOT_CURL}" != "curl" ]; then + printf "Problem with \"%s %s\"? retry %s with default config ...\n"\ + "${BASHBOT_CURL}" "${BASHBOT_CURL_ARGS}" "$2" + BASHBOT_RETRY="2"; BASHBOT_CURL="curl"; BASHBOT_CURL_ARGS="" + _exec_if_function bashbotBlockRecover + sendJsonRetry "$2" "${BASHBOT_RETRY}" "${@:3}" + unset BASHBOT_RETRY + fi + [ -n "${BOTSENT[ERROR]}" ] && processError "$3" "${BOTSENT[ERROR]}" "$4" "" "${BOTSENT[DESCRIPTION]}" "$5" "$6" fi fi } >>"${ERRORLOG}" From ecaecfee6f52cf90c2cf99acd7499447b7a45cfe Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Wed, 24 Mar 2021 12:07:49 +0100 Subject: [PATCH 14/24] fix dev version --- bashbot.sh | 2 +- modules/processUpdates.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index b2e86b0..99f2fff 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.50-14-gf790d73 +#### $$VERSION$$ v1.51-dev-16-g4c4ba0b ################################################################## # are we running in a terminal? diff --git a/modules/processUpdates.sh b/modules/processUpdates.sh index 15e4d13..ddd3d21 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.50-13-g79fc511 +#### $$VERSION$$ v1.51-dev-16-g4c4ba0b ################################################################## ############## From 9b6aba058689f432cc55dd940805870c522ad716 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sun, 4 Apr 2021 11:22:34 +0200 Subject: [PATCH 15/24] mycommands.sh: autoblock example --- mycommands.sh | 15 ++++++++++++++- mycommands.sh.clean | 15 ++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/mycommands.sh b/mycommands.sh index d17f1c7..c3a05f4 100644 --- a/mycommands.sh +++ b/mycommands.sh @@ -13,7 +13,7 @@ # License: WTFPLv2 http://www.wtfpl.net/txt/copying/ # Author: KayM (gnadelwartz), kay@rrr.de # -#### $$VERSION$$ v1.5-0-g8adca9b +#### $$VERSION$$ v1.51-dev-17-gecaecfe ####################################################### # shellcheck disable=SC1117 @@ -324,8 +324,21 @@ else # func="$1" err="$2" chat="$3" user="$4" emsg="$5" remaining args bashbotError_403() { log_debug "custom errorProcessing error 403: FUNC=$1 CHAT=$3 USER=${4:-no-user} MSGID=$6 ERTXT=$5" + local user="$4"; [[ -z "$4" && -n "$3" ]] && user="$3" + if [ -n "${user}" ]; then + # block chat/user + case "$6" in + *"blocked"*) + jssh_insertKeyDB "${user}" "User blocked bot on (LANG=C date)" "${BLOCKEDFILE}";; + *"kicked"*) + jssh_insertKeyDB "${user}" "Bot kicked from chat on (LANG=C date)" "${BLOCKEDFILE}";; + *) + jssh_insertKeyDB "${user}" "Reason: $6 on (LANG=C date)" "${BLOCKEDFILE}";; + esac + fi } + ########################### # place your processing functions here -------------- diff --git a/mycommands.sh.clean b/mycommands.sh.clean index 4cb32bf..156e876 100644 --- a/mycommands.sh.clean +++ b/mycommands.sh.clean @@ -10,7 +10,7 @@ # License: WTFPLv2 http://www.wtfpl.net/txt/copying/ # Author: KayM (gnadelwartz), kay@rrr.de # -#### $$VERSION$$ v1.5-0-g8adca9b +#### $$VERSION$$ v1.51-dev-17-gecaecfe ####################################################### # shellcheck disable=SC1117 @@ -126,4 +126,17 @@ else done <<<"${result}" } + ########################### + # example error processing + # called when delete Message failed + # func="$1" err="$2" chat="$3" user="$4" emsg="$5" remaining args + bashbotError_delete_message() { + log_debug "custom errorProcessing delete_message: ERR=$2 CHAT=$3 MSGID=$6 ERTXT=$5" + } + + # called when error 403 is returned (and no func processing) + # func="$1" err="$2" chat="$3" user="$4" emsg="$5" remaining args + bashbotError_403() { + log_debug "custom errorProcessing error 403: FUNC=$1 CHAT=$3 USER=${4:-no-user} MSGID=$6 ERTXT=$5" + } fi From f7f55ea45f955b268e58ec843626cd7c7da01694 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sun, 4 Apr 2021 11:27:39 +0200 Subject: [PATCH 16/24] modules: processUpdates: inform user if he is blocked --- modules/processUpdates.sh | 13 ++++++++++--- mycommands.sh | 2 +- mycommands.sh.clean | 2 +- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/modules/processUpdates.sh b/modules/processUpdates.sh index ddd3d21..8c9dc99 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.51-dev-16-g4c4ba0b +#### $$VERSION$$ v1.51-dev-18-g9b6aba0 ################################################################## ############## @@ -67,9 +67,16 @@ process_update() { # log message on debug [[ -n "${debug}" ]] && log_message "New Message ==========\n$(grep -F '["result",'"${num}" <<<"${UPDATE}")" - # check for users / groups to ignore + # check for users / groups to ignore, inform them ... jssh_updateArray_async "BASHBOTBLOCKED" "${BLOCKEDFILE}" - [ -n "${USER[ID]}" ] && [[ -n "${BASHBOTBLOCKED[${USER[ID]}]}" || -n "${BASHBOTBLOCKED[${CHAT[ID]}]}" ]] && return + if [ -n "${USER[ID]}" ] && [[ -n "${BASHBOTBLOCKED[${USER[ID]}]}" || -n "${BASHBOTBLOCKED[${CHAT[ID]}]}" ]];then + if [ -n "${BASHBOTBLOCKED[${USER[ID]}]}" ]; then + send_normal_message "${USER[ID]}" "User blocked because: ${BASHBOTBLOCKED[${USER[ID]}]}" & + else + send_normal_message "${CHAT[ID]}" "Chat blocked because: ${BASHBOTBLOCKED[${CHAT[ID]}]}" & + fi + return + fi # process per message type if [ -n "${iQUERY[ID]}" ]; then diff --git a/mycommands.sh b/mycommands.sh index c3a05f4..8fe24e9 100644 --- a/mycommands.sh +++ b/mycommands.sh @@ -13,7 +13,7 @@ # License: WTFPLv2 http://www.wtfpl.net/txt/copying/ # Author: KayM (gnadelwartz), kay@rrr.de # -#### $$VERSION$$ v1.51-dev-17-gecaecfe +#### $$VERSION$$ v1.51-dev-18-g9b6aba0 ####################################################### # shellcheck disable=SC1117 diff --git a/mycommands.sh.clean b/mycommands.sh.clean index 156e876..a16f39c 100644 --- a/mycommands.sh.clean +++ b/mycommands.sh.clean @@ -10,7 +10,7 @@ # License: WTFPLv2 http://www.wtfpl.net/txt/copying/ # Author: KayM (gnadelwartz), kay@rrr.de # -#### $$VERSION$$ v1.51-dev-17-gecaecfe +#### $$VERSION$$ v1.51-dev-18-g9b6aba0 ####################################################### # shellcheck disable=SC1117 From e4c13ddabe3b77c19e8609b95157a5e176f331a8 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sun, 4 Apr 2021 11:45:37 +0200 Subject: [PATCH 17/24] modules: processUpdates: optimize inform user if blocked --- modules/processUpdates.sh | 12 +++++------- mycommands.conf | 5 ++++- mycommands.sh | 2 +- mycommands.sh.clean | 2 +- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/modules/processUpdates.sh b/modules/processUpdates.sh index 8c9dc99..fbabf9d 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.51-dev-18-g9b6aba0 +#### $$VERSION$$ v1.51-dev-19-gf7f55ea ################################################################## ############## @@ -62,7 +62,7 @@ process_multi_updates() { # processing of a single array item of update # $1 array index process_update() { - local num="$1" debug="$2" + local chatuser="User" num="$1" debug="$2" pre_process_message "${num}" # log message on debug [[ -n "${debug}" ]] && log_message "New Message ==========\n$(grep -F '["result",'"${num}" <<<"${UPDATE}")" @@ -70,11 +70,9 @@ process_update() { # check for users / groups to ignore, inform them ... jssh_updateArray_async "BASHBOTBLOCKED" "${BLOCKEDFILE}" if [ -n "${USER[ID]}" ] && [[ -n "${BASHBOTBLOCKED[${USER[ID]}]}" || -n "${BASHBOTBLOCKED[${CHAT[ID]}]}" ]];then - if [ -n "${BASHBOTBLOCKED[${USER[ID]}]}" ]; then - send_normal_message "${USER[ID]}" "User blocked because: ${BASHBOTBLOCKED[${USER[ID]}]}" & - else - send_normal_message "${CHAT[ID]}" "Chat blocked because: ${BASHBOTBLOCKED[${CHAT[ID]}]}" & - fi + [ -n "${BASHBOTBLOCKED[${USER[ID]}]}" ] && chatuser="User" + [ "${NOTIFY_BLOCKED_USERS}" == "yes" ] &&\ + send_normal_message "${CHAT[ID]}" "${chatuser} blocked because: ${BASHBOTBLOCKED[${USER[ID]}]} ${BASHBOTBLOCKED[${CHAT[ID]}]}" & return fi diff --git a/mycommands.conf b/mycommands.conf index c74f079..5e3a6b6 100644 --- a/mycommands.conf +++ b/mycommands.conf @@ -12,7 +12,7 @@ # Author: KayM (gnadelwartz), kay@rrr.de # Created: 09.01.2021 07:27 # -#### $$VERSION$$ v1.5-0-g8adca9b +#### $$VERSION$$ v1.51-dev-19-gf7f55ea ####################################################### ########## @@ -96,6 +96,9 @@ WELCOME_MSG="Welcome" # export REPORT_NEWMEMBER="yes" # export REPORT_LEFTMEMBER="yes" +# uncomment to send user blocked by bot a warning if they send commands +# export NOTIFY_BLOCKED_USERS="yes" + # messages for admin only commands NOTADMIN="Sorry, this command is allowed for admin or owner only" NOTBOTADMIN="Sorry, this command is allowed for bot owner only" diff --git a/mycommands.sh b/mycommands.sh index 8fe24e9..b9b6b8c 100644 --- a/mycommands.sh +++ b/mycommands.sh @@ -13,7 +13,7 @@ # License: WTFPLv2 http://www.wtfpl.net/txt/copying/ # Author: KayM (gnadelwartz), kay@rrr.de # -#### $$VERSION$$ v1.51-dev-18-g9b6aba0 +#### $$VERSION$$ v1.51-dev-19-gf7f55ea ####################################################### # shellcheck disable=SC1117 diff --git a/mycommands.sh.clean b/mycommands.sh.clean index a16f39c..17fa6f0 100644 --- a/mycommands.sh.clean +++ b/mycommands.sh.clean @@ -10,7 +10,7 @@ # License: WTFPLv2 http://www.wtfpl.net/txt/copying/ # Author: KayM (gnadelwartz), kay@rrr.de # -#### $$VERSION$$ v1.51-dev-18-g9b6aba0 +#### $$VERSION$$ v1.51-dev-19-gf7f55ea ####################################################### # shellcheck disable=SC1117 From b097f088c8cc12ea7eb64d9b0158a722de1cabee Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Mon, 5 Apr 2021 02:32:59 +0200 Subject: [PATCH 18/24] modules: processUpdates: fix inform chat if blocked --- modules/processUpdates.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/processUpdates.sh b/modules/processUpdates.sh index fbabf9d..9a5050d 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.51-dev-19-gf7f55ea +#### $$VERSION$$ v1.51-dev-20-ge4c13dd ################################################################## ############## @@ -62,7 +62,7 @@ process_multi_updates() { # processing of a single array item of update # $1 array index process_update() { - local chatuser="User" num="$1" debug="$2" + local chatuser="Chat" num="$1" debug="$2" pre_process_message "${num}" # log message on debug [[ -n "${debug}" ]] && log_message "New Message ==========\n$(grep -F '["result",'"${num}" <<<"${UPDATE}")" From 45efa806990a0ef927b7db0b5ed95ff5148943a7 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Fri, 9 Apr 2021 17:10:37 +0200 Subject: [PATCH 19/24] modules: startBot: adjust start message --- modules/processUpdates.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/processUpdates.sh b/modules/processUpdates.sh index 9a5050d..51f9d42 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.51-dev-20-ge4c13dd +#### $$VERSION$$ v1.51-dev-21-gb097f08 ################################################################## ############## @@ -302,7 +302,7 @@ declare -A BASHBOTBLOCKED start_bot() { local DEBUGMSG # startup message - DEBUGMSG="BASHBOT startup actions, debug mode set to \"${1:-normal}\" ==========" + DEBUGMSG="BASHBOT startup actions, mode set to \"${1:-normal}\" ==========" log_update "${DEBUGMSG}" # redirect to Debug.log if [[ "$1" == *"debug" ]]; then From 69b1871eeaa10def04d357d5cf71127024557360 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Thu, 3 Jun 2021 12:03:10 +0200 Subject: [PATCH 20/24] fix Terminated message on stophook --- bashbot.rc | 6 +++--- bin/process_batch.sh | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/bashbot.rc b/bashbot.rc index 5cb3802..3bee3a0 100755 --- a/bashbot.rc +++ b/bashbot.rc @@ -5,7 +5,7 @@ # # tested on: ubuntu, opensuse, debian # -#### $$VERSION$$ v1.51-dev-10-g12157b3 +#### $$VERSION$$ v1.51-dev-22-g45efa80 # shellcheck disable=SC2009 # shellcheck disable=SC2181 # shellcheck disable=SC2250 @@ -99,9 +99,9 @@ case "$1" in 'stophook') [ "${stat}" != "hook" ] && printf "Warning, bot is not in webhook mode: %s\n" "${stat}" printf "Stopping bashbot webhook mode ... " - KILLID="$(ps -f -u "${runas}" | grep "process_batch.sh --startbot" | sed -E 's/[^0-9]+([0-9]+).*/\1/')" + KILLID="$(ps -f -u "${runas}" | grep "process_batch.sh --startbot" | sed -E 's/[^0-9]+([0-9]+).*/\1/' | tr -s "\r\n" " ")" if [ -n "${KILLID}" ]; then - $runcmd "kill $(printf "%s" "${KILLID}" | tr -s "\r\n" " " )" + $runcmd "kill ${KILLID}; wait ${KILLID} 2>/dev/null" sleep 1 fi RETVAL=$? diff --git a/bin/process_batch.sh b/bin/process_batch.sh index f313619..38b82bb 100755 --- a/bin/process_batch.sh +++ b/bin/process_batch.sh @@ -4,7 +4,7 @@ # # FILE: bin/process_batch.sh # -USAGE='process_update.sh [-h|--help] [-s|--startbot] [-w|--watch] [-n|--lines n] [file] [debug]' +USAGE='process_batch.sh [-h|--help] [-s|--startbot] [-w|--watch] [-n|--lines n] [file] [debug]' # # DESCRIPTION: processes last 10 telegram updates in file, one update per line # @@ -21,7 +21,7 @@ USAGE='process_update.sh [-h|--help] [-s|--startbot] [-w|--watch] [-n|--lines n] # AUTHOR: KayM (gnadelwartz), kay@rrr.de # CREATED: 27.02.2021 13:14 # -#### $$VERSION$$ v1.50-13-g79fc511 +#### $$VERSION$$ v1.51-dev-22-g45efa80 #=============================================================================== #### @@ -76,14 +76,14 @@ fi # ready, do stuff here ----- # kill all sub processes on exit -trap 'printf "%(%c)T: %s\n" -1 "Bot in '"${mode}"' mode stopped"; kill $(jobs -p) 2>/dev/null; send_normal_message "'"${BOTADMIN}"'" "Bot '"${BOTNAME} ${mode}"' stopped ..."' EXIT HUP QUIT +trap 'printf "%(%c)T: %s\n" -1 "Bot in '"${mode}"' mode stopped"; kill $(jobs -p) 2>/dev/null; wait $(jobs -p) 2>/dev/null; send_normal_message "'"${BOTADMIN}"'" "Bot '"${BOTNAME} ${mode}"' stopped ..."' EXIT HUP QUIT # wait after (first) update to avoid processing to many in parallel UPDWAIT="0.5" # use tail to read appended updates # shellcheck disable=SC2086,SC2248 -tail ${follow} ${lines} "${file}" |\ - while IFS="" read -r input +tail ${follow} ${lines} "${file}" 2>/dev/null |\ + while IFS="" read -r input 2>/dev/null do # read json from stdin and convert update format # replace any ID named BOTADMIN with ID of bot admin From c63f098fb00f7b06c97631ca660f288cb5299eda Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Thu, 3 Jun 2021 13:00:37 +0200 Subject: [PATCH 21/24] fix: use REALME as SCRIPT if sourced --- bashbot.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bashbot.sh b/bashbot.sh index 99f2fff..d360f54 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.51-dev-16-g4c4ba0b +#### $$VERSION$$ v1.51-dev-23-g69b1871 ################################################################## # are we running in a terminal? @@ -181,6 +181,7 @@ MODULEDIR="${SCRIPTDIR}/modules" exit_source() { exit "$1"; } if [[ "${SCRIPT}" != "${REALME}" || "$1" == "source" ]]; then SOURCE="yes" + SCRIPT="${REALME}" [ -z "$1" ] && exit_source() { printf "Exit from source ...\n"; return "$1"; } fi From 52fbb147708a035e53ba35f46e0bfbadf8dc8acf Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Thu, 3 Jun 2021 13:28:29 +0200 Subject: [PATCH 22/24] add timeout to interactive example --- examples/question.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/examples/question.sh b/examples/question.sh index d20b4ba..a908abd 100755 --- a/examples/question.sh +++ b/examples/question.sh @@ -10,7 +10,7 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ v1.5-0-g8adca9b +#### $$VERSION$$ v1.51-dev-24-gc63f098 ######################################################################## ###### @@ -29,6 +29,10 @@ export 'LANGUAGE=C.UTF-8' unset IFS # set -f # if you are paranoid use set -f to disable globbing +# kill interactive script if not finished in time, e.g. user away or error +MAXWAIT="1m" +{ sleep "${MAXWAIT}"; printf "Stopping Questionnaire after %s, you need to much time to finish ... BYE\n" "${MAXWAIT}"; kill $$; wait 2>/dev/null ;} & + # simple yes/no question, defaults to no printf "Hi, hello there\nWould you like some tea (y/n)?\n" read -r answer <"${INPUT}" From 6e66a2877ce7914ff90b3c23b291380f89e476bf Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Thu, 3 Jun 2021 14:12:47 +0200 Subject: [PATCH 23/24] adjust webhook readme and /help message --- README.html | 204 +++++++------------------------------ commands.sh | 6 +- examples/webhook/README.md | 6 +- 3 files changed, 43 insertions(+), 173 deletions(-) diff --git a/README.html b/README.html index f681054..6235128 100644 --- a/README.html +++ b/README.html @@ -6,136 +6,6 @@ Bashbot README