Skip to content

Commit d9d360e

Browse files
authored
Merge pull request #153 - Prepare Version 1.1
Prepare Version 1.1
2 parents 25a33b3 + b941d06 commit d9d360e

20 files changed

+211
-118
lines changed

README.html

Lines changed: 46 additions & 43 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,19 @@ Linted by [#ShellCheck](https://github.com/koalaman/shellcheck)
1414
Uses [JSON.sh](http://github.com/dominictarr/JSON.sh) and the magic of sed.
1515

1616
Even bashbot is written in bash, it depends on commands typically available in a Unix/Linux Environment.
17-
More concret on the common commands provided by recent versions of [coreutils](https://en.wikipedia.org/wiki/List_of_GNU_Core_Utilities_commands), [busybox](https://en.wikipedia.org/wiki/BusyBox#Commands) or [toybox](https://landley.net/toybox/help.html), see [Developer Notes](doc/7_develop.md#common-commands)
17+
More concrete on the common commands provided by recent versions of [coreutils](https://en.wikipedia.org/wiki/List_of_GNU_Core_Utilities_commands), [busybox](https://en.wikipedia.org/wiki/BusyBox#Commands) or [toybox](https://landley.net/toybox/help.html), see [Developer Notes](doc/7_develop.md#common-commands)
1818

19-
*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](doc/0_install.md)
19+
**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](doc/0_install.md)
2020

21+
**Note for embedded systems:** busybox or toybox ONLY is not sufficient, you need a to install a "real" bash, see also [Install Bashbot](doc/0_install.md)
2122

2223
Bashbot [Documentation](https://github.com/topkecleon/telegram-bot-bash) and [Downloads](https://github.com/topkecleon/telegram-bot-bash/releases) are available on www.github.com
2324

2425
## Documentation
25-
* [Introdution to Telegram Bots](https://core.telegram.org/bots)
26+
* [Introduction to Telegram Bots](https://core.telegram.org/bots)
2627
* [Install Bashbot](doc/0_install.md)
2728
* Install release
28-
* Install from githup
29+
* Install from github
2930
* Update Bashbot
3031
* Notes on Updates
3132
* [Get Bottoken from Botfather](doc/1_firstbot.md)
@@ -74,8 +75,11 @@ If you don't want to register for Telegram you should stop reading here ;-)
7475
After you're registered to Telegram send a message to [@botfather](https://telegram.me/botfather),
7576
[create a new Telegram Bot token](doc/1_firstbot.md) and write it down. You need the token to install the bot.
7677

77-
Now open a terminal and check if bash is installed: ```which bash && echo "bash installed!"```.
78-
If you get an error message bash is not installed.
78+
Now open a terminal and check if bash is installed:
79+
```
80+
which bash && echo "bash seems available..."
81+
```
82+
7983

8084
Create a new directory, change to it: ```mkdir tbb; cd tbb``` and download the latest '*.tar.gz' file from
8185
[https://github.com/topkecleon/telegram-bot-bash/releases](https://github.com/topkecleon/telegram-bot-bash/releases). This can be done with the commands:
@@ -99,7 +103,7 @@ You are Botadmin
99103
100104
/info
101105
102-
his is bashbot, the Telegram bot written entirely in bash.
106+
This is bashbot, the Telegram bot written entirely in bash.
103107
It features background tasks and interactive chats, and can serve as an interface for CLI programs.
104108
```
105109
For more Information on how to install, customize and use your new bot, read the [Documentation](#Documentation)
@@ -136,7 +140,7 @@ One of the most powerful features of unix shells is variable and command substit
136140
but as they are expanded in double quotes, this can lead to RCE and information disclosing bugs in complex scripts like bashbot.
137141
So it's more secure to escape or remove '$' in input from user, files or network.
138142

139-
A powerful tool to improve your scripts is ```shellcheck```. You can [use it online](https://www.shellcheck.net/) or [install shellcheck locally](https://github.com/koalaman/shellcheck#installing). Shellcheck is used extensive in bashbot development to ensure a high code quality, e.g. it's not allowed to push changes without passing all shellcheck tests.
143+
A powerful tool to improve your scripts is ```shellcheck```. You can [use it online](https://www.shellcheck.net/) or [install shellcheck locally](https://github.com/koalaman/shellcheck#installing). 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.
140144
In addition bashbot has a [test suite](doc/7_develop.md) to check if important functionality is working as expected.
141145

142146
### Use printf whenever possible
@@ -261,4 +265,4 @@ bashbotBlockRecover() {
261265

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

264-
#### $$VERSION$$ v1.0-0-g99217c4
268+
#### $$VERSION$$ v1.1-0-gc0eb399

README.txt

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,28 @@ Uses [JSON.sh](http://github.com/dominictarr/JSON.sh) and the magic of sed.
1919

2020
Even bashbot is written in bash, it depends on commands typically available in
2121
a Unix/Linux Environment.
22-
More concret on the common commands provided by recent versions of
22+
More concrete on the common commands provided by recent versions of
2323
[coreutils](https://en.wikipedia.org/wiki/List_of_GNU_Core_Utilities_commands),
2424
[busybox](https://en.wikipedia.org/wiki/BusyBox#Commands) or
2525
[toybox](https://landley.net/toybox/help.html), see [Developer
2626
Notes](doc/7_develop.md#common-commands)
2727

28-
*Note for MacOS and BSD Users:* As bashbot heavily uses modern bash and (gnu)
28+
**Note for MacOS and BSD Users:** As bashbot heavily uses modern bash and (gnu)
2929
grep/sed features, bashbot will not run without installing additional software,
3030
see [Install Bashbot](doc/0_install.md)
3131

32+
**Note for embedded systems:** busybox or toybox ONLY is not sufficient, you
33+
need a to install a "real" bash, see also [Install Bashbot](doc/0_install.md)
3234

3335
Bashbot [Documentation](https://github.com/topkecleon/telegram-bot-bash) and
3436
[Downloads](https://github.com/topkecleon/telegram-bot-bash/releases) are
3537
available on www.github.com
3638

3739
## Documentation
38-
* [Introdution to Telegram Bots](https://core.telegram.org/bots)
40+
* [Introduction to Telegram Bots](https://core.telegram.org/bots)
3941
* [Install Bashbot](doc/0_install.md)
4042
* Install release
41-
* Install from githup
43+
* Install from github
4244
* Update Bashbot
4345
* Notes on Updates
4446
* [Get Bottoken from Botfather](doc/1_firstbot.md)
@@ -93,9 +95,11 @@ After you're registered to Telegram send a message to
9395
[create a new Telegram Bot token](doc/1_firstbot.md) and write it down. You
9496
need the token to install the bot.
9597

96-
Now open a terminal and check if bash is installed: ```which bash && echo "bash
97-
installed!"```.
98-
If you get an error message bash is not installed.
98+
Now open a terminal and check if bash is installed:
99+
```
100+
which bash && echo "bash seems available..."
101+
```
102+
99103

100104
Create a new directory, change to it: ```mkdir tbb; cd tbb``` and download the
101105
latest '*.tar.gz' file from
@@ -126,7 +130,7 @@ You are Botadmin
126130

127131
/info
128132

129-
his is bashbot, the Telegram bot written entirely in bash.
133+
This is bashbot, the Telegram bot written entirely in bash.
130134
It features background tasks and interactive chats, and can serve as an
131135
interface for CLI programs.
132136
```
@@ -184,7 +188,7 @@ network.
184188
A powerful tool to improve your scripts is ```shellcheck```. You can [use it
185189
online](https://www.shellcheck.net/) or [install shellcheck
186190
locally](https://github.com/koalaman/shellcheck#installing). Shellcheck is used
187-
extensive in bashbot development to ensure a high code quality, e.g. it's not
191+
extensively in bashbot development to ensure a high code quality, e.g. it's not
188192
allowed to push changes without passing all shellcheck tests.
189193
In addition bashbot has a [test suite](doc/7_develop.md) to check if important
190194
functionality is working as expected.
@@ -351,4 +355,4 @@ wait
351355
If you feel that there's something missing or if you found a bug, feel free to
352356
submit a pull request!
353357

354-
#### $$VERSION$$ v1.0-0-g99217c4
358+
#### $$VERSION$$ v1.1-0-gc0eb399

bashbot.rc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/sh
22
# description: Start or stop telegram-bash-bot
33
#
4-
#### $$VERSION$$ v1.0-0-g99217c4
4+
#### $$VERSION$$ v1.1-0-gc0eb399
55
# shellcheck disable=SC2009
66
# shellcheck disable=SC2181
77

bashbot.sh

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# This file is public domain in the USA and all free countries.
1212
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
1313
#
14-
#### $$VERSION$$ v1.0-0-g99217c4
14+
#### $$VERSION$$ v1.1-0-gc0eb399
1515
#
1616
# Exit Codes:
1717
# - 0 success (hopefully)
@@ -22,8 +22,16 @@
2222
# - 5 cannot connect to telegram bot
2323
# - 6 mandatory module not found
2424
# - 6 can't get bottoken
25+
# - 10 not bash!
2526
# shellcheck disable=SC2140,SC2031,SC2120,SC1091
2627

28+
# emmbeded system may claim bash but it is not
29+
# check for bash like ARRAY handlung
30+
if ! (unset a; set -A a a; eval "a=(a b)"; eval '[ -n "${a[1]}" ]'; ) > /dev/null 2>&1; then
31+
echo "iError: Current shell does not support ARRAY's, may be busbox ash shell. pls install a real bash!";
32+
exit 10
33+
fi
34+
2735
# are we running in a terminal?
2836
if [ -t 1 ] && [ -n "$TERM" ]; then
2937
CLEAR='clear'
@@ -34,6 +42,11 @@ if [ -t 1 ] && [ -n "$TERM" ]; then
3442
NC='\e[0m'
3543
fi
3644

45+
# we need some bash 4+ features, check for old bash by feature
46+
if [ "$(echo -e "\u1111")" == "\u1111" ]; then
47+
echo -e "${ORANGE}Warning: Unicode '\uxxxx' seems not supported, install a more current bash.${NC}"
48+
fi
49+
3750
# some important helper functions
3851
# returns true if command exist
3952
_exists() {
@@ -389,7 +402,7 @@ if [ -z "${BASHBOT_WGET}" ] && _exists curl ; then
389402
local chat="";
390403
[ -n "${1}" ] && chat='"chat_id":'"${1}"','
391404
[ -n "${BASHBOTDEBUG}" ] &&\
392-
printf "%s: sendJson (curl) CHAT=%s JSON=%s URL=%s\n" "$(date)" "${1}" "${2:0:100}" "${3##*/}" >>"${DEBUGLOG}"
405+
printf "%s: sendJson (curl) CHAT=%s JSON=%s URL=%s\n" "$(date)" "${1}" "${2:0:100}" "${3##*/}" >>"${UPDATELOG}"
393406
# shellcheck disable=SC2086
394407
res="$("${BASHBOT_CURL}" -s -k ${BASHBOT_CURL_ARGS} -m "${TIMEOUT}"\
395408
-d '{'"${chat} $(iconv -f utf-8 -t utf-8 -c <<<$2)"'}' -X POST "${3}" \
@@ -402,7 +415,7 @@ if [ -z "${BASHBOT_WGET}" ] && _exists curl ; then
402415
[ "$#" -lt 4 ] && return
403416
if [ -n "$5" ]; then
404417
[ -n "${BASHBOTDEBUG}" ] &&\
405-
printf "%s: sendUpload CHAT=%s WHAT=%s FILE=%s CAPT=%s\n" "$(date)" "${1}" "${2}" "${3}" "${4}" >>"${DEBUGLOG}"
418+
printf "%s: sendUpload CHAT=%s WHAT=%s FILE=%s CAPT=%s\n" "$(date)" "${1}" "${2}" "${3}" "${4}" >>"${UPDATELOG}"
406419
# shellcheck disable=SC2086
407420
res="$("${BASHBOT_CURL}" -s -k ${BASHBOT_CURL_ARGS} "$4" -F "chat_id=$1"\
408421
-F "$2=@$3;${3##*/}" -F "caption=$5" | "${JSONSHFILE}" -s -b -n 2>/dev/null )"
@@ -426,7 +439,7 @@ else
426439
local chat="";
427440
[ -n "${1}" ] && chat='"chat_id":'"${1}"','
428441
[ -n "${BASHBOTDEBUG}" ] &&\
429-
printf "%s: sendJson (wget) CHAT=%s JSON=%s URL=%s\n" "$(date)" "${1}" "${2:0:100}" "${3##*/}" >>"${DEBUGLOG}"
442+
printf "%s: sendJson (wget) CHAT=%s JSON=%s URL=%s\n" "$(date)" "${1}" "${2:0:100}" "${3##*/}" >>"${UPDATELOG}"
430443
# shellcheck disable=SC2086
431444
res="$(wget --no-check-certificate -t 2 -T "${TIMEOUT}" ${BASHBOT_WGET_ARGS} -qO - --post-data='{'"${chat} $(iconv -f utf-8 -t utf-8 -c <<<$2)"'}' \
432445
--header='Content-Type:application/json' "${3}" | "${JSONSHFILE}" -s -b -n 2>/dev/null )"
@@ -633,8 +646,8 @@ process_client() {
633646
jssh_countKeyDB_async "${CHAT[ID]}" "${COUNTFILE}"
634647
}
635648

636-
declare -Ax BASBOT_EVENT_INLINE BASBOT_EVENT_MESSAGE BASHBOT_EVENT_CMD BASBOT_EVENT_REPLY BASBOT_EVENT_FORWARD BASHBOT_EVENT_SEND
637-
declare -Ax BASBOT_EVENT_CONTACT BASBOT_EVENT_LOCATION BASBOT_EVENT_FILE BASHBOT_EVENT_TEXT BASHBOT_EVENT_TIMER BASHBOT_BLOCKED
649+
declare -Ax BASHBOT_EVENT_INLINE BASHBOT_EVENT_MESSAGE BASHBOT_EVENT_CMD BASHBOT_EVENT_REPLY BASHBOT_EVENT_FORWARD BASHBOT_EVENT_SEND
650+
declare -Ax BASHBOT_EVENT_CONTACT BASHBOT_EVENT_LOCATION BASHBOT_EVENT_FILE BASHBOT_EVENT_TEXT BASHBOT_EVENT_TIMER BASHBOT_BLOCKED
638651

639652
start_timer(){
640653
# send alarm every ~60 s
@@ -1006,7 +1019,7 @@ bot_init() {
10061019
fi
10071020
#setup bashbot
10081021
[[ "${UID}" -eq "0" ]] && RUNUSER="nobody"
1009-
echo -n "Enter User to run basbot [$RUNUSER]: "
1022+
echo -n "Enter User to run bashbot [$RUNUSER]: "
10101023
read -r TOUSER
10111024
[ -z "$TOUSER" ] && TOUSER="$RUNUSER"
10121025
if ! id "$TOUSER" &>/dev/null; then
@@ -1145,6 +1158,8 @@ if [ -z "${SOURCE}" ]; then
11451158
sort -r "${BLOCKEDFILE}.jssh"
11461159
echo -e "${NC}\c"
11471160
fi
1161+
# show user created bot stats
1162+
_exec_if_function my_bashbot_stats "$@"
11481163
debug_checks "end $1" "$@"
11491164
exit
11501165
;;

commands.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@
99
# |_____/ \___/ |_| |_|\___/ \___) |_______)____|_|\___)_|
1010
#
1111
# this file *MUST* not be edited! place your config and commands in
12-
# the file "mycommnds.sh". a clean version is provided as "mycommands.clean"
12+
# the file "mycommands.sh". a clean version is provided as "mycommands.sh.clean"
1313
#
1414

1515
# This file is public domain in the USA and all free countries.
1616
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
1717
#
18-
#### $$VERSION$$ v1.0-0-g99217c4
18+
#### $$VERSION$$ v1.1-0-gc0eb399
1919
#
2020

21-
# adjust your language setting here, e.g.when run from other user or cron.
21+
# adjust your language setting here, e.g. when run from other user or cron.
2222
# https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment
2323
export 'LC_ALL=C.UTF-8'
2424
export 'LANG=C.UTF-8'
@@ -29,15 +29,15 @@ unset IFS
2929

3030
#-----------------------------
3131
# this file *MUST* not edited!
32-
# copy "mycommands.sh.dist" to "mycommnds.sh" and change the strings there
32+
# copy "mycommands.sh.dist" to "mycommands.sh" and change the strings there
3333
bashbot_info='This is bashbot, the Telegram bot written entirely in bash.
3434
It features background tasks and interactive chats, and can serve as an interface for CLI programs.
3535
It currently can send, receive and forward messages, custom keyboards, photos, audio, voice, documents, locations and video files.
3636
'
3737

3838
#-----------------------------
3939
# this file *MUST* not edited!
40-
# copy "mycommands.sh.dist" to "mycommnds.sh" and change the strings there
40+
# copy "mycommands.sh.dist" to "mycommands.sh" and change the strings there
4141
bashbot_help='Place your own commands and messages in mycommands.sh
4242
4343
*Available commands*:
@@ -65,7 +65,7 @@ fi
6565

6666
#----------------------------
6767
# this file *MUST* not edited!
68-
# copy "mycommands.sh.dist" to "mycommnds.sh" and change the values there
68+
# copy "mycommands.sh.dist" to "mycommands.sh" and change the values there
6969
# defaults to no inline and nonsense home dir
7070
export INLINE="0"
7171
export FILE_REGEX="${BASHBOT_ETC}/.*"
@@ -97,7 +97,7 @@ if [ -z "${1}" ] || [[ "${1}" == *"debug"* ]];then
9797
case "${MESSAGE}" in
9898
################################################
9999
# this file *MUST* not edited!
100-
# copy "mycommands.sh.dist" to "mycommnds.sh" and change the values and add your commands there
100+
# copy "mycommands.sh.dist" to "mycommands.sh" and change the values and add your commands there
101101
#
102102
# GLOBAL commands start here, edit messages only
103103
'/info'*)

dev/all-tests.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22
# this has to run once atfer git clone
33
# and every time we create new hooks
4-
#### $$VERSION$$ v1.0-0-g99217c4
4+
#### $$VERSION$$ v1.1-0-gc0eb399
55

66
# magic to ensure that we're always inside the root of our application,
77
# no matter from which directory we'll run script
@@ -26,7 +26,7 @@ passed=0
2626
#echo PLAN ${#all_tests}
2727
for test in $(find ./*-test.sh | sort -u) ;
2828
do
29-
[ "${test}" = "test/all-tests.sh" ] && continue
29+
[ "${test}" = "dev/all-tests.sh" ] && continue
3030
[ ! -x "${test}" ] && continue
3131
tests=$((tests+1))
3232
echo "TEST: ${test}"
@@ -56,6 +56,6 @@ fi
5656
echo -e "${passed} / ${tests}\\n"
5757
[ -d "${TESTENV}" ] && echo "Logfiles from run are in ${TESTENV}"
5858

59-
ls -ld /tmp/bashbot.test* 2>/dev/null && echo "Don not forget to deleted bashbot test files in /tmp!!"
59+
ls -ld /tmp/bashbot.test* 2>/dev/null && echo "Do not forget to delete bashbot test files in /tmp!!"
6060

6161
exit ${exitcode}

dev/git-add.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#
44
# works together with git pre-push.sh and ADD all changed files since last push
55

6-
#### $$VERSION$$ v1.0-0-g99217c4
6+
#### $$VERSION$$ v1.1-0-gc0eb399
77

88
# magic to ensure that we're always inside the root of our application,
99
# no matter from which directory we'll run script

dev/hooks/pre-commit.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env bash
2-
#### $$VERSION$$ v1.0-0-g99217c4
2+
#### $$VERSION$$ v1.1-0-gc0eb399
33

44
############
55
# NOTE: you MUST run install-hooks.sh again when updating this file!
@@ -65,7 +65,7 @@ else
6565
exit 1
6666
fi
6767

68-
if which codespell &>/dev/null; then
68+
if command -v codespell &>/dev/null; then
6969
echo "Running codespell"
7070
echo "............................"
7171
codespell -B 1 --skip="*.log,*.html,*.txt,.git*,jsonDB-keyboard" -L "ba"

dev/hooks/pre-push.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env bash
2-
#### $$VERSION$$ v1.0-0-g99217c4
2+
#### $$VERSION$$ v1.1-0-gc0eb399
33

44
############
55
# NOTE: you MUST run install-hooks.sh again when updating this file!

0 commit comments

Comments
 (0)