From b4dcb52793da298ad004c40772ff635ef9630ab1 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sun, 29 Nov 2020 10:50:05 +0100 Subject: [PATCH 001/100] allow enabling of getJson update logging --- bashbot.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index 1e749a6..e9e5f27 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -11,7 +11,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.2-dev-25-g0b64af7 +#### $$VERSION$$ v1.2-pre-0-gb4c83c1 # # Exit Codes: # - 0 success (hopefully) @@ -946,6 +946,7 @@ process_message() { ######################### # main get updates loop, should never terminate declare -A BASHBOTBLOCKED +export BASHBOT_UPDATELOG="${BASHBOT_UPDATELOG-nolog}" # allow to be "" start_bot() { local DEBUGMSG ADMIN OFFSET=0 # adaptive sleep defaults @@ -958,7 +959,7 @@ start_bot() { # redirect to Debug.log [[ "${1}" == *"debug" ]] && exec &>>"${DEBUGLOG}" printf "%s\n" "${DEBUGMSG}"; DEBUGMSG="${1}" - [[ "${DEBUGMSG}" == "xdebug"* ]] && set -x + [[ "${DEBUGMSG}" == "xdebug"* ]] && set -x i && unset BASHBOT_UPDATELOG # cleaup old pipes and empty logfiles find "${DATADIR}" -type p -delete find "${DATADIR}" -size 0 -name "*.log" -delete @@ -994,7 +995,7 @@ start_bot() { # adaptive sleep in ms rounded to next 0.1 s sleep "$(_round_float "${nextsleep}e-3" "1")" # get next update - UPDATE="$(getJson "${UPD_URL}${OFFSET}" "nolog" 2>/dev/null | "${JSONSHFILE}" -b -n 2>/dev/null | iconv -f utf-8 -t utf-8 -c)" + UPDATE="$(getJson "${UPD_URL}${OFFSET}" "${BASHBOT_UPDATELOG}" 2>/dev/null | "${JSONSHFILE}" -b -n 2>/dev/null | iconv -f utf-8 -t utf-8 -c)" # did we get an response? if [ -n "${UPDATE}" ]; then # we got something, do processing From a1773cce84ce6941e3eeb5980213c333c90edd5d Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sun, 29 Nov 2020 10:58:06 +0100 Subject: [PATCH 002/100] document enabling update logging --- doc/7_develop.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/doc/7_develop.md b/doc/7_develop.md index 43cc2bc..59accb8 100644 --- a/doc/7_develop.md +++ b/doc/7_develop.md @@ -25,6 +25,9 @@ you can the change the level of verbosity of the debug argument: ``` +Logging of telegram update poll is disabled by default, also in `debug` mode. To enable it without using verbose `xdebug` mode +set `BASHBOT_UPDATELOG` to an empty value (not unset) `export BASHBOT_UPDATELOG=""` + ### Modules and Addons **Modules** resides in ```modules/*.sh``` and are colletions of optional bashbot functions grouped by functionality. Main reason for creating modules was @@ -347,5 +350,5 @@ fi #### [Prev Function Reference](6_reference.md) -#### $$VERSION$$ v1.2-dev-13-g2a5d47d +#### $$VERSION$$ v1.2-pre-1-gb4dcb52 From b5caff0a325cff1595cadb075ae3ce5db44f92be Mon Sep 17 00:00:00 2001 From: Gnadelwartz Date: Sun, 29 Nov 2020 15:34:00 +0100 Subject: [PATCH 003/100] statisfy newer shellcheck version --- README.html | 218 ++++++++++++------------- README.md | 2 +- README.txt | 7 +- bashbot.rc | 9 +- bashbot.sh | 5 +- commands.sh | 4 +- dev/hooks/pre-commit.sh | 4 +- dev/obfuscate.sh | 2 +- doc/7_develop.md | 5 +- examples/bash2env.sh | 4 +- examples/jsonDB-keyboard/mycommands.sh | 5 +- modules/background.sh | 3 +- modules/sendMessage.sh | 3 +- mycommands.sh | 9 +- 14 files changed, 142 insertions(+), 138 deletions(-) diff --git a/README.html b/README.html index dc33d59..4d91e68 100644 --- a/README.html +++ b/README.html @@ -5,82 +5,78 @@ Bashbot README - + - -
+

Bashbot README

@@ -95,7 +91,7 @@ Written by Drew (@topkecleon) and Kay M (@gnadelwartz).

Uses JSON.sh and the magic of sed.

Even bashbot is written in bash, it depends on commands typically available in a Unix/Linux Environment. More concrete on the common commands provided by recent versions of coreutils, busybox or toybox, see Developer Notes

Note for MacOS and BSD Users: As bashbot heavily uses modern bash and (gnu) grep/sed features, bashbot will not run without installing additional software, see Install Bashbot

-

Note for embedded systems: busybox or toybox ONLY is not sufficient, you need a to install a "real" bash, see also Install Bashbot

+

Note for embedded systems: busybox or toybox ONLY is not sufficient, you need a to install a "real" bash, see also Install Bashbot

Bashbot Documentation and Downloads are available on www.github.com

