From bccd064516662130cc4178e14997cfa5f1060930 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sat, 18 May 2019 20:25:18 +0200 Subject: [PATCH] start dev3 - remove tmux --- README.html | 2 +- README.md | 2 +- README.txt | 2 +- bashbot.rc | 2 +- bashbot.sh | 31 ++---- commands.sh | 4 +- dev/all-tests.sh | 2 +- dev/git-add.sh | 2 +- dev/hooks/pre-commit.sh | 2 +- dev/hooks/pre-push.sh | 2 +- dev/install-hooks.sh | 2 +- dev/make-distribution.sh | 2 +- dev/make-standalone.sh | 2 +- dev/shellcheck.files | 2 +- dev/version.sh | 2 +- doc/0_install.md | 2 +- doc/1_firstbot.md | 2 +- doc/2_usage.md | 2 +- doc/3_advanced.md | 2 +- doc/4_expert.md | 2 +- doc/5_practice.md | 2 +- doc/6_reference.md | 2 +- doc/7_develop.md | 2 +- doc/8_custom.md | 2 +- examples/README.md | 2 +- examples/background-scripts/run_diskusage.sh | 2 +- .../background-scripts/run_filecontent.sh | 2 +- examples/background-scripts/run_filename.sh | 2 +- examples/background-scripts/run_notify.sh | 2 +- examples/bashbot-multi.sh | 2 +- examples/bashbot.cron | 2 +- examples/calc.sh | 2 +- examples/notify.sh | 2 +- examples/question.sh | 2 +- examples/send-system-status/botacl | 2 +- examples/send-system-status/mycommands.sh | 2 +- modules/aliases.sh | 2 +- modules/answerInline.sh | 2 +- modules/background.sh | 101 ++++++++++++++---- modules/chatMember.sh | 2 +- modules/sendMessage.sh | 2 +- mycommands.sh | 2 +- test/ADD-test-new.sh | 2 +- test/ALL-tests.inc.sh | 2 +- test/a-commit-test.sh | 2 +- test/b-example-test.sh | 2 +- test/c-init-test.sh | 2 +- test/d-JSON.sh-test.sh | 2 +- test/d-process_inline-test.sh | 2 +- test/d-process_message-test.sh | 2 +- test/d-send_message-test.sh | 2 +- test/d-user_is-test.sh | 2 +- test/e-env-test.sh | 2 +- 53 files changed, 140 insertions(+), 96 deletions(-) diff --git a/README.html b/README.html index 4d7dfc4..ae2c52f 100644 --- a/README.html +++ b/README.html @@ -107,6 +107,6 @@

@Gnadelwartz

That’s it!

If you feel that there’s something missing or if you found a bug, feel free to submit a pull request!

-


VERSION
v0.76-1-ge8a1fd0

+


VERSION
v0.80-dev3-0-g31a5d00

