Skip to content

Commit

Permalink
Merge pull request #153 - Prepare Version 1.1
Browse files Browse the repository at this point in the history
Prepare Version 1.1
  • Loading branch information
gnadelwartz authored Sep 23, 2020
2 parents 25a33b3 + b941d06 commit d9d360e
Show file tree
Hide file tree
Showing 20 changed files with 211 additions and 118 deletions.
89 changes: 46 additions & 43 deletions README.html

Large diffs are not rendered by default.

22 changes: 13 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,19 @@ Linted by [#ShellCheck](https://github.com/koalaman/shellcheck)
Uses [JSON.sh](http://github.com/dominictarr/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 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)
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)

*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)
**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)

**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)

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

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

Now open a terminal and check if bash is installed: ```which bash && echo "bash installed!"```.
If you get an error message bash is not installed.
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](https://github.com/topkecleon/telegram-bot-bash/releases). This can be done with the commands:
Expand All @@ -99,7 +103,7 @@ You are Botadmin
/info
his is bashbot, the Telegram bot written entirely in bash.
This is bashbot, the Telegram bot written entirely in bash.
It features background tasks and interactive chats, and can serve as an interface for CLI programs.
```
For more Information on how to install, customize and use your new bot, read the [Documentation](#Documentation)
Expand Down Expand Up @@ -136,7 +140,7 @@ One of the most powerful features of unix shells is variable and command substit
but as they are expanded in double quotes, this can lead to RCE and information disclosing bugs in complex scripts like bashbot.
So it's more secure to escape or remove '$' in input from user, files or network.

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.
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.
In addition bashbot has a [test suite](doc/7_develop.md) to check if important functionality is working as expected.

### Use printf whenever possible
Expand Down Expand Up @@ -261,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.0-0-g99217c4
#### $$VERSION$$ v1.1-0-gc0eb399
24 changes: 14 additions & 10 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,28 @@ Uses [JSON.sh](http://github.com/dominictarr/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 concret on the common commands provided by recent versions of
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)

*Note for MacOS and BSD Users:* As bashbot heavily uses modern bash and (gnu)
**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)

**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)

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

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

Now open a terminal and check if bash is installed: ```which bash && echo "bash
installed!"```.
If you get an error message bash is not installed.
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
Expand Down Expand Up @@ -126,7 +130,7 @@ You are Botadmin

/info

his is bashbot, the Telegram bot written entirely in bash.
This is bashbot, the Telegram bot written entirely in bash.
It features background tasks and interactive chats, and can serve as an
interface for CLI programs.
```
Expand Down Expand Up @@ -184,7 +188,7 @@ network.
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
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](doc/7_develop.md) to check if important
functionality is working as expected.
Expand Down Expand Up @@ -351,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.0-0-g99217c4
#### $$VERSION$$ v1.1-0-gc0eb399
2 changes: 1 addition & 1 deletion bashbot.rc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh
# description: Start or stop telegram-bash-bot
#
#### $$VERSION$$ v1.0-0-g99217c4
#### $$VERSION$$ v1.1-0-gc0eb399
# shellcheck disable=SC2009
# shellcheck disable=SC2181

Expand Down
29 changes: 22 additions & 7 deletions bashbot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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.0-0-g99217c4
#### $$VERSION$$ v1.1-0-gc0eb399
#
# Exit Codes:
# - 0 success (hopefully)
Expand All @@ -22,8 +22,16 @@
# - 5 cannot connect to telegram bot
# - 6 mandatory module not found
# - 6 can't get bottoken
# - 10 not bash!
# shellcheck disable=SC2140,SC2031,SC2120,SC1091

# 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!";
exit 10
fi

# are we running in a terminal?
if [ -t 1 ] && [ -n "$TERM" ]; then
CLEAR='clear'
Expand All @@ -34,6 +42,11 @@ if [ -t 1 ] && [ -n "$TERM" ]; then
NC='\e[0m'
fi

# we need some bash 4+ features, check for old bash by feature
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() {
Expand Down Expand Up @@ -389,7 +402,7 @@ if [ -z "${BASHBOT_WGET}" ] && _exists curl ; then
local chat="";
[ -n "${1}" ] && chat='"chat_id":'"${1}"','
[ -n "${BASHBOTDEBUG}" ] &&\
printf "%s: sendJson (curl) CHAT=%s JSON=%s URL=%s\n" "$(date)" "${1}" "${2:0:100}" "${3##*/}" >>"${DEBUGLOG}"
printf "%s: sendJson (curl) CHAT=%s JSON=%s URL=%s\n" "$(date)" "${1}" "${2:0:100}" "${3##*/}" >>"${UPDATELOG}"
# shellcheck disable=SC2086
res="$("${BASHBOT_CURL}" -s -k ${BASHBOT_CURL_ARGS} -m "${TIMEOUT}"\
-d '{'"${chat} $(iconv -f utf-8 -t utf-8 -c <<<$2)"'}' -X POST "${3}" \
Expand All @@ -402,7 +415,7 @@ if [ -z "${BASHBOT_WGET}" ] && _exists curl ; then
[ "$#" -lt 4 ] && return
if [ -n "$5" ]; then
[ -n "${BASHBOTDEBUG}" ] &&\
printf "%s: sendUpload CHAT=%s WHAT=%s FILE=%s CAPT=%s\n" "$(date)" "${1}" "${2}" "${3}" "${4}" >>"${DEBUGLOG}"
printf "%s: sendUpload CHAT=%s WHAT=%s FILE=%s CAPT=%s\n" "$(date)" "${1}" "${2}" "${3}" "${4}" >>"${UPDATELOG}"
# shellcheck disable=SC2086
res="$("${BASHBOT_CURL}" -s -k ${BASHBOT_CURL_ARGS} "$4" -F "chat_id=$1"\
-F "$2=@$3;${3##*/}" -F "caption=$5" | "${JSONSHFILE}" -s -b -n 2>/dev/null )"
Expand All @@ -426,7 +439,7 @@ else
local chat="";
[ -n "${1}" ] && chat='"chat_id":'"${1}"','
[ -n "${BASHBOTDEBUG}" ] &&\
printf "%s: sendJson (wget) CHAT=%s JSON=%s URL=%s\n" "$(date)" "${1}" "${2:0:100}" "${3##*/}" >>"${DEBUGLOG}"
printf "%s: sendJson (wget) CHAT=%s JSON=%s URL=%s\n" "$(date)" "${1}" "${2:0:100}" "${3##*/}" >>"${UPDATELOG}"
# shellcheck disable=SC2086
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)"'}' \
--header='Content-Type:application/json' "${3}" | "${JSONSHFILE}" -s -b -n 2>/dev/null )"
Expand Down Expand Up @@ -633,8 +646,8 @@ process_client() {
jssh_countKeyDB_async "${CHAT[ID]}" "${COUNTFILE}"
}

declare -Ax BASBOT_EVENT_INLINE BASBOT_EVENT_MESSAGE BASHBOT_EVENT_CMD BASBOT_EVENT_REPLY BASBOT_EVENT_FORWARD BASHBOT_EVENT_SEND
declare -Ax BASBOT_EVENT_CONTACT BASBOT_EVENT_LOCATION BASBOT_EVENT_FILE BASHBOT_EVENT_TEXT BASHBOT_EVENT_TIMER BASHBOT_BLOCKED
declare -Ax BASHBOT_EVENT_INLINE BASHBOT_EVENT_MESSAGE BASHBOT_EVENT_CMD BASHBOT_EVENT_REPLY BASHBOT_EVENT_FORWARD BASHBOT_EVENT_SEND
declare -Ax BASHBOT_EVENT_CONTACT BASHBOT_EVENT_LOCATION BASHBOT_EVENT_FILE BASHBOT_EVENT_TEXT BASHBOT_EVENT_TIMER BASHBOT_BLOCKED

start_timer(){
# send alarm every ~60 s
Expand Down Expand Up @@ -1006,7 +1019,7 @@ bot_init() {
fi
#setup bashbot
[[ "${UID}" -eq "0" ]] && RUNUSER="nobody"
echo -n "Enter User to run basbot [$RUNUSER]: "
echo -n "Enter User to run bashbot [$RUNUSER]: "
read -r TOUSER
[ -z "$TOUSER" ] && TOUSER="$RUNUSER"
if ! id "$TOUSER" &>/dev/null; then
Expand Down Expand Up @@ -1145,6 +1158,8 @@ if [ -z "${SOURCE}" ]; then
sort -r "${BLOCKEDFILE}.jssh"
echo -e "${NC}\c"
fi
# show user created bot stats
_exec_if_function my_bashbot_stats "$@"
debug_checks "end $1" "$@"
exit
;;
Expand Down
14 changes: 7 additions & 7 deletions commands.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
# |_____/ \___/ |_| |_|\___/ \___) |_______)____|_|\___)_|
#
# this file *MUST* not be edited! place your config and commands in
# the file "mycommnds.sh". a clean version is provided as "mycommands.clean"
# the file "mycommands.sh". a clean version is provided as "mycommands.sh.clean"
#

# 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.1-0-gc0eb399
#

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

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

#-----------------------------
# this file *MUST* not edited!
# copy "mycommands.sh.dist" to "mycommnds.sh" and change the strings there
# copy "mycommands.sh.dist" to "mycommands.sh" and change the strings there
bashbot_help='Place your own commands and messages in mycommands.sh
*Available commands*:
Expand Down Expand Up @@ -65,7 +65,7 @@ fi

#----------------------------
# this file *MUST* not edited!
# copy "mycommands.sh.dist" to "mycommnds.sh" and change the values there
# copy "mycommands.sh.dist" to "mycommands.sh" and change the values there
# defaults to no inline and nonsense home dir
export INLINE="0"
export FILE_REGEX="${BASHBOT_ETC}/.*"
Expand Down Expand Up @@ -97,7 +97,7 @@ if [ -z "${1}" ] || [[ "${1}" == *"debug"* ]];then
case "${MESSAGE}" in
################################################
# this file *MUST* not edited!
# copy "mycommands.sh.dist" to "mycommnds.sh" and change the values and add your commands there
# copy "mycommands.sh.dist" to "mycommands.sh" and change the values and add your commands there
#
# GLOBAL commands start here, edit messages only
'/info'*)
Expand Down
6 changes: 3 additions & 3 deletions dev/all-tests.sh
Original file line number Diff line number Diff line change
@@ -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.0-0-g99217c4
#### $$VERSION$$ v1.1-0-gc0eb399

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

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

exit ${exitcode}
2 changes: 1 addition & 1 deletion dev/git-add.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# works together with git pre-push.sh and ADD all changed files since last push

#### $$VERSION$$ v1.0-0-g99217c4
#### $$VERSION$$ v1.1-0-gc0eb399

# magic to ensure that we're always inside the root of our application,
# no matter from which directory we'll run script
Expand Down
4 changes: 2 additions & 2 deletions dev/hooks/pre-commit.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env bash
#### $$VERSION$$ v1.0-0-g99217c4
#### $$VERSION$$ v1.1-0-gc0eb399

############
# NOTE: you MUST run install-hooks.sh again when updating this file!
Expand Down Expand Up @@ -65,7 +65,7 @@ else
exit 1
fi

if which codespell &>/dev/null; then
if command -v codespell &>/dev/null; then
echo "Running codespell"
echo "............................"
codespell -B 1 --skip="*.log,*.html,*.txt,.git*,jsonDB-keyboard" -L "ba"
Expand Down
2 changes: 1 addition & 1 deletion dev/hooks/pre-push.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env bash
#### $$VERSION$$ v1.0-0-g99217c4
#### $$VERSION$$ v1.1-0-gc0eb399

############
# NOTE: you MUST run install-hooks.sh again when updating this file!
Expand Down
2 changes: 1 addition & 1 deletion dev/install-hooks.sh
Original file line number Diff line number Diff line change
@@ -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.0-0-g99217c4
#### $$VERSION$$ v1.1-0-gc0eb399

# magic to ensure that we're always inside the root of our application,
# no matter from which directory we'll run script
Expand Down
2 changes: 1 addition & 1 deletion dev/make-distribution.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# file: make-distribution.sh
# creates files and arcchives to dirtribute bashbot
#
#### $$VERSION$$ v1.0-0-g99217c4
#### $$VERSION$$ v1.1-0-gc0eb399

# magic to ensure that we're always inside the root of our application,
# no matter from which directory we'll run script
Expand Down
2 changes: 1 addition & 1 deletion dev/make-standalone.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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.0-0-g99217c4
#### $$VERSION$$ v1.1-0-gc0eb399

# magic to ensure that we're always inside the root of our application,
# no matter from which directory we'll run script
Expand Down
2 changes: 1 addition & 1 deletion dev/shellcheck.files
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# list of additional files to check from shellcheck
#### $$VERSION$$ v1.0-0-g99217c4
#### $$VERSION$$ v1.1-0-gc0eb399
bashbot.rc
mycommands.sh.clean
2 changes: 1 addition & 1 deletion dev/version.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
#
#### $$VERSION$$ v1.0-0-g99217c4
#### $$VERSION$$ v1.1-0-gc0eb399
# shellcheck disable=SC2016
#
# Easy Versioning in git:
Expand Down
Loading

0 comments on commit d9d360e

Please sign in to comment.