Documentation

    @@ -162,8 +158,8 @@ Written by Drew (@topkecleon) and Kay M (@gnadelwartz).

    Now open a terminal and check if bash is installed:

    which bash && echo "bash seems available..."
     
    -

    Create a new directory, change to it: mkdir tbb; cd tbb and download the latest '*.tar.gz' file from https://github.com/topkecleon/telegram-bot-bash/releases. This can be done with the commands:

    -
    wget -q https://github.com/$(wget -q https://github.com/topkecleon/telegram-bot-bash/releases/latest -O - | egrep '/.*/.*/.*tar.gz' -o)
    +

    Create a new directory, change to it: mkdir tbb; cd tbb and download the latest '*.tar.gz' file from https://github.com/topkecleon/telegram-bot-bash/releases. This can be done with the commands:

    +

    Extract the '*.tar.gz' file and change to bashbot directory: tar -xzf *.tar.gz; cd telegram-bot-bash, install bashbot: ./bashbot.sh init and enter your bot token when asked. All other questions can be answered by hitting the <Return> key.

    That's all, now you can start your bot with ./bashbot.sh start and send him messages:

    /start
    @@ -200,18 +196,18 @@ It features background tasks and interactive chats, and can serve as an interfac
     

    A powerful tool to improve your scripts is shellcheck. You can use it online or install shellcheck locally. Shellcheck is used extensively in bashbot development to ensure a high code quality, e.g. it's not allowed to push changes without passing all shellcheck tests. In addition bashbot has a test suite to check if important functionality is working as expected.

    Use printf whenever possible

    If you're writing a script and it is taking external input (from the user as arguments or file system...), you shouldn't use echo to display it. Use printf whenever possible

    -
      # very simple
    -  echo "text with variables. PWD=$PWD"
    -  printf '%s\n' "text with variables. PWD=$PWD"
    -  -> text with variables. PWD=/home/xxx
    -
    -  # more advanced
    -  FLOAT="1.2346777892864" INTEGER="12345.123"
    -  echo "text with variabeles. float=$FLOAT, integer=$INTEGER, PWD=$PWD"
    -  ->text with variables. float=1.2346777892864, integer=12345.123, PWD=/home/xxx
    -
    -  printf "text with variables. float=%.2f, integer=%d, PWD=%s\n" "" "$INTEGER" "$PWD"
    -  ->text with variables. float=1.23, integer=12345, PWD=/home/xxx
    +

    Do not use #!/usr/bin/env bash

    We stay with /bin/bash shebang, because it's more save from security perspective.

    Use of a fixed path to the system provided bash makes it harder for attackers or users to place alternative versions of bash and avoids using a possibly broken, mangled or compromised bash executable.

    @@ -241,38 +237,38 @@ It features background tasks and interactive chats, and can serve as an interfac

    Can I send messages from CLI and scripts?

    Of course, you can send messages from CLI and scripts, simply install bashbot as described here, send the message '/start' to set yourself as botadmin and stop the bot with ./bashbot.sh stop.

    Run the following commands in your bash shell or script while you are in the installation directory:

    -
    # prepare bash / script to send commands
    -export BASHBOT_HOME="$(pwd)"
    -source ./bashbot.sh source
    -
    -# send me a test message
    -send_message "$(getConfigKey "botadmin")" "test"
    -
    -# send me output of a system command
    -send_message "$(getConfigKey "botadmin")" "$(df -h)"
    +

    For more information see Expert Use

    Blocked by telegram?

    This may happen if to many or wrong requests are sent to api.telegram.org, e.g. using a invalid token or not existing API calls. If the block stay for longer time you can ask telegram service to unblock your IP-Adress.

    You can check with curl or wget if you are blocked by Telegram:

    -
    curl -m 10  https://api.telegram.org/bot
    -#curl: (28) Connection timed out after 10001 milliseconds
    -
    -wget -t 1 -T 10 https://api.telegram.org/bot
    -#Connecting to api.telegram.org (api.telegram.org)|46.38.243.234|:443... failed: Connection timed out.
    +

    Since Version 0.96 bashbot offers the option to recover from broken connections (aka blocked). Therefore you can provide a function named bashbotBlockRecover() in mycommands.sh. If the function exists it is called every time when a broken connection is detected.

    Possible actions are: Check if network is working, change IP-Adress or simply wait some time.

    If everything seems OK return 0 for retry or any non 0 value to give up.

    -
    # called when bashbot sedn command failed because we can not connect to telegram
    -# return 0 to retry, return non 0 to give up
    -bashbotBlockRecover() {
    -    # place your commands to unblock here, e.g. change IP-Adess or simply wait
    -    sleep 60 && return 0 # may be temporary
    -    return 1 
    -    }
    -
    +

    @Gnadelwartz

    That's it all guys!

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

    -

    $$VERSION$$ v1.1-0-ge835bbc

    +

    $$VERSION$$ v1.1-29-ga1773cc

    diff --git a/README.md b/README.md index a9ab7a8..9d91676 100644 --- a/README.md +++ b/README.md @@ -265,4 +265,4 @@ bashbotBlockRecover() { If you feel that there's something missing or if you found a bug, feel free to submit a pull request! -#### $$VERSION$$ v1.1-0-ge835bbc +#### $$VERSION$$ v1.1-29-ga1773cc diff --git a/README.txt b/README.txt index e0252c6..ea1e6e6 100644 --- a/README.txt +++ b/README.txt @@ -151,9 +151,10 @@ debug` │   ├── BASHBOT.log # log what your bot is doing ... │   ├── ERROR.log # connection errors from / to telegram API │   │ -│   ├── DEBUG.log # stdout/stderr of you bot (debug mode enabled) -│   └── MESSAGE.log # full text of all message send/received (debug mode +│   ├── DEBUG.log # stdout/stderr of you bot (debug mode enabled) +│   └── MESSAGE.log # full text of all message send/received +(debug mode enabled) ``` ---- @@ -355,4 +356,4 @@ wait If you feel that there's something missing or if you found a bug, feel free to submit a pull request! -#### $$VERSION$$ v1.1-0-ge835bbc +#### $$VERSION$$ v1.1-29-ga1773cc diff --git a/bashbot.rc b/bashbot.rc index 6100154..063ff4e 100755 --- a/bashbot.rc +++ b/bashbot.rc @@ -1,7 +1,12 @@ #!/bin/sh # description: Start or stop telegram-bash-bot # -#### $$VERSION$$ v1.2-dev-13-g2a5d47d +# example service script to run bashbot in background +# may or may not work on your system +# +# tested on: ubuntu, opensuse +# +#### $$VERSION$$ v1.2-pre2-0-ga1773cc # shellcheck disable=SC2009 # shellcheck disable=SC2181 @@ -25,7 +30,7 @@ runcmd="echo Dry run:" # not activated until you edit lines below # edit the next line to fit the user you want to run bashbot, e.g. nobody: runas="nobody" -# uncomment one of the following lines to fit your system +# uncomment one of the example lines to fit your system # runcmd="su $runas -s /bin/bash -c " # runasuser with *su* # runcmd="runuser $runas -s /bin/bash -c " # runasuser with *runuser* diff --git a/bashbot.sh b/bashbot.sh index e9e5f27..8117047 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -11,7 +11,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.2-pre-0-gb4c83c1 +#### $$VERSION$$ v1.2-pre2-0-ga1773cc # # Exit Codes: # - 0 success (hopefully) @@ -23,7 +23,7 @@ # - 6 mandatory module not found # - 7 can't get bottoken # - 10 not bash! -# shellcheck disable=SC2140,SC2031,SC2120,SC1091 +# shellcheck disable=SC2140,SC2031,SC2120,SC1091,SC1117 # emmbeded system may claim bash but it is not # check for bash like ARRAY handlung @@ -1112,6 +1112,7 @@ fi if [ -z "${SOURCE}" ]; then ############## # internal options only for use from bashbot and developers + # shellcheck disable=SC2221,SC2222 case "${1}" in # update botname when starting only "botname"|"start"*) diff --git a/commands.sh b/commands.sh index af4f582..3b36d00 100644 --- a/commands.sh +++ b/commands.sh @@ -15,7 +15,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.1-0-gc0eb399 +#### $$VERSION$$ v1.1-29-ga1773cc # # adjust your language setting here, e.g. when run from other user or cron. @@ -89,7 +89,7 @@ if [ -z "${1}" ] || [[ "${1}" == *"debug"* ]];then ################### # user defined commands must placed in mycommands - _exec_if_function mycommands + ! _is_function mycommands || mycommands # run commands if true (0) is returned or if mycommands dose not exist # shellcheck disable=SC2181 diff --git a/dev/hooks/pre-commit.sh b/dev/hooks/pre-commit.sh index 73650c9..1308ea9 100755 --- a/dev/hooks/pre-commit.sh +++ b/dev/hooks/pre-commit.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v1.1-0-gc0eb399 +#### $$VERSION$$ v1.2-pre2-0-ga1773cc ############ # NOTE: you MUST run install-hooks.sh again when updating this file! @@ -68,7 +68,7 @@ fi if command -v codespell &>/dev/null; then echo "Running codespell" echo "............................" - codespell -B 1 --skip="*.log,*.html,*.txt,.git*,jsonDB-keyboard" -L "ba" + codespell --skip="*.log,*.html,*.txt,.git*,jsonDB-keyboard" -L "ba" echo "if there are (to many) typo's shown, consider running:" echo "codespell -i 3 -w --skip=\"*.log,*.html,*.txt,.git*,examples\" -L \"ba\"" else diff --git a/dev/obfuscate.sh b/dev/obfuscate.sh index ae37c0a..2cd77ca 100755 --- a/dev/obfuscate.sh +++ b/dev/obfuscate.sh @@ -1,5 +1,5 @@ #!/bin/bash -# shellcheck disable=SC2028,2016 +# shellcheck disable=SC2028,SC2016,SC1117 # joke hack to obfuscate bashbot.min.sh infile="bashbot.sh" diff --git a/doc/7_develop.md b/doc/7_develop.md index 59accb8..037692e 100644 --- a/doc/7_develop.md +++ b/doc/7_develop.md @@ -28,7 +28,6 @@ you can the change the level of verbosity of the debug argument: Logging of telegram update poll is disabled by default, also in `debug` mode. To enable it without using verbose `xdebug` mode set `BASHBOT_UPDATELOG` to an empty value (not unset) `export BASHBOT_UPDATELOG=""` - ### Modules and Addons **Modules** resides in ```modules/*.sh``` and are colletions of optional bashbot functions grouped by functionality. Main reason for creating modules was to keep 'bashbot.sh' small, while extending functionality. In addition not every function is needed by all bots, so you can @@ -191,7 +190,7 @@ Now have a look at the directory 'standalone', here you find the files 'bashbot. ### Setup your develop environment -1. install git, install [shellcheck](5_practice.md#Test-your-Bot-with-shellcheck) +1. install git, install [shellcheck](5_practice.md#Test-your-Bot-with-shellcheck), install pandoc 2. setup your [environment for UTF-8](4_expert.md#Setting-up-your-Environment) 3. clone your bashbot fork to a new directory ```git clone https://github.com//telegram-bot-bash.git```, replace `````` with your username on github 4. create and change to your develop branch ```git checkout -b ```, replace `````` with the name you want to name it, e.g. 'develop' @@ -350,5 +349,5 @@ fi #### [Prev Function Reference](6_reference.md) -#### $$VERSION$$ v1.2-pre-1-gb4dcb52 +#### $$VERSION$$ v1.2-pre2-0-ga1773cc diff --git a/examples/bash2env.sh b/examples/bash2env.sh index b2ff238..82a9439 100755 --- a/examples/bash2env.sh +++ b/examples/bash2env.sh @@ -5,8 +5,8 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) - -#### $$VERSION$$ v1.0-0-g99217c4 +# shellcheck disable=SC1117 +#### $$VERSION$$ v1.2-pre2-0-ga1773cc # adjust your language setting here # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment diff --git a/examples/jsonDB-keyboard/mycommands.sh b/examples/jsonDB-keyboard/mycommands.sh index 032eb14..2ad52e5 100644 --- a/examples/jsonDB-keyboard/mycommands.sh +++ b/examples/jsonDB-keyboard/mycommands.sh @@ -2,10 +2,9 @@ # files: mycommands.sh.dist # copy to mycommands.sh and add all your commands and functions here ... # -#### $$VERSION$$ v1.2-dev-13-g2a5d47d +#### $$VERSION$$ v1.2-pre2-0-ga1773cc # -# shellcheck disable=SC2154 -# shellcheck disable=SC2034 +# shellcheck disable=SC2154,SC2034,SC1117,SC2221,SC2222 # within *xxx* markup we need only one \ to escape a '_', e.g. my\_stupid\_bot (stupid V1 markup) bashbot_title='*Hallo, ich bin der @'"${ME//_/\\_}"'. Ich suche und finde Dealz!*' diff --git a/modules/background.sh b/modules/background.sh index 9220aee..3ed07df 100644 --- a/modules/background.sh +++ b/modules/background.sh @@ -5,7 +5,8 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ v1.0-0-g99217c4 +# shellcheck disable=SC1117 +#### $$VERSION$$ v1.2-pre2-0-ga1773cc # will be automatically sourced from bashbot diff --git a/modules/sendMessage.sh b/modules/sendMessage.sh index fc9d195..2f52306 100644 --- a/modules/sendMessage.sh +++ b/modules/sendMessage.sh @@ -5,7 +5,8 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ v1.1-0-gc0eb399 +# shellcheck disable=SC1117 +#### $$VERSION$$ v1.2-pre2-0-ga1773cc # will be automatically sourced from bashbot diff --git a/mycommands.sh b/mycommands.sh index 5cb5e75..a0fa00c 100644 --- a/mycommands.sh +++ b/mycommands.sh @@ -8,7 +8,8 @@ # #### if you start to develop your own bot, use the clean version of this file: # #### mycommands.clean # -#### $$VERSION$$ v1.1-0-gc0eb399 +# shellcheck disable=SC1117 +#### $$VERSION$$ v1.2-pre2-0-ga1773cc # # uncomment the following lines to overwrite info and help messages @@ -111,13 +112,13 @@ else # example for actions based on chat or sender case "${USER[ID]}+${CHAT[ID]}" in - 'USERID+'*) # do something for all messages from USER + 'USERID1+'*) # do something for all messages from USER printf "%s: U=%s C=%s M=%s\n" "$(date)" "${USER[ID]}" "${CHAT[ID]}" "${MESSAGE}" >>"${DATADIR}/${USER[ID]}.log" ;;& - *'+CHATID') # do something for all messages from CHAT + *'+CHATID1') # do something for all messages from CHAT printf "%s: U=%s C=%s M=%s\n" "$(date)" "${USER[ID]}" "${CHAT[ID]}" "${MESSAGE}" >>"${DATADIR}/${CHAT[ID]}.log" ;;& - 'USERID+CHATID') # do something only for messages form USER in CHAT + 'USERID2+CHATID2') # do something only for messages form USER in CHAT printf "%s: U=%s C=%s M=%s\n" "$(date)" "${USER[ID]}" "${CHAT[ID]}" "${MESSAGE}" >>"${DATADIR}/${CHAT[ID]}+${USER[ID]}.log" ;;& esac From 11c1d5532206f815b07bfb19ff13f536887ed20d Mon Sep 17 00:00:00 2001 From: Gnadelwartz Date: Sun, 29 Nov 2020 15:48:22 +0100 Subject: [PATCH 004/100] bc and codespell are optional --- dev/hooks/pre-commit.sh | 4 ++-- doc/7_develop.md | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dev/hooks/pre-commit.sh b/dev/hooks/pre-commit.sh index 1308ea9..a6130fd 100755 --- a/dev/hooks/pre-commit.sh +++ b/dev/hooks/pre-commit.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v1.2-pre2-0-ga1773cc +#### $$VERSION$$ v1.2-pre2-1-gb5caff0 ############ # NOTE: you MUST run install-hooks.sh again when updating this file! @@ -49,7 +49,7 @@ VERSION="$(git describe --tags | sed -e 's/-.*//' -e 's/v//' -e 's/,/./')" # LOCAL version must greater than latest REMOTE release version echo "Update Version of modified files" -if (( $(echo "${VERSION} >= ${REMOTEVER}" | bc -l) )); then +if ! command -v bc &> /dev/null || (( $(echo "${VERSION} >= ${REMOTEVER}" | bc -l) )); then # update version in bashbot files on push set +f [ -f "${LASTPUSH}" ] && LASTFILES="$(find ./* -newer "${LASTPUSH}")" diff --git a/doc/7_develop.md b/doc/7_develop.md index 037692e..25724b3 100644 --- a/doc/7_develop.md +++ b/doc/7_develop.md @@ -190,7 +190,7 @@ Now have a look at the directory 'standalone', here you find the files 'bashbot. ### Setup your develop environment -1. install git, install [shellcheck](5_practice.md#Test-your-Bot-with-shellcheck), install pandoc +1. install the commands git, [shellcheck](5_practice.md#Test-your-Bot-with-shellcheck), bc, pandoc, bc, codespell 2. setup your [environment for UTF-8](4_expert.md#Setting-up-your-Environment) 3. clone your bashbot fork to a new directory ```git clone https://github.com//telegram-bot-bash.git```, replace `````` with your username on github 4. create and change to your develop branch ```git checkout -b ```, replace `````` with the name you want to name it, e.g. 'develop' @@ -349,5 +349,5 @@ fi #### [Prev Function Reference](6_reference.md) -#### $$VERSION$$ v1.2-pre2-0-ga1773cc +#### $$VERSION$$ v1.2-pre2-1-gb5caff0 From 282448772a11b93fbb9b12ff96ee9ee0bdf9c843 Mon Sep 17 00:00:00 2001 From: Gnadelwartz Date: Sun, 29 Nov 2020 15:57:26 +0100 Subject: [PATCH 005/100] fix BASHBOT_UPDATELOG --- bashbot.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index 8117047..332a728 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -11,7 +11,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.2-pre2-0-ga1773cc +#### $$VERSION$$ v1.2-pre2-2-g11c1d55 # # Exit Codes: # - 0 success (hopefully) @@ -959,7 +959,7 @@ start_bot() { # redirect to Debug.log [[ "${1}" == *"debug" ]] && exec &>>"${DEBUGLOG}" printf "%s\n" "${DEBUGMSG}"; DEBUGMSG="${1}" - [[ "${DEBUGMSG}" == "xdebug"* ]] && set -x i && unset BASHBOT_UPDATELOG + [[ "${DEBUGMSG}" == "xdebug"* ]] && set -x && unset BASHBOT_UPDATELOG # cleaup old pipes and empty logfiles find "${DATADIR}" -type p -delete find "${DATADIR}" -size 0 -name "*.log" -delete From 95b2b9a79dce2a73ecc0c899ecbcc8ac2e6428fb Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sun, 29 Nov 2020 17:20:57 +0100 Subject: [PATCH 006/100] detect if no curl AND no wget --- README.html | 218 +++++++++++++------------ README.md | 2 +- README.txt | 7 +- bashbot.rc | 2 +- bashbot.sh | 32 ++-- commands.sh | 2 +- dev/hooks/pre-commit.sh | 2 +- doc/7_develop.md | 2 +- examples/bash2env.sh | 2 +- examples/jsonDB-keyboard/mycommands.sh | 2 +- modules/background.sh | 2 +- modules/sendMessage.sh | 2 +- mycommands.sh | 2 +- 13 files changed, 146 insertions(+), 131 deletions(-) diff --git a/README.html b/README.html index 4d91e68..9a235df 100644 --- a/README.html +++ b/README.html @@ -5,78 +5,82 @@ Bashbot README - - + -
    +

    Bashbot README

    @@ -91,7 +95,7 @@ Written by Drew (@topkecleon) and Kay M (@gnadelwartz).

    Uses JSON.sh and the magic of sed.

    Even bashbot is written in bash, it depends on commands typically available in a Unix/Linux Environment. More concrete on the common commands provided by recent versions of coreutils, busybox or toybox, see Developer Notes

    Note for MacOS and BSD Users: As bashbot heavily uses modern bash and (gnu) grep/sed features, bashbot will not run without installing additional software, see Install Bashbot

    -

    Note for embedded systems: busybox or toybox ONLY is not sufficient, you need a to install a "real" bash, see also Install Bashbot

    +

    Note for embedded systems: busybox or toybox ONLY is not sufficient, you need a to install a "real" bash, see also Install Bashbot

    Bashbot Documentation and Downloads are available on www.github.com

    Documentation

      @@ -158,8 +162,8 @@ Written by Drew (@topkecleon) and Kay M (@gnadelwartz).

      Now open a terminal and check if bash is installed:

      which bash && echo "bash seems available..."
       
      -

      Create a new directory, change to it: mkdir tbb; cd tbb and download the latest '*.tar.gz' file from https://github.com/topkecleon/telegram-bot-bash/releases. This can be done with the commands:

      - +

      Create a new directory, change to it: mkdir tbb; cd tbb and download the latest '*.tar.gz' file from https://github.com/topkecleon/telegram-bot-bash/releases. This can be done with the commands:

      +
      wget -q https://github.com/$(wget -q https://github.com/topkecleon/telegram-bot-bash/releases/latest -O - | egrep '/.*/.*/.*tar.gz' -o)

      Extract the '*.tar.gz' file and change to bashbot directory: tar -xzf *.tar.gz; cd telegram-bot-bash, install bashbot: ./bashbot.sh init and enter your bot token when asked. All other questions can be answered by hitting the <Return> key.

      That's all, now you can start your bot with ./bashbot.sh start and send him messages:

      /start
      @@ -196,18 +200,18 @@ It features background tasks and interactive chats, and can serve as an interfac
       

      A powerful tool to improve your scripts is shellcheck. You can use it online or install shellcheck locally. Shellcheck is used extensively in bashbot development to ensure a high code quality, e.g. it's not allowed to push changes without passing all shellcheck tests. In addition bashbot has a test suite to check if important functionality is working as expected.

      Use printf whenever possible

      If you're writing a script and it is taking external input (from the user as arguments or file system...), you shouldn't use echo to display it. Use printf whenever possible

      - +
        # very simple
      +  echo "text with variables. PWD=$PWD"
      +  printf '%s\n' "text with variables. PWD=$PWD"
      +  -> text with variables. PWD=/home/xxx
      +
      +  # more advanced
      +  FLOAT="1.2346777892864" INTEGER="12345.123"
      +  echo "text with variabeles. float=$FLOAT, integer=$INTEGER, PWD=$PWD"
      +  ->text with variables. float=1.2346777892864, integer=12345.123, PWD=/home/xxx
      +
      +  printf "text with variables. float=%.2f, integer=%d, PWD=%s\n" "" "$INTEGER" "$PWD"
      +  ->text with variables. float=1.23, integer=12345, PWD=/home/xxx

      Do not use #!/usr/bin/env bash

      We stay with /bin/bash shebang, because it's more save from security perspective.

      Use of a fixed path to the system provided bash makes it harder for attackers or users to place alternative versions of bash and avoids using a possibly broken, mangled or compromised bash executable.

      @@ -237,38 +241,38 @@ It features background tasks and interactive chats, and can serve as an interfac

      Can I send messages from CLI and scripts?

      Of course, you can send messages from CLI and scripts, simply install bashbot as described here, send the message '/start' to set yourself as botadmin and stop the bot with ./bashbot.sh stop.

      Run the following commands in your bash shell or script while you are in the installation directory:

      - +
      # prepare bash / script to send commands
      +export BASHBOT_HOME="$(pwd)"
      +source ./bashbot.sh source
      +
      +# send me a test message
      +send_message "$(getConfigKey "botadmin")" "test"
      +
      +# send me output of a system command
      +send_message "$(getConfigKey "botadmin")" "$(df -h)"

      For more information see Expert Use

      Blocked by telegram?

      This may happen if to many or wrong requests are sent to api.telegram.org, e.g. using a invalid token or not existing API calls. If the block stay for longer time you can ask telegram service to unblock your IP-Adress.

      You can check with curl or wget if you are blocked by Telegram:

      - +
      curl -m 10  https://api.telegram.org/bot
      +#curl: (28) Connection timed out after 10001 milliseconds
      +
      +wget -t 1 -T 10 https://api.telegram.org/bot
      +#Connecting to api.telegram.org (api.telegram.org)|46.38.243.234|:443... failed: Connection timed out.

      Since Version 0.96 bashbot offers the option to recover from broken connections (aka blocked). Therefore you can provide a function named bashbotBlockRecover() in mycommands.sh. If the function exists it is called every time when a broken connection is detected.

      Possible actions are: Check if network is working, change IP-Adress or simply wait some time.

      If everything seems OK return 0 for retry or any non 0 value to give up.

      - +
      # called when bashbot sedn command failed because we can not connect to telegram
      +# return 0 to retry, return non 0 to give up
      +bashbotBlockRecover() {
      +    # place your commands to unblock here, e.g. change IP-Adess or simply wait
      +    sleep 60 && return 0 # may be temporary
      +    return 1 
      +    }
      +

      @Gnadelwartz

      That's it all guys!

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

      -

      $$VERSION$$ v1.1-29-ga1773cc

      +

      $$VERSION$$ v1.2-pre2-0-g2824487

      diff --git a/README.md b/README.md index 9d91676..b61772a 100644 --- a/README.md +++ b/README.md @@ -265,4 +265,4 @@ bashbotBlockRecover() { If you feel that there's something missing or if you found a bug, feel free to submit a pull request! -#### $$VERSION$$ v1.1-29-ga1773cc +#### $$VERSION$$ v1.2-pre2-0-g2824487 diff --git a/README.txt b/README.txt index ea1e6e6..b8e18bc 100644 --- a/README.txt +++ b/README.txt @@ -151,10 +151,9 @@ debug` │   ├── BASHBOT.log # log what your bot is doing ... │   ├── ERROR.log # connection errors from / to telegram API │   │ -│   ├── DEBUG.log # stdout/stderr of you bot (debug mode +│   ├── DEBUG.log # stdout/stderr of you bot (debug mode enabled) +│   └── MESSAGE.log # full text of all message send/received (debug mode enabled) -│   └── MESSAGE.log # full text of all message send/received -(debug mode enabled) ``` ---- @@ -356,4 +355,4 @@ wait If you feel that there's something missing or if you found a bug, feel free to submit a pull request! -#### $$VERSION$$ v1.1-29-ga1773cc +#### $$VERSION$$ v1.2-pre2-0-g2824487 diff --git a/bashbot.rc b/bashbot.rc index 063ff4e..a783431 100755 --- a/bashbot.rc +++ b/bashbot.rc @@ -6,7 +6,7 @@ # # tested on: ubuntu, opensuse # -#### $$VERSION$$ v1.2-pre2-0-ga1773cc +#### $$VERSION$$ v1.2-pre2-0-g2824487 # shellcheck disable=SC2009 # shellcheck disable=SC2181 diff --git a/bashbot.sh b/bashbot.sh index 332a728..84499d1 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -11,7 +11,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.2-pre2-2-g11c1d55 +#### $$VERSION$$ v1.2-pre2-0-g2824487 # # Exit Codes: # - 0 success (hopefully) @@ -22,6 +22,7 @@ # - 5 cannot connect to telegram bot # - 6 mandatory module not found # - 7 can't get bottoken +# - 8 curl/wget missing # - 10 not bash! # shellcheck disable=SC2140,SC2031,SC2120,SC1091,SC1117 @@ -385,6 +386,7 @@ get_file() { printf '%s\n' "${URL}"/"$(JsonGetString <<< "${res}" '"result","file_path"')" } +# curl is preferred, try detect curl even not in PATH # return TRUE if curl is found or custom curl detected # return FALSE if no curl is found or wget is forced by BASHBOT_WGET # sets BASHBOT_CURL to point to curl @@ -421,8 +423,8 @@ TIMEOUT="${BASHBOT_TIMEOUT}" [[ "$TIMEOUT" =~ ^[0-9]+$ ]] || TIMEOUT="20" if detect_curl ; then + # here we have curl ---- [ -z "${BASHBOT_CURL}" ] && BASHBOT_CURL="curl" - # simple curl or wget call, output to stdout getJson(){ [[ -n "${BASHBOTDEBUG}" && -n "${3}" ]] && printf "%s: getJson (curl) URL=%s\n" "$(date)" "${1##*/}" >>"${DEBUGLOG}" # shellcheck disable=SC2086 @@ -459,14 +461,15 @@ if detect_curl ; then [ -n "${BASHBOT_EVENT_SEND[*]}" ] && event_send "upload" "$@" & } else - # simple curl or wget call outputs result to stdout - getJson(){ + # NO curl, try wget + if _exists wget; then + getJson(){ [[ -n "${BASHBOTDEBUG}" && -z "${3}" ]] && printf "%s: getJson (wget) URL=%s\n" "$(date)" "${1##*/}" >>"${DEBUGLOG}" # shellcheck disable=SC2086 wget --no-check-certificate -t 2 -T "${TIMEOUT}" ${BASHBOT_WGET_ARGS} -qO - "$1" - } - # usage: sendJson "chat" "JSON" "URL" - sendJson(){ + } + # usage: sendJson "chat" "JSON" "URL" + sendJson(){ local chat=""; [ -n "${1}" ] && chat='"chat_id":'"${1}"',' [ -n "${BASHBOTDEBUG}" ] &&\ @@ -476,12 +479,21 @@ else --header='Content-Type:application/json' "${3}" | "${JSONSHFILE}" -b -n 2>/dev/null )" sendJsonResult "${res}" "sendJson (wget)" "$@" [ -n "${BASHBOT_EVENT_SEND[*]}" ] && event_send "send" "${@}" & - } - sendUpload() { + } + sendUpload() { log_error "Sorry, wget does not support file upload" BOTSENT[OK]="false" [ -n "${BASHBOT_EVENT_SEND[*]}" ] && event_send "upload" "$@" & - } + } + else + # ups, no curl AND no wget + if [ -n "${BASHBOT_WGET}" ]; then + printf "%s: Error: You set BASHBOT_WGET but no wget found!\n" "$(date)" + else + printf "%s: Error: You must at least install curl or wget\n" "$(date)" + fi + exit 8 + fi fi # retry sendJson diff --git a/commands.sh b/commands.sh index 3b36d00..f2cd4e2 100644 --- a/commands.sh +++ b/commands.sh @@ -15,7 +15,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.1-29-ga1773cc +#### $$VERSION$$ v1.2-pre2-0-g2824487 # # adjust your language setting here, e.g. when run from other user or cron. diff --git a/dev/hooks/pre-commit.sh b/dev/hooks/pre-commit.sh index a6130fd..b546703 100755 --- a/dev/hooks/pre-commit.sh +++ b/dev/hooks/pre-commit.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v1.2-pre2-1-gb5caff0 +#### $$VERSION$$ v1.2-pre2-0-g2824487 ############ # NOTE: you MUST run install-hooks.sh again when updating this file! diff --git a/doc/7_develop.md b/doc/7_develop.md index 25724b3..db6fd63 100644 --- a/doc/7_develop.md +++ b/doc/7_develop.md @@ -349,5 +349,5 @@ fi #### [Prev Function Reference](6_reference.md) -#### $$VERSION$$ v1.2-pre2-1-gb5caff0 +#### $$VERSION$$ v1.2-pre2-0-g2824487 diff --git a/examples/bash2env.sh b/examples/bash2env.sh index 82a9439..853dff9 100755 --- a/examples/bash2env.sh +++ b/examples/bash2env.sh @@ -6,7 +6,7 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # shellcheck disable=SC1117 -#### $$VERSION$$ v1.2-pre2-0-ga1773cc +#### $$VERSION$$ v1.2-pre2-0-g2824487 # adjust your language setting here # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment diff --git a/examples/jsonDB-keyboard/mycommands.sh b/examples/jsonDB-keyboard/mycommands.sh index 2ad52e5..0f684ef 100644 --- a/examples/jsonDB-keyboard/mycommands.sh +++ b/examples/jsonDB-keyboard/mycommands.sh @@ -2,7 +2,7 @@ # files: mycommands.sh.dist # copy to mycommands.sh and add all your commands and functions here ... # -#### $$VERSION$$ v1.2-pre2-0-ga1773cc +#### $$VERSION$$ v1.2-pre2-0-g2824487 # # shellcheck disable=SC2154,SC2034,SC1117,SC2221,SC2222 diff --git a/modules/background.sh b/modules/background.sh index 3ed07df..4179d50 100644 --- a/modules/background.sh +++ b/modules/background.sh @@ -6,7 +6,7 @@ # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # # shellcheck disable=SC1117 -#### $$VERSION$$ v1.2-pre2-0-ga1773cc +#### $$VERSION$$ v1.2-pre2-0-g2824487 # will be automatically sourced from bashbot diff --git a/modules/sendMessage.sh b/modules/sendMessage.sh index 2f52306..573e806 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.2-pre2-0-ga1773cc +#### $$VERSION$$ v1.2-pre2-0-g2824487 # will be automatically sourced from bashbot diff --git a/mycommands.sh b/mycommands.sh index a0fa00c..9d6f178 100644 --- a/mycommands.sh +++ b/mycommands.sh @@ -9,7 +9,7 @@ # #### mycommands.clean # # shellcheck disable=SC1117 -#### $$VERSION$$ v1.2-pre2-0-ga1773cc +#### $$VERSION$$ v1.2-pre2-0-g2824487 # # uncomment the following lines to overwrite info and help messages From ef80aa5690bd66d25795aa5217cba3afda40c476 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sun, 29 Nov 2020 17:43:00 +0100 Subject: [PATCH 007/100] better curl/wget not found message --- bashbot.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index 84499d1..dd04913 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -11,7 +11,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.2-pre2-0-g2824487 +#### $$VERSION$$ v1.2-pre2-1-g95b2b9a # # Exit Codes: # - 0 success (hopefully) @@ -488,9 +488,9 @@ else else # ups, no curl AND no wget if [ -n "${BASHBOT_WGET}" ]; then - printf "%s: Error: You set BASHBOT_WGET but no wget found!\n" "$(date)" + echo -e "${RED}Error: You set BASHBOT_WGET but no wget found!${NC}" else - printf "%s: Error: You must at least install curl or wget\n" "$(date)" + echo -e "${RED}Error: curl and wget not found, install curl!${NC}" fi exit 8 fi @@ -1173,7 +1173,7 @@ if [ -z "${SOURCE}" ]; then exit ;; # print usage stats - "count") echo -e "${RED}Command ${GREY}count${RED} is deprecated, use ${GREY}stats{$RED}instead.${NC}";& + "count") echo -e "${RED}Command ${GREY}count${RED} is deprecated, use ${GREY}stats${RED}instead.${NC}";& "stats") ME="$(getConfigKey "botname")" declare -A STATS From aac3ddf45fcf75cf6ffc79d630e505d8009d9405 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sun, 29 Nov 2020 17:44:20 +0100 Subject: [PATCH 008/100] fix make-dist --- README.html | 2 +- README.md | 2 +- README.txt | 2 +- bashbot.rc | 2 +- bashbot.sh | 2 +- commands.sh | 2 +- dev/hooks/pre-commit.sh | 2 +- dev/make-distribution.sh | 6 +++--- doc/7_develop.md | 2 +- examples/bash2env.sh | 2 +- examples/jsonDB-keyboard/mycommands.sh | 2 +- modules/background.sh | 2 +- modules/sendMessage.sh | 2 +- mycommands.sh | 2 +- 14 files changed, 16 insertions(+), 16 deletions(-) diff --git a/README.html b/README.html index 9a235df..ca6492e 100644 --- a/README.html +++ b/README.html @@ -273,6 +273,6 @@ It features background tasks and interactive chats, and can serve as an interfac

      @Gnadelwartz

      That's it all guys!

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

      -

      $$VERSION$$ v1.2-pre2-0-g2824487

      +

      $$VERSION$$ v1.2-pre2-2-gef80aa5

      diff --git a/README.md b/README.md index b61772a..7eb13e3 100644 --- a/README.md +++ b/README.md @@ -265,4 +265,4 @@ bashbotBlockRecover() { If you feel that there's something missing or if you found a bug, feel free to submit a pull request! -#### $$VERSION$$ v1.2-pre2-0-g2824487 +#### $$VERSION$$ v1.2-pre2-2-gef80aa5 diff --git a/README.txt b/README.txt index b8e18bc..995ef71 100644 --- a/README.txt +++ b/README.txt @@ -355,4 +355,4 @@ wait If you feel that there's something missing or if you found a bug, feel free to submit a pull request! -#### $$VERSION$$ v1.2-pre2-0-g2824487 +#### $$VERSION$$ v1.2-pre2-2-gef80aa5 diff --git a/bashbot.rc b/bashbot.rc index a783431..c4032bd 100755 --- a/bashbot.rc +++ b/bashbot.rc @@ -6,7 +6,7 @@ # # tested on: ubuntu, opensuse # -#### $$VERSION$$ v1.2-pre2-0-g2824487 +#### $$VERSION$$ v1.2-pre2-2-gef80aa5 # shellcheck disable=SC2009 # shellcheck disable=SC2181 diff --git a/bashbot.sh b/bashbot.sh index dd04913..f331020 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -11,7 +11,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.2-pre2-1-g95b2b9a +#### $$VERSION$$ v1.2-pre2-2-gef80aa5 # # Exit Codes: # - 0 success (hopefully) diff --git a/commands.sh b/commands.sh index f2cd4e2..60c5b51 100644 --- a/commands.sh +++ b/commands.sh @@ -15,7 +15,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.2-pre2-0-g2824487 +#### $$VERSION$$ v1.2-pre2-2-gef80aa5 # # adjust your language setting here, e.g. when run from other user or cron. diff --git a/dev/hooks/pre-commit.sh b/dev/hooks/pre-commit.sh index b546703..b17a54f 100755 --- a/dev/hooks/pre-commit.sh +++ b/dev/hooks/pre-commit.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v1.2-pre2-0-g2824487 +#### $$VERSION$$ v1.2-pre2-2-gef80aa5 ############ # NOTE: you MUST run install-hooks.sh again when updating this file! diff --git a/dev/make-distribution.sh b/dev/make-distribution.sh index be4d110..b9e9b19 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$$ v1.1-0-gc0eb399 +#### $$VERSION$$ v1.2-pre2-2-gef80aa5 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script @@ -57,8 +57,8 @@ fi # make html doc echo "Create html doc" -#shellcheck disable=SC1090 -source "$GIT_DIR/../dev/make-html.sh" +# shellcheck disable=SC1090,SC1091 +source "../../dev/make-html.sh" # create archive cd .. || exit 1 diff --git a/doc/7_develop.md b/doc/7_develop.md index db6fd63..3358a08 100644 --- a/doc/7_develop.md +++ b/doc/7_develop.md @@ -349,5 +349,5 @@ fi #### [Prev Function Reference](6_reference.md) -#### $$VERSION$$ v1.2-pre2-0-g2824487 +#### $$VERSION$$ v1.2-pre2-2-gef80aa5 diff --git a/examples/bash2env.sh b/examples/bash2env.sh index 853dff9..6964a70 100755 --- a/examples/bash2env.sh +++ b/examples/bash2env.sh @@ -6,7 +6,7 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # shellcheck disable=SC1117 -#### $$VERSION$$ v1.2-pre2-0-g2824487 +#### $$VERSION$$ v1.2-pre2-2-gef80aa5 # adjust your language setting here # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment diff --git a/examples/jsonDB-keyboard/mycommands.sh b/examples/jsonDB-keyboard/mycommands.sh index 0f684ef..9fe79e4 100644 --- a/examples/jsonDB-keyboard/mycommands.sh +++ b/examples/jsonDB-keyboard/mycommands.sh @@ -2,7 +2,7 @@ # files: mycommands.sh.dist # copy to mycommands.sh and add all your commands and functions here ... # -#### $$VERSION$$ v1.2-pre2-0-g2824487 +#### $$VERSION$$ v1.2-pre2-2-gef80aa5 # # shellcheck disable=SC2154,SC2034,SC1117,SC2221,SC2222 diff --git a/modules/background.sh b/modules/background.sh index 4179d50..a2422bb 100644 --- a/modules/background.sh +++ b/modules/background.sh @@ -6,7 +6,7 @@ # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # # shellcheck disable=SC1117 -#### $$VERSION$$ v1.2-pre2-0-g2824487 +#### $$VERSION$$ v1.2-pre2-2-gef80aa5 # will be automatically sourced from bashbot diff --git a/modules/sendMessage.sh b/modules/sendMessage.sh index 573e806..d20457f 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.2-pre2-0-g2824487 +#### $$VERSION$$ v1.2-pre2-2-gef80aa5 # will be automatically sourced from bashbot diff --git a/mycommands.sh b/mycommands.sh index 9d6f178..e724487 100644 --- a/mycommands.sh +++ b/mycommands.sh @@ -9,7 +9,7 @@ # #### mycommands.clean # # shellcheck disable=SC1117 -#### $$VERSION$$ v1.2-pre2-0-g2824487 +#### $$VERSION$$ v1.2-pre2-2-gef80aa5 # # uncomment the following lines to overwrite info and help messages From c50499c7ff5d552835f1341a8e0a2cd7fb05fcfa Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Mon, 30 Nov 2020 18:36:21 +0100 Subject: [PATCH 009/100] remove unwanted comments from standalone scripts --- dev/make-standalone.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dev/make-standalone.sh b/dev/make-standalone.sh index 816645a..e09cc8b 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$$ v1.1-0-gc0eb399 +#### $$VERSION$$ v1.2-pre2-3-gaac3ddf # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script @@ -38,7 +38,7 @@ echo " ... create unified commands.sh" { # first head of commands.sh - sed -n '0,/^if / p' commands.sh | head -n -2 + sed -n '0,/^if / p' commands.sh | grep -v -F -e "___" -e "*MUST*" -e "mycommands.sh.dist" -e "mycommands.sh.clean"| head -n -2 # then mycommands from first non comment line on printf '\n##############################\n# my commands starts here ...\n' @@ -77,7 +77,7 @@ rm -rf modules echo "Create minimized Version of bashbot.sh and commands.sh" sed -E -e '/(shellcheck)|(#!\/bin\/bash)/! s/^[[:space:]]*#.*//' -e 's/^[[:space:]]*//' -e '/^$/d' -e 'N;s/\\\n/ /;P;D' bashbot.sh |\ sed 'N;s/\\\n/ /;P;D' > bashbot.sh.min -sed -E -e '/(shellcheck)|(#!\/bin\/bash)/! s/^[[:space:]]*#.*//' -e 's/^[[:space:]]*//' -e '/^$/d' commands.sh |\ +sed -E -e '/(shellcheck)|(#!\/bin\/bash)/! s/^[[:space:]]*#.*//' -e 's/^[[:space:]]*//' -e 's/\)[[:space:]]+#.*/)/' -e '/^$/d' commands.sh |\ sed 'N;s/\\\n/ /;P;D' > commands.sh.min chmod +x bashbot.sh.min From d30a700b3356ffdca8826ba195bc58d82c7dafd9 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Mon, 30 Nov 2020 18:38:19 +0100 Subject: [PATCH 010/100] change Version to v1.2 --- README.html | 2 +- README.md | 2 +- README.txt | 2 +- addons/antiFlood.sh | 2 +- addons/example.sh | 2 +- bashbot.rc | 2 +- bashbot.sh | 2 +- commands.sh | 2 +- 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 +- examples/README.md | 2 +- examples/background-scripts/run_diskusage.sh | 2 +- examples/background-scripts/run_filecontent.sh | 2 +- examples/background-scripts/run_filename.sh | 2 +- examples/background-scripts/run_notify.sh | 2 +- examples/bash2env.sh | 2 +- examples/bashbot-multi.sh | 2 +- examples/bashbot.cron | 2 +- examples/calc.sh | 2 +- examples/jsonDB-keyboard/mycommands.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 | 2 +- modules/chatMember.sh | 2 +- modules/jsonDB.sh | 2 +- modules/sendMessage.sh | 2 +- mycommands.sh | 2 +- mycommands.sh.clean | 2 +- scripts/interactive.sh.clean | 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 +- 59 files changed, 59 insertions(+), 59 deletions(-) diff --git a/README.html b/README.html index ca6492e..7c538ee 100644 --- a/README.html +++ b/README.html @@ -273,6 +273,6 @@ It features background tasks and interactive chats, and can serve as an interfac

      @Gnadelwartz

      That's it all guys!

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

      -

      $$VERSION$$ v1.2-pre2-2-gef80aa5

      +

      $$VERSION$$ v1.2-0-gc50499c

      diff --git a/README.md b/README.md index 7eb13e3..ea86121 100644 --- a/README.md +++ b/README.md @@ -265,4 +265,4 @@ bashbotBlockRecover() { If you feel that there's something missing or if you found a bug, feel free to submit a pull request! -#### $$VERSION$$ v1.2-pre2-2-gef80aa5 +#### $$VERSION$$ v1.2-0-gc50499c diff --git a/README.txt b/README.txt index 995ef71..39c1363 100644 --- a/README.txt +++ b/README.txt @@ -355,4 +355,4 @@ wait If you feel that there's something missing or if you found a bug, feel free to submit a pull request! -#### $$VERSION$$ v1.2-pre2-2-gef80aa5 +#### $$VERSION$$ v1.2-0-gc50499c diff --git a/addons/antiFlood.sh b/addons/antiFlood.sh index d3f0696..214498f 100644 --- a/addons/antiFlood.sh +++ b/addons/antiFlood.sh @@ -4,7 +4,7 @@ # this addon counts how many files, e.g. stickers, are sent to # a chat and takes actions if threshold is reached # -#### $$VERSION$$ v1.0-0-g99217c4 +#### $$VERSION$$ v1.2-0-gc50499c # used events: # diff --git a/addons/example.sh b/addons/example.sh index 8e307a6..4cffd77 100644 --- a/addons/example.sh +++ b/addons/example.sh @@ -4,7 +4,7 @@ # Addons can register to bashbot events at startup # by providing their name and a callback per event # -#### $$VERSION$$ v1.2-dev-13-g2a5d47d +#### $$VERSION$$ v1.2-0-gc50499c # # If an event occurs each registered event function is called. # diff --git a/bashbot.rc b/bashbot.rc index c4032bd..693880e 100755 --- a/bashbot.rc +++ b/bashbot.rc @@ -6,7 +6,7 @@ # # tested on: ubuntu, opensuse # -#### $$VERSION$$ v1.2-pre2-2-gef80aa5 +#### $$VERSION$$ v1.2-0-gc50499c # shellcheck disable=SC2009 # shellcheck disable=SC2181 diff --git a/bashbot.sh b/bashbot.sh index f331020..dd7ea9c 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -11,7 +11,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.2-pre2-2-gef80aa5 +#### $$VERSION$$ v1.2-0-gc50499c # # Exit Codes: # - 0 success (hopefully) diff --git a/commands.sh b/commands.sh index 60c5b51..4b9c667 100644 --- a/commands.sh +++ b/commands.sh @@ -15,7 +15,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.2-pre2-2-gef80aa5 +#### $$VERSION$$ v1.2-0-gc50499c # # adjust your language setting here, e.g. when run from other user or cron. diff --git a/dev/all-tests.sh b/dev/all-tests.sh index e9e1ab8..91e45f4 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$$ v1.1-0-gc0eb399 +#### $$VERSION$$ v1.2-0-gc50499c # 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 e0614d5..2e7cb5f 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$$ v1.1-0-gc0eb399 +#### $$VERSION$$ v1.2-0-gc50499c # 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 b17a54f..e1bf28f 100755 --- a/dev/hooks/pre-commit.sh +++ b/dev/hooks/pre-commit.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v1.2-pre2-2-gef80aa5 +#### $$VERSION$$ v1.2-0-gc50499c ############ # 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 341cd9a..877b299 100755 --- a/dev/hooks/pre-push.sh +++ b/dev/hooks/pre-push.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v1.1-0-gc0eb399 +#### $$VERSION$$ v1.2-0-gc50499c ############ # 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 f4f12cc..ba0d8e4 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$$ v1.1-0-gc0eb399 +#### $$VERSION$$ v1.2-0-gc50499c # 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 b9e9b19..f2f992a 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$$ v1.2-pre2-2-gef80aa5 +#### $$VERSION$$ v1.2-0-gc50499c # 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 e09cc8b..507ce15 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$$ v1.2-pre2-3-gaac3ddf +#### $$VERSION$$ v1.2-0-gc50499c # 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 207ffed..f6f53fb 100644 --- a/dev/shellcheck.files +++ b/dev/shellcheck.files @@ -1,4 +1,4 @@ # list of additional files to check from shellcheck -#### $$VERSION$$ v1.1-0-gc0eb399 +#### $$VERSION$$ v1.2-0-gc50499c bashbot.rc mycommands.sh.clean diff --git a/dev/version.sh b/dev/version.sh index 00a3075..1eb32cd 100755 --- a/dev/version.sh +++ b/dev/version.sh @@ -1,6 +1,6 @@ #!/bin/bash # -#### $$VERSION$$ v1.1-0-gc0eb399 +#### $$VERSION$$ v1.2-0-gc50499c # shellcheck disable=SC2016 # # Easy Versioning in git: diff --git a/doc/0_install.md b/doc/0_install.md index 4bd2735..19944b8 100644 --- a/doc/0_install.md +++ b/doc/0_install.md @@ -169,5 +169,5 @@ The old format is supported for backward compatibility, but may fail for corner #### [Next Create Bot](1_firstbot.md) -#### $$VERSION$$ v1.1-0-ge835bbc +#### $$VERSION$$ v1.2-0-gc50499c diff --git a/doc/1_firstbot.md b/doc/1_firstbot.md index 2ab8bce..3ec3a16 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$$ v1.0-0-g99217c4 +#### $$VERSION$$ v1.2-0-gc50499c diff --git a/doc/2_usage.md b/doc/2_usage.md index 5a89c40..d4ed03c 100644 --- a/doc/2_usage.md +++ b/doc/2_usage.md @@ -283,5 +283,5 @@ send_action "${CHAT[ID]}" "action" #### [Prev Create Bot](1_firstbot.md) #### [Next Advanced Usage](3_advanced.md) -#### $$VERSION$$ v1.1-0-gc0eb399 +#### $$VERSION$$ v1.2-0-gc50499c diff --git a/doc/3_advanced.md b/doc/3_advanced.md index ceb3eb0..a499036 100644 --- a/doc/3_advanced.md +++ b/doc/3_advanced.md @@ -297,5 +297,5 @@ Note: If you disable automatic retry, se above, you disable also connection prob #### [Prev Getting started](2_usage.md) #### [Next Expert Use](4_expert.md) -#### $$VERSION$$ v1.2-dev-14-g6ec00d4 +#### $$VERSION$$ v1.2-0-gc50499c diff --git a/doc/4_expert.md b/doc/4_expert.md index 3f08ebe..73e0f59 100644 --- a/doc/4_expert.md +++ b/doc/4_expert.md @@ -378,5 +378,5 @@ for every poll until the maximum of BASHBOT_SLEEP ms. #### [Prev Advanced Use](3_advanced.md) #### [Next Best Practice](5_practice.md) -#### $$VERSION$$ v1.2-dev-13-g2a5d47d +#### $$VERSION$$ v1.2-0-gc50499c diff --git a/doc/5_practice.md b/doc/5_practice.md index dcdc963..4e6ac01 100644 --- a/doc/5_practice.md +++ b/doc/5_practice.md @@ -158,5 +158,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$$ v1.2-dev-13-g2a5d47d +#### $$VERSION$$ v1.2-0-gc50499c diff --git a/doc/6_reference.md b/doc/6_reference.md index 4288f31..3947dcc 100644 --- a/doc/6_reference.md +++ b/doc/6_reference.md @@ -1049,5 +1049,5 @@ The name of your bot is available as bash variable "$ME", there is no need to ca #### [Prev Best Practice](5_practice.md) #### [Next Notes for Developers](7_develop.md) -#### $$VERSION$$ v1.2-dev-13-g2a5d47d +#### $$VERSION$$ v1.2-0-gc50499c diff --git a/doc/7_develop.md b/doc/7_develop.md index 3358a08..7c00da4 100644 --- a/doc/7_develop.md +++ b/doc/7_develop.md @@ -349,5 +349,5 @@ fi #### [Prev Function Reference](6_reference.md) -#### $$VERSION$$ v1.2-pre2-2-gef80aa5 +#### $$VERSION$$ v1.2-0-gc50499c diff --git a/examples/README.md b/examples/README.md index eeb8d12..467a8ca 100644 --- a/examples/README.md +++ b/examples/README.md @@ -56,6 +56,6 @@ convert existing bots. **jsonDB-keybords** contains a stripped down real world example from my bot showing the usage of jsonDB to store and retrieve values plus use of keyboards in private chats. It's an extended version of mycommands.sh.dist. Messages and help are in german. -#### $$VERSION$$ v1.0-0-g99217c4 +#### $$VERSION$$ v1.2-0-gc50499c diff --git a/examples/background-scripts/run_diskusage.sh b/examples/background-scripts/run_diskusage.sh index 228b1fc..d75d530 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$$ v1.2-dev-13-g2a5d47d +#### $$VERSION$$ v1.2-0-gc50499c ###### # parameters diff --git a/examples/background-scripts/run_filecontent.sh b/examples/background-scripts/run_filecontent.sh index 2daf1f2..e1ebd81 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$$ v1.2-dev-13-g2a5d47d +#### $$VERSION$$ v1.2-0-gc50499c ###### # parameters diff --git a/examples/background-scripts/run_filename.sh b/examples/background-scripts/run_filename.sh index daf56ca..5559b4e 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$$ v1.2-dev-13-g2a5d47d +#### $$VERSION$$ v1.2-0-gc50499c ###### # parameters diff --git a/examples/background-scripts/run_notify.sh b/examples/background-scripts/run_notify.sh index 6460fa0..4515080 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$$ v1.0-0-g99217c4 +#### $$VERSION$$ v1.2-0-gc50499c ###### # parameters diff --git a/examples/bash2env.sh b/examples/bash2env.sh index 6964a70..5e0440e 100755 --- a/examples/bash2env.sh +++ b/examples/bash2env.sh @@ -6,7 +6,7 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # shellcheck disable=SC1117 -#### $$VERSION$$ v1.2-pre2-2-gef80aa5 +#### $$VERSION$$ v1.2-0-gc50499c # 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 7ae8de8..4356480 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$$ v1.2-dev-13-g2a5d47d +#### $$VERSION$$ v1.2-0-gc50499c if [ "${2}" = "" ] || [ "${2}" = "-h" ]; then echo "Usage: $0 botname command" diff --git a/examples/bashbot.cron b/examples/bashbot.cron index 5d9623f..0f0f83a 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$$ v1.0-0-g99217c4 +#### $$VERSION$$ v1.2-0-gc50499c SHELL=/bin/sh diff --git a/examples/calc.sh b/examples/calc.sh index 3102d43..ebcef45 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$$ v1.0-0-g99217c4 +#### $$VERSION$$ v1.2-0-gc50499c ###### # parameters diff --git a/examples/jsonDB-keyboard/mycommands.sh b/examples/jsonDB-keyboard/mycommands.sh index 9fe79e4..200b620 100644 --- a/examples/jsonDB-keyboard/mycommands.sh +++ b/examples/jsonDB-keyboard/mycommands.sh @@ -2,7 +2,7 @@ # files: mycommands.sh.dist # copy to mycommands.sh and add all your commands and functions here ... # -#### $$VERSION$$ v1.2-pre2-2-gef80aa5 +#### $$VERSION$$ v1.2-0-gc50499c # # shellcheck disable=SC2154,SC2034,SC1117,SC2221,SC2222 diff --git a/examples/notify.sh b/examples/notify.sh index 7f2f37a..9b311bc 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$$ v1.0-0-g99217c4 +#### $$VERSION$$ v1.2-0-gc50499c ###### # parameters diff --git a/examples/question.sh b/examples/question.sh index 9914b31..8efd6ff 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$$ v1.0-0-g99217c4 +#### $$VERSION$$ v1.2-0-gc50499c ###### # parameters diff --git a/examples/send-system-status/botacl b/examples/send-system-status/botacl index c13a16a..4665f3b 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$$ v1.0-0-g99217c4 +#### $$VERSION$$ v1.2-0-gc50499c # Format: # user:resource:chat diff --git a/examples/send-system-status/mycommands.sh b/examples/send-system-status/mycommands.sh index 0ed8d77..80bfae7 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$$ v1.2-dev-13-g2a5d47d +#### $$VERSION$$ v1.2-0-gc50499c # # shellcheck disable=SC2154 # shellcheck disable=SC2034 diff --git a/modules/aliases.sh b/modules/aliases.sh index ffa675f..82f80ef 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$$ v1.0-0-g99217c4 +#### $$VERSION$$ v1.2-0-gc50499c # # will be automatically sourced from bashbot diff --git a/modules/answerInline.sh b/modules/answerInline.sh index 49b7a26..496ee21 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$$ v1.0-0-g99217c4 +#### $$VERSION$$ v1.2-0-gc50499c # will be automatically sourced from bashbot diff --git a/modules/background.sh b/modules/background.sh index a2422bb..3d8ce17 100644 --- a/modules/background.sh +++ b/modules/background.sh @@ -6,7 +6,7 @@ # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # # shellcheck disable=SC1117 -#### $$VERSION$$ v1.2-pre2-2-gef80aa5 +#### $$VERSION$$ v1.2-0-gc50499c # will be automatically sourced from bashbot diff --git a/modules/chatMember.sh b/modules/chatMember.sh index 09f9e69..85a7e4c 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$$ v1.2-dev-14-g6ec00d4 +#### $$VERSION$$ v1.2-0-gc50499c # will be automatically sourced from bashbot diff --git a/modules/jsonDB.sh b/modules/jsonDB.sh index af6597d..1b9554e 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.0-0-g99217c4 +#### $$VERSION$$ v1.2-0-gc50499c # # source from commands.sh to use jsonDB functions # diff --git a/modules/sendMessage.sh b/modules/sendMessage.sh index d20457f..d0f46f3 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.2-pre2-2-gef80aa5 +#### $$VERSION$$ v1.2-0-gc50499c # will be automatically sourced from bashbot diff --git a/mycommands.sh b/mycommands.sh index e724487..7112314 100644 --- a/mycommands.sh +++ b/mycommands.sh @@ -9,7 +9,7 @@ # #### mycommands.clean # # shellcheck disable=SC1117 -#### $$VERSION$$ v1.2-pre2-2-gef80aa5 +#### $$VERSION$$ v1.2-0-gc50499c # # uncomment the following lines to overwrite info and help messages diff --git a/mycommands.sh.clean b/mycommands.sh.clean index cbe3531..4a65a8c 100644 --- a/mycommands.sh.clean +++ b/mycommands.sh.clean @@ -4,7 +4,7 @@ # files: mycommands.sh.clean # copy to mycommands.sh and add all your commands and functions here ... # -#### $$VERSION$$ v1.1-0-gc0eb399 +#### $$VERSION$$ v1.2-0-gc50499c # ########## diff --git a/scripts/interactive.sh.clean b/scripts/interactive.sh.clean index 4fdc70f..966218e 100755 --- a/scripts/interactive.sh.clean +++ b/scripts/interactive.sh.clean @@ -6,7 +6,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.0-0-g99217c4 +#### $$VERSION$$ v1.2-0-gc50499c ###### # parameters diff --git a/test/ADD-test-new.sh b/test/ADD-test-new.sh index 8e56210..eff7211 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$$ v1.0-0-g99217c4 +#### $$VERSION$$ v1.2-0-gc50499c # 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 a58a56c..6cc83e5 100644 --- a/test/ALL-tests.inc.sh +++ b/test/ALL-tests.inc.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v1.0-0-g99217c4 +#### $$VERSION$$ v1.2-0-gc50499c # common variables export TESTME DIRME TESTDIR LOGFILE REFDIR TESTNAME diff --git a/test/a-commit-test.sh b/test/a-commit-test.sh index 23232ce..de7ae20 100755 --- a/test/a-commit-test.sh +++ b/test/a-commit-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v1.0-0-g99217c4 +#### $$VERSION$$ v1.2-0-gc50499c ../dev/hooks/pre-commit.sh diff --git a/test/b-example-test.sh b/test/b-example-test.sh index 865e4de..e9507dd 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$$ v1.0-0-g99217c4 +#### $$VERSION$$ v1.2-0-gc50499c # 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 bc3500f..ae80385 100755 --- a/test/c-init-test.sh +++ b/test/c-init-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v1.0-0-g99217c4 +#### $$VERSION$$ v1.2-0-gc50499c # 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 2d99f70..db1c00a 100755 --- a/test/d-JSON.sh-test.sh +++ b/test/d-JSON.sh-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v1.2-dev-13-g2a5d47d +#### $$VERSION$$ v1.2-0-gc50499c # 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 4040435..ed02b3d 100755 --- a/test/d-process_inline-test.sh +++ b/test/d-process_inline-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v1.0-0-g99217c4 +#### $$VERSION$$ v1.2-0-gc50499c # 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 644cb94..a93e501 100755 --- a/test/d-process_message-test.sh +++ b/test/d-process_message-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v1.0-0-g99217c4 +#### $$VERSION$$ v1.2-0-gc50499c # 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 2ed52ad..98b706a 100755 --- a/test/d-send_message-test.sh +++ b/test/d-send_message-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v1.0-0-g99217c4 +#### $$VERSION$$ v1.2-0-gc50499c # 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 4046cfa..0a472a0 100755 --- a/test/d-user_is-test.sh +++ b/test/d-user_is-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v1.0-0-g99217c4 +#### $$VERSION$$ v1.2-0-gc50499c # 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 5247955..5897f6a 100755 --- a/test/e-env-test.sh +++ b/test/e-env-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v1.0-0-g99217c4 +#### $$VERSION$$ v1.2-0-gc50499c # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh From 1b8a1d4253b215355cd970d6b71c0b11801473dd Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Thu, 3 Dec 2020 14:07:39 +0100 Subject: [PATCH 011/100] get/save botid, new function bot_is_admin --- bashbot.rc | 7 +++---- bashbot.sh | 12 ++++++++++-- dev/hooks/pre-commit.sh | 4 ++-- doc/6_reference.md | 19 ++++++++++++++++--- modules/chatMember.sh | 12 +++++++++++- mycommands.sh | 4 ++-- 6 files changed, 44 insertions(+), 14 deletions(-) diff --git a/bashbot.rc b/bashbot.rc index 693880e..c27fb1b 100755 --- a/bashbot.rc +++ b/bashbot.rc @@ -1,12 +1,11 @@ #!/bin/sh # description: Start or stop telegram-bash-bot # -# example service script to run bashbot in background -# may or may not work on your system +# example service script to run bashbot in background as specified user # -# tested on: ubuntu, opensuse +# tested on: ubuntu, opensuse, debian # -#### $$VERSION$$ v1.2-0-gc50499c +#### $$VERSION$$ v1.2-1-gd30a700 # shellcheck disable=SC2009 # shellcheck disable=SC2181 diff --git a/bashbot.sh b/bashbot.sh index dd7ea9c..d17b5b9 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -11,7 +11,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.2-0-gc50499c +#### $$VERSION$$ v1.2-1-gd30a700 # # Exit Codes: # - 0 success (hopefully) @@ -607,7 +607,15 @@ title2Json(){ # get bot name getBotName() { - getJson "$ME_URL" | "${JSONSHFILE}" -b -n 2>/dev/null | JsonGetString '"result","username"' + local response + declare -A BOTARRAY + response="$(getJson "$ME_URL" | "${JSONSHFILE}" -b -n 2>/dev/null)" + Json2Array 'BOTARRAY' <<<"${response}" + [[ -z "${response}" || -z "${BOTARRAY["result","username"]}" ]] && return 1 + # save botname and id + setConfigKey "botname" "${BOTARRAY["result","username"]}" + setConfigKey "botid" "${BOTARRAY["result","id"]}" + echo "${BOTARRAY["result","username"]}" } # pure bash implementation, done by KayM (@gnadelwartz) diff --git a/dev/hooks/pre-commit.sh b/dev/hooks/pre-commit.sh index e1bf28f..fb8d8a9 100755 --- a/dev/hooks/pre-commit.sh +++ b/dev/hooks/pre-commit.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v1.2-0-gc50499c +#### $$VERSION$$ v1.2-1-gd30a700 ############ # NOTE: you MUST run install-hooks.sh again when updating this file! @@ -30,7 +30,7 @@ fi # run shellcheck before commit set +f -FILES="$(find ./* -name '*.sh' | grep -v 'DIST\/' | grep -v 'STANDALONE\/')" +FILES="$(find ./* -name '*.sh' | grep -v -e 'DIST\/' -e 'STANDALONE\/' -e 'JSON.sh')" set -f FILES="${FILES} $(sed '/^#/d' <"dev/shellcheck.files")" if [ "$FILES" != "" ]; then diff --git a/doc/6_reference.md b/doc/6_reference.md index 3947dcc..1717c76 100644 --- a/doc/6_reference.md +++ b/doc/6_reference.md @@ -244,6 +244,19 @@ fi The following functions are bashbot only and not part of the Telegram API. +##### bot_is_admin +Return true (0) if bot is admin or creator of given chat. + +*usage:* bot_is_admin "${CHAT[ID]}" + + +*example:* +```bash +if bot_is_admin "${CHAT[ID]}"; then + send_markdown_message "${CHAT[ID]}" "*I'm admin...*" +fi +``` + ##### user_is_botadmin Return true (0) if user is admin of bot, user id if botadmin is read from file './botadmin'. @@ -253,7 +266,7 @@ Return true (0) if user is admin of bot, user id if botadmin is read from file ' *example:* ```bash - _is_botadmin && send_markdown_message "${CHAT[ID]}" "You are *BOTADMIN*." +user_is_botadmin "${CHAT[ID]}" && send_markdown_message "${CHAT[ID]}" "You are *BOTADMIN*." ``` ##### user_is_creator @@ -272,7 +285,7 @@ Return true (0) if user is admin or creator of given chat. *example:* ```bash -if _is_admin ; then +if user_is_admin "${CHAT[ID]}" ; then send_markdown_message "${CHAT[ID]}" "*LEAVING CHAT...*" leave_chat "${CHAT[ID]}" fi @@ -1049,5 +1062,5 @@ The name of your bot is available as bash variable "$ME", there is no need to ca #### [Prev Best Practice](5_practice.md) #### [Next Notes for Developers](7_develop.md) -#### $$VERSION$$ v1.2-0-gc50499c +#### $$VERSION$$ v1.2-1-gd30a700 diff --git a/modules/chatMember.sh b/modules/chatMember.sh index 85a7e4c..06a6306 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$$ v1.2-0-gc50499c +#### $$VERSION$$ v1.2-1-gd30a700 # will be automatically sourced from bashbot @@ -18,6 +18,7 @@ UNBAN_URL=$URL'/unbanChatMember' GETMEMBER_URL=$URL'/getChatMember' # usage: status="$(get_chat_member_status "chat" "user")" +# $1 chat # $2 user get_chat_member_status() { sendJson "$1" '"user_id":'"$2"'' "$GETMEMBER_URL" # shellcheck disable=SC2154 @@ -42,6 +43,13 @@ user_is_creator() { return 1 } +# $1 chat +bot_is_admin() { + [ "${2:-+}" ] && return 0 + user_is_admin "$2" "$(getConfigKey "botid")" +} + +# $1 chat # $2 user user_is_admin() { [ "${1:--}" == "${2:-+}" ] && return 0 user_is_botadmin "$2" && return 0 @@ -50,6 +58,7 @@ user_is_admin() { return 1 } +# $1 user user_is_botadmin() { local admin; admin="$(getConfigKey "botadmin")"; [ -z "${admin}" ] && return 1 [[ "${admin}" == "${1}" || "${admin}" == "${2}" ]] && return 0 @@ -58,6 +67,7 @@ user_is_botadmin() { return 1 } +# $1 user # $2 key # $3 chat user_is_allowed() { [ -z "$1" ] && return 1 # user can do everything diff --git a/mycommands.sh b/mycommands.sh index 7112314..236e717 100644 --- a/mycommands.sh +++ b/mycommands.sh @@ -9,7 +9,7 @@ # #### mycommands.clean # # shellcheck disable=SC1117 -#### $$VERSION$$ v1.2-0-gc50499c +#### $$VERSION$$ v1.2-1-gd30a700 # # uncomment the following lines to overwrite info and help messages @@ -149,7 +149,7 @@ else MESSAGE="${MESSAGE#/* }" ;; '/_new_chat_member'*) - if [[ -n "${WELCOME_NEWMEMBER}" && "${NEWMEMBER[ISBOT]}" != "true" ]]; then + if [[ -n "${WELCOME_NEWMEMBER}" && "${NEWMEMBER[ISBOT]}" != "true" ]] && bot_is_admin "${CHAT[ID]}"; then send_normal_message "${CHAT[ID]}"\ "${WELCOME_MSG} ${NEWMEMBER[FIRST_NAME]} ${NEWMEMBER[LAST_NAME]} (@${NEWMEMBER[USERNAME]})" MYSENTID="${BOTSENT[ID]}" From b0281f1f325c0adb9fcafe500fa917f87006dd16 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Thu, 3 Dec 2020 14:25:32 +0100 Subject: [PATCH 012/100] fix bot_is_admin --- modules/chatMember.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/modules/chatMember.sh b/modules/chatMember.sh index 06a6306..e6f99f5 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$$ v1.2-1-gd30a700 +#### $$VERSION$$ v1.2-2-g1b8a1d4 # will be automatically sourced from bashbot @@ -45,12 +45,12 @@ user_is_creator() { # $1 chat bot_is_admin() { - [ "${2:-+}" ] && return 0 - user_is_admin "$2" "$(getConfigKey "botid")" + user_is_admin "$1" "$(getConfigKey "botid")" } # $1 chat # $2 user user_is_admin() { + [[ -z "$1" || -z "$2" ]] && return 1 [ "${1:--}" == "${2:-+}" ] && return 0 user_is_botadmin "$2" && return 0 local me; me="$(get_chat_member_status "$1" "$2")" @@ -60,6 +60,7 @@ user_is_admin() { # $1 user user_is_botadmin() { + [ -z "$1" ] && return 1 local admin; admin="$(getConfigKey "botadmin")"; [ -z "${admin}" ] && return 1 [[ "${admin}" == "${1}" || "${admin}" == "${2}" ]] && return 0 #[[ "${admin}" = "@*" ]] && [[ "${admin}" = "${2}" ]] && return 0 From 40106ee163b324625e0a4d891059776a95136187 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Thu, 3 Dec 2020 14:52:35 +0100 Subject: [PATCH 013/100] offer to check bottoken online on first init --- addons/antiFlood.jssh | 0 bashbot.rc | 4 ++-- bashbot.sh | 11 ++++++++++- 3 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 addons/antiFlood.jssh diff --git a/addons/antiFlood.jssh b/addons/antiFlood.jssh new file mode 100644 index 0000000..e69de29 diff --git a/bashbot.rc b/bashbot.rc index c27fb1b..10cd4e6 100755 --- a/bashbot.rc +++ b/bashbot.rc @@ -5,7 +5,7 @@ # # tested on: ubuntu, opensuse, debian # -#### $$VERSION$$ v1.2-1-gd30a700 +#### $$VERSION$$ v1.2-3-gb0281f1 # shellcheck disable=SC2009 # shellcheck disable=SC2181 @@ -27,7 +27,7 @@ runcmd="echo Dry run:" # not activated until you edit lines below # Configuration Section # edit the next line to fit the user you want to run bashbot, e.g. nobody: -runas="nobody" +runas="root" # uncomment one of the example lines to fit your system # runcmd="su $runas -s /bin/bash -c " # runasuser with *su* diff --git a/bashbot.sh b/bashbot.sh index d17b5b9..7b7858c 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -11,7 +11,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.2-1-gd30a700 +#### $$VERSION$$ v1.2-3-gb0281f1 # # Exit Codes: # - 0 success (hopefully) @@ -1093,6 +1093,15 @@ bot_init() { find . -name '*.jssh*' -exec chmod u+w \{\} + echo "Done." fi + # ask to check bottoken online + if [ -z "$(getConfigKey "botid")" ]; then + echo -e "Seems to be your first init. Should I verify your bot token online? (y/N) N\b\c" + read -r ANSWER + if [[ "${ANSWER}" =~ ^[Yy] ]]; then + echo -e "${GREEN}Contacting telegram to verify your bot token ...${NC}" + $0 botname + fi + fi # check if botconf if seems valid echo -e "${GREEN}This is your bot config:${NC}" sed 's/^/\t/' "${BOTCONFIG}.jssh" | grep -vF '["bot_config_key"]' From 658fac607ce5fc90320b5f29154bc47491308620 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Thu, 3 Dec 2020 14:54:45 +0100 Subject: [PATCH 014/100] fix .jssh files in gitignore --- .gitignore | 2 +- addons/antiFlood.jssh | 0 2 files changed, 1 insertion(+), 1 deletion(-) delete mode 100644 addons/antiFlood.jssh diff --git a/.gitignore b/.gitignore index 9575134..1e2b176 100644 --- a/.gitignore +++ b/.gitignore @@ -6,7 +6,7 @@ /botconf* /botacl* /botown* -ˆ.jssh +*.jssh *.save *.log *.swp diff --git a/addons/antiFlood.jssh b/addons/antiFlood.jssh deleted file mode 100644 index e69de29..0000000 From 59c51afb523abb6b9278ad335ecab527913937a3 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Thu, 3 Dec 2020 14:58:32 +0100 Subject: [PATCH 015/100] default to nobody --- bashbot.rc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bashbot.rc b/bashbot.rc index 10cd4e6..2555777 100755 --- a/bashbot.rc +++ b/bashbot.rc @@ -5,7 +5,7 @@ # # tested on: ubuntu, opensuse, debian # -#### $$VERSION$$ v1.2-3-gb0281f1 +#### $$VERSION$$ v1.2-4-g40106ee # shellcheck disable=SC2009 # shellcheck disable=SC2181 @@ -27,7 +27,7 @@ runcmd="echo Dry run:" # not activated until you edit lines below # Configuration Section # edit the next line to fit the user you want to run bashbot, e.g. nobody: -runas="root" +runas="nobody" # uncomment one of the example lines to fit your system # runcmd="su $runas -s /bin/bash -c " # runasuser with *su* From d6e1c222f7aafd636d2dae0e549c81ea7ceb0492 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Thu, 3 Dec 2020 20:43:20 +0100 Subject: [PATCH 016/100] optimize getBotName --- bashbot.rc | 2 +- bashbot.sh | 10 ++++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/bashbot.rc b/bashbot.rc index 2555777..9ee685a 100755 --- a/bashbot.rc +++ b/bashbot.rc @@ -5,7 +5,7 @@ # # tested on: ubuntu, opensuse, debian # -#### $$VERSION$$ v1.2-4-g40106ee +#### $$VERSION$$ v1.2-5-g658fac6 # shellcheck disable=SC2009 # shellcheck disable=SC2181 diff --git a/bashbot.sh b/bashbot.sh index 7b7858c..624309e 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -11,7 +11,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.2-3-gb0281f1 +#### $$VERSION$$ v1.2-6-g59c51af # # Exit Codes: # - 0 success (hopefully) @@ -605,13 +605,11 @@ title2Json(){ printf '%s\n' "${title}${caption}${desc}${markup}${keyboard}" } -# get bot name +# get bot name and id from telegram getBotName() { - local response declare -A BOTARRAY - response="$(getJson "$ME_URL" | "${JSONSHFILE}" -b -n 2>/dev/null)" - Json2Array 'BOTARRAY' <<<"${response}" - [[ -z "${response}" || -z "${BOTARRAY["result","username"]}" ]] && return 1 + Json2Array 'BOTARRAY' <<<"$(getJson "$ME_URL" | "${JSONSHFILE}" -b -n 2>/dev/null)" + [ -z "${BOTARRAY["result","username"]}" ] && return 1 # save botname and id setConfigKey "botname" "${BOTARRAY["result","username"]}" setConfigKey "botid" "${BOTARRAY["result","id"]}" From 04ec4baab2d8453d64f39b45ba0f534af59011be Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Fri, 4 Dec 2020 21:35:21 +0100 Subject: [PATCH 017/100] fix test with existing config --- bashbot.rc | 2 +- dev/all-tests.sh | 5 ++++- test/c-init-test.sh | 3 ++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/bashbot.rc b/bashbot.rc index 9ee685a..d4719dd 100755 --- a/bashbot.rc +++ b/bashbot.rc @@ -5,7 +5,7 @@ # # tested on: ubuntu, opensuse, debian # -#### $$VERSION$$ v1.2-5-g658fac6 +#### $$VERSION$$ v1.2-7-gd6e1c22 # shellcheck disable=SC2009 # shellcheck disable=SC2181 diff --git a/dev/all-tests.sh b/dev/all-tests.sh index 91e45f4..b89edd8 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$$ v1.2-0-gc50499c +#### $$VERSION$$ v1.2-7-gd6e1c22 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script @@ -18,6 +18,9 @@ mkdir "${TESTENV}" cp -r ./* "${TESTENV}" cd "test" || exit 1 +# delete possible config +rm "${TESTENV}/botconfig.jssh" "${TESTENV}/botacl" + #set -e fail=0 tests=0 diff --git a/test/c-init-test.sh b/test/c-init-test.sh index ae80385..6456d59 100755 --- a/test/c-init-test.sh +++ b/test/c-init-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v1.2-0-gc50499c +#### $$VERSION$$ v1.2-7-gd6e1c22 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh @@ -14,6 +14,7 @@ set -e $TESTTOKEN nobody botadmin + EOF echo "${SUCCESS}" From 62cab32da563eb86bffb70b7957243f96645e353 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sat, 5 Dec 2020 14:11:21 +0100 Subject: [PATCH 018/100] bottoken starts with bot id --- bashbot.sh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index 624309e..56bde6f 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -11,7 +11,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.2-6-g59c51af +#### $$VERSION$$ v1.2-8-g04ec4ba # # Exit Codes: # - 0 success (hopefully) @@ -264,20 +264,22 @@ if [ -z "${BOTTOKEN}" ]; then fi fi - # BOTTOKEN format checks if ! check_token "${BOTTOKEN}"; then echo -e "${ORANGE}Warning: your bottoken may incorrect. it should have the following format:${NC}" echo -e "${GREY}123456789${RED}:${GREY}Aa-Zz_0Aa-Zz_1Aa-Zz_2Aa-Zz_3Aa-Zz_4${ORANGE} => ${NC}\c" echo -e "${GREY}8-10 digits${RED}:${GREY}35 alphanumeric characters + '_-'${NC}" echo -e "${ORANGE}Your current token is: '${GREY}^$(cat -ve <<<"${BOTTOKEN//:/${RED}:${GREY}}")${ORANGE}'${NC}" - [[ ! "${BOTTOKEN}" =~ ^[0-9]{8,10}: ]] &&\ + if [[ ! "${BOTTOKEN}" =~ ^[0-9]{8,10}: ]]; then echo -e "${ORANGE}Possible problem in the digits part, len is $(($(wc -c <<<"${BOTTOKEN%:*}")-1))${NC}" + [ -n "$(getConfigKey "botid")" ] && echo -e "${GREY}Did you mean: \"${NC}$(getConfigKey "botid")${GREY}\" ?${NC}" + fi [[ ! "${BOTTOKEN}" =~ :[a-zA-Z0-9_-]{35}$ ]] &&\ echo -e "${ORANGE}Possible problem in the characters part, len is $(($(wc -c <<<"${BOTTOKEN#*:}")-1))${NC}" fi + ################## # here we start with the real stuff BASHBOT_RETRY="" # retry by default From 10c104d471ad0cea9ef35f33407172d081fd505e Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Mon, 7 Dec 2020 15:50:56 +0100 Subject: [PATCH 019/100] check for locale C --- bashbot.sh | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index 56bde6f..be9dcc7 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -11,7 +11,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.2-8-g04ec4ba +#### $$VERSION$$ v1.2-9-g62cab32 # # Exit Codes: # - 0 success (hopefully) @@ -29,7 +29,7 @@ # emmbeded system may claim bash but it is not # check for bash like ARRAY handlung if ! (unset a; set -A a a; eval "a=(a b)"; eval '[ -n "${a[1]}" ]'; ) > /dev/null 2>&1; then - echo "iError: Current shell does not support ARRAY's, may be busbox ash shell. pls install a real bash!"; + echo "Error: Current shell does not support ARRAY's, may be busbox ash shell. pls install a real bash!"; exit 10 fi @@ -48,25 +48,26 @@ if [ "$(echo -e "\u1111")" == "\u1111" ]; then echo -e "${ORANGE}Warning: Unicode '\uxxxx' seems not supported, install a more current bash.${NC}" fi + # some important helper functions # returns true if command exist _exists() { - [ "$(LC_ALL=C type -t "${1}")" = "file" ] + [ "$({ LC_ALL=C type -t "${1}"; } 2>/dev/null)" = "file" ] } # execute function if exists _exec_if_function() { - [ "$(LC_ALL=C type -t "${1}")" != "function" ] && return 1 + [ "$({ LC_ALL=C type -t "${1}"; } 2>/dev/null)" != "function" ] && return 1 "$@" } # returns true if function exist _is_function() { - [ "$(LC_ALL=C type -t "${1}")" = "function" ] + [ "$({ LC_ALL=C type -t "${1}"; } 2>/dev/null)" = "function" ] } # round $1 in international notation! , returns float with $2 decimal digits # if $2 is not given or is not a positive number zero is assumed _round_float() { local digit="${2}"; [[ "${2}" =~ ^[0-9]+$ ]] || digit="0" - LC_ALL=C printf "%.${digit}f" "${1}" + { LC_ALL=C printf "%.${digit}f" "${1}"; } 2>/dev/null } setConfigKey() { [[ "$1" =~ ^[-a-zA-Z0-9,._]+$ ]] || return 3 @@ -107,6 +108,11 @@ debug_checks(){ _exec_if_function my_debug_checks "${DATE}" "${WHERE}" "$*" } >>"${DEBUGLOG}" +# some linux, e.g. manajro seems not to have C locale activated by default +if _exists locale && [ "$(locale -a | grep -c -e "^C$" -e "^C.utf8$")" -lt 2 ]; then + echo -e "${ORANGE}Warning: locale ${NC}${GREY}C${NC}${ORANGE} and/or ${NC}${GREY}C.utf8${NC}${ORANGE} seems missing, use \"${NC}${GREY}locale -a${NC}${ORANGE}\" to show what locales are installed on your system.${NC}" +fi + # get location and name of bashbot.sh SCRIPT="$0" REALME="${BASH_SOURCE[0]}" From 5db2ef6f3071861466a0de9511a4c7965373ba52 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Mon, 7 Dec 2020 18:29:37 +0100 Subject: [PATCH 020/100] add BOTSENT[ID] to documentation --- doc/2_usage.md | 13 ++++++++++++- doc/3_advanced.md | 5 +++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/doc/2_usage.md b/doc/2_usage.md index d4ed03c..561f8fd 100644 --- a/doc/2_usage.md +++ b/doc/2_usage.md @@ -205,6 +205,17 @@ they contain the following variables only: * ```${iQUERY[FIRST_NAME]}```: User's first name * ```${iQUERY[LAST_NAME]}```: User's last name + +### Send Message Results + +BOTSWEND is set on every send_xxx action and only valid until next send action. For more on message results see. +[Advanced Usage](3_advanced.md) + +* ```$BOTSENT```: This array contains the parsed results from the last transmission to telegram. + * ```${BOTSENT[OK]}```: contains the string ```true```: after a successful transmission + * ```${BOTSENT[ID]}```: Message ID of sent message, image, file etc., if OK is true + + ## Usage of bashbot functions #### sending messages @@ -283,5 +294,5 @@ send_action "${CHAT[ID]}" "action" #### [Prev Create Bot](1_firstbot.md) #### [Next Advanced Usage](3_advanced.md) -#### $$VERSION$$ v1.2-0-gc50499c +#### $$VERSION$$ v1.2-10-g10c104d diff --git a/doc/3_advanced.md b/doc/3_advanced.md index a499036..3876730 100644 --- a/doc/3_advanced.md +++ b/doc/3_advanced.md @@ -227,7 +227,7 @@ answer_inline_query "${iQUERY[ID]}" "cached_sticker" "identifier for the sticker See also [answer_inline_multi, answer_inline_compose](6_reference.md#answer_inline_multi) and [mycommands.sh](../mycommands.sh) for more information. -### Handle send message errors +### Send message results Our examples usually do not care about errors happening while sending a message, this is OK as long your bot does not send an massive aoumnt of messages. By default bashbot detects if a message is not sent and try to recover when possible, @@ -244,6 +244,7 @@ every send action will overwrite them! * ```$BOTSENT```: This array contains the parsed results from the last transmission to telegram. * ```${BOTSENT[OK]}```: contains the string ```true```: after a successful transmission + * ```${BOTSENT[ID]}```: Message ID if OK is true * ```${BOTSENT[ERROR]}```: Error code if an error occurred * ```${BOTSENT[DESC]}```: Description text for error * ```${BOTSENT[RETRY]}```: Seconds to wait if telegram requests throtteling. @@ -297,5 +298,5 @@ Note: If you disable automatic retry, se above, you disable also connection prob #### [Prev Getting started](2_usage.md) #### [Next Expert Use](4_expert.md) -#### $$VERSION$$ v1.2-0-gc50499c +#### $$VERSION$$ v1.2-10-g10c104d From 336f00bb3cc5cb7a6e78e4acc4be47a091500046 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Mon, 7 Dec 2020 18:34:23 +0100 Subject: [PATCH 021/100] fix BOTSENT spelling --- doc/2_usage.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/2_usage.md b/doc/2_usage.md index 561f8fd..ad43bd2 100644 --- a/doc/2_usage.md +++ b/doc/2_usage.md @@ -208,7 +208,7 @@ they contain the following variables only: ### Send Message Results -BOTSWEND is set on every send_xxx action and only valid until next send action. For more on message results see. +BOTSENT is set on every send_xxx action and only valid until next send action. For more on message results see. [Advanced Usage](3_advanced.md) * ```$BOTSENT```: This array contains the parsed results from the last transmission to telegram. @@ -294,5 +294,5 @@ send_action "${CHAT[ID]}" "action" #### [Prev Create Bot](1_firstbot.md) #### [Next Advanced Usage](3_advanced.md) -#### $$VERSION$$ v1.2-10-g10c104d +#### $$VERSION$$ v1.2-11-g5db2ef6 From b9cfd4b5e8e35670451dd631b650f097c3b38af5 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sun, 13 Dec 2020 08:53:29 +0100 Subject: [PATCH 022/100] process service messages in groups only --- README.html | 209 +++++++++++++++++++++++++++++++++++++++++----------- bashbot.sh | 24 +++--- 2 files changed, 181 insertions(+), 52 deletions(-) diff --git a/README.html b/README.html index 7c538ee..ec005d3 100644 --- a/README.html +++ b/README.html @@ -6,6 +6,136 @@ Bashbot README