diff --git a/README.md b/README.md index b27c8ae..c4184ec 100644 --- a/README.md +++ b/README.md @@ -107,4 +107,4 @@ Well, thats a damn good question ... may be because I'm an Unix/Linux admin from If you feel that there's something missing or if you found a bug, feel free to submit a pull request! -#### $$VERSION$$ v0.76-1-ge8a1fd0 +#### $$VERSION$$ v0.80-dev3-0-g31a5d00 diff --git a/README.txt b/README.txt index b394f5b..f394c59 100644 --- a/README.txt +++ b/README.txt @@ -155,4 +155,4 @@ health status If you feel that there's something missing or if you found a bug, feel free to submit a pull request! -#### $$VERSION$$ v0.76-1-ge8a1fd0 +#### $$VERSION$$ v0.80-dev3-0-g31a5d00 diff --git a/bashbot.rc b/bashbot.rc index 19d1837..908f863 100755 --- a/bashbot.rc +++ b/bashbot.rc @@ -1,7 +1,7 @@ #!/bin/sh # description: Start or stop telegram-bash-bot # -#### $$VERSION$$ v0.76-1-ge8a1fd0 +#### $$VERSION$$ v0.80-dev3-0-g31a5d00 # shellcheck disable=SC2009 # shellcheck disable=SC2181 diff --git a/bashbot.sh b/bashbot.sh index 3e7410e..79bc85b 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -12,7 +12,7 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ v0.76-1-ge8a1fd0 +#### $$VERSION$$ v0.80-dev3-0-g31a5d00 # # Exit Codes: # - 0 sucess (hopefully) @@ -58,7 +58,6 @@ if [ ! -f "${TOKENFILE}" ]; then echo "Running headless, run ${SCRIPT} init first!" exit 2 else - ${CLEAR} echo -e "${RED}TOKEN MISSING.${NC}" echo -e "${ORANGE}PLEASE WRITE YOUR TOKEN HERE OR PRESS CTRL+C TO ABORT${NC}" read -r token @@ -72,7 +71,6 @@ if [ ! -f "${BOTADMIN}" ]; then echo "Running headless, set botadmin to AUTO MODE!" echo '?' > "${BOTADMIN}" else - ${CLEAR} echo -e "${RED}BOTADMIN MISSING.${NC}" echo -e "${ORANGE}PLEASE WRITE YOUR TELEGRAM ID HERE OR ENTER '?'${NC}" echo -e "${ORANGE}TO MAKE FIRST USER TYPING '/start' TO BOTADMIN${NC}" @@ -92,7 +90,6 @@ TMPDIR="${BASHBOT_VAR:-.}/data-bot-bash" if [ ! -d "${TMPDIR}" ]; then mkdir "${TMPDIR}" elif [ ! -w "${TMPDIR}" ]; then - ${CLEAR} echo -e "${RED}ERROR: Can't write to ${TMPDIR}!.${NC}" ls -ld "${TMPDIR}" exit 2 @@ -102,7 +99,6 @@ COUNTFILE="${BASHBOT_VAR:-.}/count" if [ ! -f "${COUNTFILE}" ]; then echo "" >"${COUNTFILE}" elif [ ! -w "${COUNTFILE}" ]; then - ${CLEAR} echo -e "${RED}ERROR: Can't write to ${COUNTFILE}!.${NC}" ls -l "${COUNTFILE}" exit 2 @@ -124,7 +120,6 @@ export res BOTSENT USER MESSAGE URLS CONTACT LOCATION CHAT FORWARD REPLYTO VENUE COMMANDS="${BASHBOT_ETC:-.}/commands.sh" if [ "$1" != "source" ]; then if [ ! -f "${COMMANDS}" ] || [ ! -r "${COMMANDS}" ]; then - ${CLEAR} echo -e "${RED}ERROR: ${COMMANDS} does not exist or is not readable!.${NC}" ls -l "${COMMANDS}" exit 3 @@ -429,11 +424,11 @@ if [ "$1" != "source" ]; then "outproc") # forward output from interactive and jobs to chat [ "$3" = "" ] && echo "No file to read from" && exit 3 [ "$2" = "" ] && echo "No chat to send to" && exit 3 - until [ "$line" = "imprettydarnsuredatdisisdaendofdacmd" ];do + while true ;do line="" read -r -t 10 line - [ "$line" != "" ] && [ "$line" != "imprettydarnsuredatdisisdaendofdacmd" ] && send_message "$2" "$line" - done <"${TMPDIR:-.}/$3" + [ "$line" != "" ] && send_message "$2" "$line" + done rm -f -r "${TMPDIR:-.}/$3" exit ;; @@ -470,18 +465,15 @@ if [ "$1" != "source" ]; then while read -r f; do send_markdown_message "${f//COUNT}" "$*"; $sleep; done <"${COUNTFILE}" ;; "start") - ${CLEAR} tmux kill-session -t "$ME" &>/dev/null tmux new-session -d -s "$ME" "bash $SCRIPT startbot" && echo -e "${GREEN}Bot started successfully.${NC}" echo "Tmux session name $ME" || echo -e "${RED}An error occurred while starting the bot. ${NC}" ;; "kill") - ${CLEAR} tmux kill-session -t "$ME" &>/dev/null echo -e "${GREEN}OK. Bot stopped successfully.${NC}" ;; "background" | "resumeback") - ${CLEAR} echo -e "${GREEN}Restart background processes ...${NC}" for FILE in "${TMPDIR:-.}/"*-back.cmd; do if [ "${FILE}" = "${TMPDIR:-.}/*-back.cmd" ]; then @@ -492,33 +484,30 @@ if [ "$1" != "source" ]; then JOB="${RESTART#*:}" PROG="${JOB#*:}" JOB="${JOB%:*}" - fifo="back-${JOB}-${ME}_${CHAT[ID]}" # compose fifo from jobname, $ME (botname) and CHAT[ID] + fifo="$(fifoname "${CHAT[ID]}" "back-${JOB}")" echo "restartbackground ${PROG} ${fifo}" - ( tmux kill-session -t "${fifo}"; tmux kill-session -t "sendprocess_${fifo}"; rm -f -r "${TMPDIR:-.}/${fifo}") 2>/dev/null - mkfifo "${TMPDIR:-.}/${fifo}" - tmux new-session -d -s "${fifo}" "${PROG} &>${TMPDIR:-.}/${fifo}; echo imprettydarnsuredatdisisdaendofdacmd>${TMPDIR:-.}/${fifo}" - tmux new-session -d -s "sendprocess_${fifo}" "bash $SCRIPT outproc ${CHAT[ID]} ${fifo}" + start_back "${CHAT[ID]}" "${PROG}" "${JOB}" fi done ;; "killback" | "suspendback") - ${CLEAR} echo -e "${GREEN}Stopping background processes ...${NC}" for FILE in "${TMPDIR:-.}/"*-back.cmd; do if [ "${FILE}" = "${TMPDIR:-.}/*-back.cmd" ]; then echo -e "${RED}No background processes.${NC}"; break else REMOVE="$(< "${FILE}")" + CHAT[ID]="${RESTART%%:*}" JOB="${REMOVE#*:}" - fifo="back-${JOB%:*}-${ME}_${REMOVE%%:*}" + JOB="${JOB%:*}" + fifo="$(fifoname "${CHAT[ID]}" "back-${JOB}")" echo "killbackground ${fifo}" [ "$1" = "killback" ] && rm -f "${FILE}" # remove job - ( tmux kill-session -t "${fifo}"; tmux kill-session -t "sendprocess_${fifo}"; rm -f -r "${TMPDIR:-.}/${fifo}") 2>/dev/null + kill_proc "${CHAT[ID]}" "back-${JOB}" fi done ;; "help") - ${CLEAR} less "README.txt" exit ;; diff --git a/commands.sh b/commands.sh index 2654af7..129c378 100644 --- a/commands.sh +++ b/commands.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$$ v0.76-1-ge8a1fd0 +#### $$VERSION$$ v0.80-dev3-0-g31a5d00 # # adjust your language setting here, e.g.when run from other user or cron. @@ -107,7 +107,7 @@ if [ "${1}" != "source" ];then if [ "$res" -eq 0 ] ; then killproc && _message "Command canceled.";else _message "No command is currently running.";fi ;; *) # forward messages to optional dispatcher - _is_function startproc && if tmux ls | grep -v send | grep -q "$copname"; then inproc; fi # interactive running + _is_function forward_interactive && forward_interactive "${CHAT[ID]}" "${MESSAGE}" # interactive running _is_function mycommands && mycommands ;; esac diff --git a/dev/all-tests.sh b/dev/all-tests.sh index bc99493..7739b76 100755 --- a/dev/all-tests.sh +++ b/dev/all-tests.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # this has to run once atfer git clone # and every time we create new hooks -#### $$VERSION$$ v0.76-1-ge8a1fd0 +#### $$VERSION$$ v0.80-dev3-0-g31a5d00 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/dev/git-add.sh b/dev/git-add.sh index aeb99aa..249bd60 100755 --- a/dev/git-add.sh +++ b/dev/git-add.sh @@ -3,7 +3,7 @@ # # works together with git pre-push.sh and ADD all changed files since last push -#### $$VERSION$$ v0.76-1-ge8a1fd0 +#### $$VERSION$$ v0.80-dev3-0-g31a5d00 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/dev/hooks/pre-commit.sh b/dev/hooks/pre-commit.sh index bf19b43..38f5729 100755 --- a/dev/hooks/pre-commit.sh +++ b/dev/hooks/pre-commit.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.76-1-ge8a1fd0 +#### $$VERSION$$ v0.80-dev3-0-g31a5d00 ############ # NOTE: you MUST run install-hooks.sh again when updating this file! diff --git a/dev/hooks/pre-push.sh b/dev/hooks/pre-push.sh index e1e1610..b50de77 100755 --- a/dev/hooks/pre-push.sh +++ b/dev/hooks/pre-push.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.76-1-ge8a1fd0 +#### $$VERSION$$ v0.80-dev3-0-g31a5d00 ############ # NOTE: you MUST run install-hooks.sh again when updating this file! diff --git a/dev/install-hooks.sh b/dev/install-hooks.sh index d510bf2..7c58fe0 100755 --- a/dev/install-hooks.sh +++ b/dev/install-hooks.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # this has to run once atfer git clone # and every time we create new hooks -#### $$VERSION$$ v0.76-1-ge8a1fd0 +#### $$VERSION$$ v0.80-dev3-0-g31a5d00 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/dev/make-distribution.sh b/dev/make-distribution.sh index cec7784..7f1253a 100755 --- a/dev/make-distribution.sh +++ b/dev/make-distribution.sh @@ -2,7 +2,7 @@ # file: make-distribution.sh # creates files and arcchives to dirtribute bashbot # -#### $$VERSION$$ v0.76-1-ge8a1fd0 +#### $$VERSION$$ v0.80-dev3-0-g31a5d00 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/dev/make-standalone.sh b/dev/make-standalone.sh index 7fe348f..7d49f07 100755 --- a/dev/make-standalone.sh +++ b/dev/make-standalone.sh @@ -5,7 +5,7 @@ # If you your bot is finished you can use make-standalone.sh to create the # the old all-in-one bashbot: bashbot.sh and commands.sh only! # -#### $$VERSION$$ v0.76-1-ge8a1fd0 +#### $$VERSION$$ v0.80-dev3-0-g31a5d00 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/dev/shellcheck.files b/dev/shellcheck.files index 0b3c8a0..5bf5b1e 100644 --- a/dev/shellcheck.files +++ b/dev/shellcheck.files @@ -1,3 +1,3 @@ # list of additional files to check from shellcheck -#### $$VERSION$$ v0.76-1-ge8a1fd0 +#### $$VERSION$$ v0.80-dev3-0-g31a5d00 bashbot.rc diff --git a/dev/version.sh b/dev/version.sh index 7340d72..c4851f6 100755 --- a/dev/version.sh +++ b/dev/version.sh @@ -1,6 +1,6 @@ #!/bin/bash # -#### $$VERSION$$ v0.76-1-ge8a1fd0 +#### $$VERSION$$ v0.80-dev3-0-g31a5d00 # shellcheck disable=SC2016 # # Easy Versioning in git: diff --git a/doc/0_install.md b/doc/0_install.md index 674b542..47b1f7b 100644 --- a/doc/0_install.md +++ b/doc/0_install.md @@ -70,5 +70,5 @@ The old format is supported for backward compatibility, but may fail for corner #### [Next Create Bot](1_firstbot.md) -#### $$VERSION$$ v0.76-1-ge8a1fd0 +#### $$VERSION$$ v0.80-dev3-0-g31a5d00 diff --git a/doc/1_firstbot.md b/doc/1_firstbot.md index 1884726..deb4785 100644 --- a/doc/1_firstbot.md +++ b/doc/1_firstbot.md @@ -65,5 +65,5 @@ group. This step is up to you actually. #### [Prev Installation](0_install.md) #### [Next Getting started](2_usage.md) -#### $$VERSION$$ v0.76-1-ge8a1fd0 +#### $$VERSION$$ v0.80-dev3-0-g31a5d00 diff --git a/doc/2_usage.md b/doc/2_usage.md index 28aa312..3f9d780 100644 --- a/doc/2_usage.md +++ b/doc/2_usage.md @@ -182,5 +182,5 @@ send_action "${CHAT[ID]}" "action" #### [Prev Create Bot](1_firstbot.md) #### [Next Advanced Usage](3_advanced.md) -#### $$VERSION$$ v0.76-1-ge8a1fd0 +#### $$VERSION$$ v0.80-dev3-0-g31a5d00 diff --git a/doc/3_advanced.md b/doc/3_advanced.md index 1360d1c..0ae7851 100644 --- a/doc/3_advanced.md +++ b/doc/3_advanced.md @@ -180,5 +180,5 @@ See also [answer_inline_multi, answer_inline_compose](6_reference.md#answer_inli #### [Prev Getting started](2_usage.md) #### [Next Expert Use](4_expert.md) -#### $$VERSION$$ v0.76-1-ge8a1fd0 +#### $$VERSION$$ v0.80-dev3-0-g31a5d00 diff --git a/doc/4_expert.md b/doc/4_expert.md index adace28..6f7f6c0 100644 --- a/doc/4_expert.md +++ b/doc/4_expert.md @@ -104,5 +104,5 @@ An example crontab is provided in ```examples/bashbot.cron```. #### [Prev Expert Use](4_expert.md) #### [Next Best Practice](5_practice.md) -#### $$VERSION$$ v0.76-1-ge8a1fd0 +#### $$VERSION$$ v0.80-dev3-0-g31a5d00 diff --git a/doc/5_practice.md b/doc/5_practice.md index 9e717e5..fc69778 100644 --- a/doc/5_practice.md +++ b/doc/5_practice.md @@ -153,5 +153,5 @@ The second warning is about an unused variable, this is true because in our exam #### [Prev Best Practice](5_practice.md) #### [Next Functions Reference](6_reference.md) -#### $$VERSION$$ v0.76-1-ge8a1fd0 +#### $$VERSION$$ v0.80-dev3-0-g31a5d00 diff --git a/doc/6_reference.md b/doc/6_reference.md index a3359f0..4837f76 100644 --- a/doc/6_reference.md +++ b/doc/6_reference.md @@ -592,5 +592,5 @@ Send Input from Telegram to waiting Interactive Chat. #### [Prev Best Practice](5_practice.md) #### [Next Notes for Developers](7_develop.md) -#### $$VERSION$$ v0.76-1-ge8a1fd0 +#### $$VERSION$$ v0.80-dev3-0-g31a5d00 diff --git a/doc/7_develop.md b/doc/7_develop.md index 55bc350..112bf6b 100644 --- a/doc/7_develop.md +++ b/doc/7_develop.md @@ -188,5 +188,5 @@ fi #### [Prev Function Reference](6_reference.md) #### [Next Bashbot Environment](8_custom.md) -#### $$VERSION$$ v0.76-1-ge8a1fd0 +#### $$VERSION$$ v0.80-dev3-0-g31a5d00 diff --git a/doc/8_custom.md b/doc/8_custom.md index 04db87a..ebb2f3b 100644 --- a/doc/8_custom.md +++ b/doc/8_custom.md @@ -131,5 +131,5 @@ for every poll until the maximum of BASHBOT_SLEEP ms. #### [Prev Notes for Developers](7_develop.md) -#### $$VERSION$$ v0.76-1-ge8a1fd0 +#### $$VERSION$$ v0.80-dev3-0-g31a5d00 diff --git a/examples/README.md b/examples/README.md index 45fa8eb..11426f6 100644 --- a/examples/README.md +++ b/examples/README.md @@ -55,6 +55,6 @@ convert existing bots. **external-use** will contain some examples on how to send messages from external scripts to Telegram chats or users. -#### $$VERSION$$ v0.76-1-ge8a1fd0 +#### $$VERSION$$ v0.80-dev3-0-g31a5d00 diff --git a/examples/background-scripts/run_diskusage.sh b/examples/background-scripts/run_diskusage.sh index 4c756f3..043ae6c 100755 --- a/examples/background-scripts/run_diskusage.sh +++ b/examples/background-scripts/run_diskusage.sh @@ -4,7 +4,7 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) -#### $$VERSION$$ v0.76-1-ge8a1fd0 +#### $$VERSION$$ v0.80-dev3-0-g31a5d00 # adjust your language setting here # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment diff --git a/examples/background-scripts/run_filecontent.sh b/examples/background-scripts/run_filecontent.sh index fa5ab5c..826c33c 100755 --- a/examples/background-scripts/run_filecontent.sh +++ b/examples/background-scripts/run_filecontent.sh @@ -2,7 +2,7 @@ # file: run_filename # background job to display content of all new files in WATCHDIR # -#### $$VERSION$$ v0.76-1-ge8a1fd0 +#### $$VERSION$$ v0.80-dev3-0-g31a5d00 # adjust your language setting here # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment diff --git a/examples/background-scripts/run_filename.sh b/examples/background-scripts/run_filename.sh index 3c070fb..86911fa 100755 --- a/examples/background-scripts/run_filename.sh +++ b/examples/background-scripts/run_filename.sh @@ -2,7 +2,7 @@ # file: run_filename # background job to display all new files in WATCHDIR # -#### $$VERSION$$ v0.76-1-ge8a1fd0 +#### $$VERSION$$ v0.80-dev3-0-g31a5d00 # adjust your language setting here # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment diff --git a/examples/background-scripts/run_notify.sh b/examples/background-scripts/run_notify.sh index e019204..1f81f75 100755 --- a/examples/background-scripts/run_notify.sh +++ b/examples/background-scripts/run_notify.sh @@ -4,7 +4,7 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) -#### $$VERSION$$ v0.76-1-ge8a1fd0 +#### $$VERSION$$ v0.80-dev3-0-g31a5d00 # adjust your language setting here # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment diff --git a/examples/bashbot-multi.sh b/examples/bashbot-multi.sh index 61cdde6..293eb78 100755 --- a/examples/bashbot-multi.sh +++ b/examples/bashbot-multi.sh @@ -2,7 +2,7 @@ # file. multibot.sh # description: run multiple telegram bots from one installation # -#### $$VERSION$$ v0.76-1-ge8a1fd0 +#### $$VERSION$$ v0.80-dev3-0-g31a5d00 if [ "${2}" = "" ] || [ "${2}" = "-h" ]; then echo "Usage: $0 botname command" diff --git a/examples/bashbot.cron b/examples/bashbot.cron index df9b95f..d727ca6 100644 --- a/examples/bashbot.cron +++ b/examples/bashbot.cron @@ -7,7 +7,7 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ v0.76-1-ge8a1fd0 +#### $$VERSION$$ v0.80-dev3-0-g31a5d00 SHELL=/bin/sh diff --git a/examples/calc.sh b/examples/calc.sh index 4c47dd0..2c79621 100755 --- a/examples/calc.sh +++ b/examples/calc.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$$ v0.76-1-ge8a1fd0 +#### $$VERSION$$ v0.80-dev3-0-g31a5d00 # adjust your language setting here # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment diff --git a/examples/notify.sh b/examples/notify.sh index 976548f..45e2d14 100755 --- a/examples/notify.sh +++ b/examples/notify.sh @@ -4,7 +4,7 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) -#### $$VERSION$$ v0.76-1-ge8a1fd0 +#### $$VERSION$$ v0.80-dev3-0-g31a5d00 # adjust your language setting here # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment diff --git a/examples/question.sh b/examples/question.sh index ee74b57..a7ca0c7 100755 --- a/examples/question.sh +++ b/examples/question.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$$ v0.76-1-ge8a1fd0 +#### $$VERSION$$ v0.80-dev3-0-g31a5d00 # adjust your language setting here # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment diff --git a/examples/send-system-status/botacl b/examples/send-system-status/botacl index 9f41c1f..2c20ed9 100644 --- a/examples/send-system-status/botacl +++ b/examples/send-system-status/botacl @@ -1,7 +1,7 @@ # file: botacl # a user not listed here, will return false from 'user_is_allowed' # -#### $$VERSION$$ v0.76-1-ge8a1fd0 +#### $$VERSION$$ v0.80-dev3-0-g31a5d00 # Format: # user:ressource:chat diff --git a/examples/send-system-status/mycommands.sh b/examples/send-system-status/mycommands.sh index 64b5180..7c9b946 100644 --- a/examples/send-system-status/mycommands.sh +++ b/examples/send-system-status/mycommands.sh @@ -5,7 +5,7 @@ # to show how you can customize bashbot by only editing mycommands.sh # NOTE: this is not tested, simply copied from original source and reworked! # -#### $$VERSION$$ v0.76-1-ge8a1fd0 +#### $$VERSION$$ v0.80-dev3-0-g31a5d00 # # shellcheck disable=SC2154 # shellcheck disable=SC2034 diff --git a/modules/aliases.sh b/modules/aliases.sh index 3ead78f..5781952 100644 --- a/modules/aliases.sh +++ b/modules/aliases.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$$ v0.76-1-ge8a1fd0 +#### $$VERSION$$ v0.80-dev3-0-g31a5d00 # # source from commands.sh to use the aliases diff --git a/modules/answerInline.sh b/modules/answerInline.sh index 3fde398..fcdae5f 100644 --- a/modules/answerInline.sh +++ b/modules/answerInline.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$$ v0.76-1-ge8a1fd0 +#### $$VERSION$$ v0.80-dev3-0-g31a5d00 # source from commands.sh to use the inline functions diff --git a/modules/background.sh b/modules/background.sh index d1145d6..c6d3221 100644 --- a/modules/background.sh +++ b/modules/background.sh @@ -5,48 +5,103 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ v0.76-1-ge8a1fd0 +#### $$VERSION$$ v0.80-dev3-0-g31a5d00 # source from commands.sh if you want ro use interactive or background jobs ###### # interactive and background functions +# old syntax as aliases background() { - echo "${CHAT[ID]}:$2:$1" >"${TMPDIR:-.}/${copname:--}$2-back.cmd" - startproc "$1" "back-$2-" + start_back "${CHAT[ID]}" "$1" "$2" } - startproc() { - killproc "$2" - local fifo="$2${copname}" - mkfifo "${TMPDIR:-.}/${fifo}" - tmux new-session -d -s "${fifo}" "$1 &>${TMPDIR:-.}/${fifo}; echo imprettydarnsuredatdisisdaendofdacmd>${TMPDIR:-.}/${fifo}" - tmux new-session -d -s "sendprocess_${fifo}" "bash $SCRIPT outproc ${CHAT[ID]} ${fifo}" + start_proc "${CHAT[ID]}" "$1" "$2" } - - checkback() { - checkproc "back-$1-" + check_back "${CHAT[ID]}" "$1" +} +checkproc() { + check_proc "${CHAT[ID]}" "$1" +} +killback() { + kill_back "${CHAT[ID]}" "$1" +} +killproc() { + kill_proc "${CHAT[ID]}" "$1" } -checkproc() { - tmux ls | grep -q "$1${copname}" +# internal functions +# $1 chatid +# $2 prefix +fifoname(){ + echo "$2${ME}_$1" +} + +# $1 pipename +listproc() { + # shellcheck disable=SC2009 + ps -ef | grep -v grep| grep "$1" | sed 's/\s\+/\t/g' | cut -f 2 +} + +# inline and backgound functions +# $1 chatid +# $2 program +# $3 jobname +start_back() { + local fifo; fifo="$(fifoname "$1")" + echo "$1:$3:$2" >"${TMPDIR:-.}/${fifo}$3-back.cmd" + start_proc "$1" "$2" "back-$3-" +} + + +# $1 chatid +# $2 program +# $3 prefix +start_proc() { + [ "$2" = "" ] && return + kill_proc "$1" "$3" + local fifo; fifo="$(fifoname "$1" "$3")" + mkfifo "${TMPDIR:-.}/${fifo}" + ( $2 <"${TMPDIR:-.}/${fifo}" | "${SCRIPT}" outproc "${1}" "${fifo}"; ) &>>"${TMPDIR:-.}/${fifo}.log" & + disown -a +} + + +# $1 chatid +# $2 jobname +check_back() { + check_proc "$1" "back-$2-" +} + +# $1 chatid +# $2 prefix +check_proc() { + [ "$(listproc "$(fifoname "$1" "$2")")" != "" ] # shellcheck disable=SC2034 res=$?; return $? } -killback() { - killproc "back-$1-" - rm -f "${TMPDIR:-.}/${copname}$1-back.cmd" +# $1 chatid +# $2 jobname +kill_back() { + kill_proc "$1" "back-$2-" + rm -f "${TMPDIR:-.}/$(fifoname "$1")$2-back.cmd" } -killproc() { - local fifo="$1${copname}" - (tmux kill-session -t "${fifo}"; echo imprettydarnsuredatdisisdaendofdacmd>"${TMPDIR:-.}/${fifo}"; tmux kill-session -t "sendprocess_${fifo}"; rm -f -r "${TMPDIR:-.}/${fifo}")2>/dev/null + +# $1 chatid +# $2 prefix +kill_proc() { + local fifo; fifo="$(fifoname "$1" "$2")" + kill -15 "$(listproc "${fifo}")" 2>/dev/null + rm -f -r "${TMPDIR:-.}/${fifo}"; } -inproc() { - tmux send-keys -t "$copname" "${MESSAGE[0]} ${URLS[*]} -" +# $1 chat +# $2 message +forward_interactive() { + local fifo; fifo="$(fifoname "$1")" + [ -p "${fifo}" ] && echo "$2" >"${fifo}" } diff --git a/modules/chatMember.sh b/modules/chatMember.sh index 09148df..d2ed8d9 100644 --- a/modules/chatMember.sh +++ b/modules/chatMember.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$$ v0.76-1-ge8a1fd0 +#### $$VERSION$$ v0.80-dev3-0-g31a5d00 # source from commands.sh to use the member functions diff --git a/modules/sendMessage.sh b/modules/sendMessage.sh index 59e57e5..cb9999f 100644 --- a/modules/sendMessage.sh +++ b/modules/sendMessage.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$$ v0.76-1-ge8a1fd0 +#### $$VERSION$$ v0.80-dev3-0-g31a5d00 # source from commands.sh to use the sendMessage functions diff --git a/mycommands.sh b/mycommands.sh index fb00731..33d8edf 100644 --- a/mycommands.sh +++ b/mycommands.sh @@ -2,7 +2,7 @@ # files: mycommands.sh.dist # copy to mycommands.sh and add all your commands and functions here ... # -#### $$VERSION$$ v0.76-1-ge8a1fd0 +#### $$VERSION$$ v0.80-dev3-0-g31a5d00 # # uncomment the following lines to overwrite info and help messages diff --git a/test/ADD-test-new.sh b/test/ADD-test-new.sh index 70bbf47..d097145 100755 --- a/test/ADD-test-new.sh +++ b/test/ADD-test-new.sh @@ -2,7 +2,7 @@ # # ADD a new test skeleton to test dir, but does not activate test # -#### $$VERSION$$ v0.76-1-ge8a1fd0 +#### $$VERSION$$ v0.80-dev3-0-g31a5d00 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/test/ALL-tests.inc.sh b/test/ALL-tests.inc.sh index 56e068a..8208922 100644 --- a/test/ALL-tests.inc.sh +++ b/test/ALL-tests.inc.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.76-1-ge8a1fd0 +#### $$VERSION$$ v0.80-dev3-0-g31a5d00 # common variables export TESTME DIRME TESTDIR LOGFILE REFDIR TESTNAME diff --git a/test/a-commit-test.sh b/test/a-commit-test.sh index 31b7ae6..c0a19e5 100755 --- a/test/a-commit-test.sh +++ b/test/a-commit-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.76-1-ge8a1fd0 +#### $$VERSION$$ v0.80-dev3-0-g31a5d00 ../dev/hooks/pre-commit.sh diff --git a/test/b-example-test.sh b/test/b-example-test.sh index 7f34def..d50cc87 100644 --- a/test/b-example-test.sh +++ b/test/b-example-test.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash # file: b-example-test.sh -#### $$VERSION$$ v0.76-1-ge8a1fd0 +#### $$VERSION$$ v0.80-dev3-0-g31a5d00 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh diff --git a/test/c-init-test.sh b/test/c-init-test.sh index 1e65619..b440572 100755 --- a/test/c-init-test.sh +++ b/test/c-init-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.76-1-ge8a1fd0 +#### $$VERSION$$ v0.80-dev3-0-g31a5d00 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh diff --git a/test/d-JSON.sh-test.sh b/test/d-JSON.sh-test.sh index 70be42f..9a45a95 100755 --- a/test/d-JSON.sh-test.sh +++ b/test/d-JSON.sh-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.76-1-ge8a1fd0 +#### $$VERSION$$ v0.80-dev3-0-g31a5d00 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh diff --git a/test/d-process_inline-test.sh b/test/d-process_inline-test.sh index 3c36f23..46a6e30 100755 --- a/test/d-process_inline-test.sh +++ b/test/d-process_inline-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.76-1-ge8a1fd0 +#### $$VERSION$$ v0.80-dev3-0-g31a5d00 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh diff --git a/test/d-process_message-test.sh b/test/d-process_message-test.sh index 6b13f25..5efc4ed 100755 --- a/test/d-process_message-test.sh +++ b/test/d-process_message-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.76-1-ge8a1fd0 +#### $$VERSION$$ v0.80-dev3-0-g31a5d00 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh diff --git a/test/d-send_message-test.sh b/test/d-send_message-test.sh index 1f7759b..750be37 100755 --- a/test/d-send_message-test.sh +++ b/test/d-send_message-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.76-1-ge8a1fd0 +#### $$VERSION$$ v0.80-dev3-0-g31a5d00 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh diff --git a/test/d-user_is-test.sh b/test/d-user_is-test.sh index 7c2b750..901ccbd 100755 --- a/test/d-user_is-test.sh +++ b/test/d-user_is-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.76-1-ge8a1fd0 +#### $$VERSION$$ v0.80-dev3-0-g31a5d00 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh diff --git a/test/e-env-test.sh b/test/e-env-test.sh index 5f03074..d9aefdd 100755 --- a/test/e-env-test.sh +++ b/test/e-env-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.76-1-ge8a1fd0 +#### $$VERSION$$ v0.80-dev3-0-g31a5d00 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh