diff --git a/bashbot.sh b/bashbot.sh index 71bcaa4..86bce42 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -30,7 +30,7 @@ BOTCOMMANDS="-h help init start stop status suspendback resumeback killb # 8 - curl/wget missing # 10 - not bash! # -#### $$VERSION$$ v1.45-dev-68-ge6838d1 +#### $$VERSION$$ v1.45-dev-69-gb454827 ################################################################## # are we running in a terminal? diff --git a/bin/any_command.sh b/bin/any_command.sh index 1e1373e..349356a 100755 --- a/bin/any_command.sh +++ b/bin/any_command.sh @@ -21,7 +21,7 @@ USAGE='any_command.sh [-h|--help] [--force|--reference] bot_command args ...' # AUTHOR: KayM (gnadelwartz), kay@rrr.de # CREATED: 30.01.2021 10:24 # -#### $$VERSION$$ v1.45-dev-68-ge6838d1 +#### $$VERSION$$ v1.45-dev-69-gb454827 #=============================================================================== #### diff --git a/bin/bashbot_env.inc.sh b/bin/bashbot_env.inc.sh new file mode 100644 index 0000000..17c0f5e --- /dev/null +++ b/bin/bashbot_env.inc.sh @@ -0,0 +1,91 @@ +#!/bin/bash +#=============================================================================== +# +# FILE: bashbot_env.inc.sh +# +# USAGE: source bashbot_env.inc.sh [debug] +# +# DESCRIPTION: set bashbot environment for all scripts in this directory +# +# OPTIONS: $1 - will be forwarded ro bashbot, e.g. debug +# +# LICENSE: WTFPLv2 http://www.wtfpl.net/txt/copying/ +# AUTHOR: KayM (gnadelwartz), kay@rrr.de +# CREATED: 18.12.2020 12:27 +# +#### $$VERSION$$ v1.45-dev-69-gb454827 +#=============================================================================== + +############ +# set where your bashbot lives +export BASHBOT_HOME BASHBOT_ETC BASHBOT_VAR FILE_REGEX ME + +# default: one dir up +BASHBOT_HOME="$(cd "${BASH_SOURCE[0]%/*}/../" >/dev/null 2>&1 && pwd)" +[ "${BASHBOT_HOME}" = "" ] && BASHBOT_HOME="../" + +# set you own BASHBOT_HOME if different, e.g. +# BASHBOT_HOME="/usr/local/telegram-bot-bash" +BASHBOT_VAR="${BASHBOT_HOME}" +BASHBOT_ETC="${BASHBOT_HOME}" + +##### +# if files are not readable, eviroment is wrong or bashbot is not initialized + +# check for bashbot +if [ ! -r "${BASHBOT_HOME}/bashbot.sh" ]; then + printf "%s\n" "Bashbot.sh not found in \"${BASHBOT_HOME}\"" + exit 4 +fi + +dev=" Are we in dev or did you forget to run init?" +# check for botconfig.jssh readable +if [ ! -r "${BASHBOT_ETC}/botconfig.jssh" ]; then + printf "%s\n" "Bashbot config file in \"${BASHBOT_ETC}\" does not exist or is not readable. ${dev}" + exit 3 +fi +# check for count.jssh readable +if [ ! -r "${BASHBOT_VAR}/count.jssh" ]; then + printf "%s\n" "Bashbot count file in \"${BASHBOT_VAR}\" does not exist or is not readable. ${dev}" + exit 3 +fi + +# shellcheck disable=SC1090 +source "${BASHBOT_HOME}/bashbot.sh" source "$1" + +# overwrite bot FILE regex to BASHBOT_VAR +# change this to the location you want to allow file uploads from +UPLOADDIR="${BASHBOT_VAR%/bin*}" +FILE_REGEX="${UPLOADDIR}/.*" + +# get and check ADMIN and NAME +BOTNAME="$(getConfigKey "botname")" +ME="${BOTNAME}" +[[ -z "${BOTADMIN}" || "${BOTADMIN}" == "?" ]] && printf "%s\n" "${ORANGE}Warning: Botadmin not set, send bot command${NC} /start" +[[ -z "${BOTNAME}" ]] && printf "%s\n" "${ORANGE}Warning: Botname not set, run bashbot.sh botname" + +# default webhook pipe +export WEBHOOK="${DATADIR}/webhook-fifo-${ME}" + + +# output command result or Telegram response +print_result() { jssh_printDB "BOTSENT" | sort -r; } +print_response() { jssh_printDB "UPD"; } + +# check and output help +print_help() { + case "$1" in + '') + printf "missing arguments\n" + ;& + "-h"*) + printf 'usage: %s\n' "${USAGE}" + exit 1 + ;; + '--h'*) + sed -n '/^#====/,/^#====/p' <"$0" + exit 1 + ;; + esac +} + diff --git a/bin/bashbot_init.inc.sh b/bin/bashbot_init.inc.sh index 7746e6f..b4ca71d 100644 --- a/bin/bashbot_init.inc.sh +++ b/bin/bashbot_init.inc.sh @@ -11,7 +11,7 @@ # AUTHOR: KayM (gnadelwartz), kay@rrr.de # CREATED: 27.01.2021 13:42 # -#### $$VERSION$$ v1.45-dev-68-ge6838d1 +#### $$VERSION$$ v1.45-dev-69-gb454827 #=============================================================================== # shellcheck disable=SC2059 diff --git a/bin/bashbot_stats.sh b/bin/bashbot_stats.sh index e111bfa..331033a 100755 --- a/bin/bashbot_stats.sh +++ b/bin/bashbot_stats.sh @@ -17,7 +17,7 @@ USAGE='bashbot_stats.sh [-h|--help] [debug]' # AUTHOR: KayM (gnadelwartz), kay@rrr.de # CREATED: 23.12.2020 20:34 # -#### $$VERSION$$ v1.45-dev-68-ge6838d1 +#### $$VERSION$$ v1.45-dev-69-gb454827 #=============================================================================== # set bashbot environment diff --git a/bin/delete_message.sh b/bin/delete_message.sh index e5eab73..5de96fb 100755 --- a/bin/delete_message.sh +++ b/bin/delete_message.sh @@ -20,7 +20,7 @@ USAGE='delete_message.sh [-h|--help] "CHAT[ID]" "MESSAGE[ID]" [debug]' # AUTHOR: KayM (gnadelwartz), kay@rrr.de # CREATED: 03.01.2021 15:37 # -#### $$VERSION$$ v1.45-dev-68-ge6838d1 +#### $$VERSION$$ v1.45-dev-69-gb454827 #=============================================================================== #### diff --git a/bin/edit_buttons.sh b/bin/edit_buttons.sh index 62a63a2..8ce27c3 100755 --- a/bin/edit_buttons.sh +++ b/bin/edit_buttons.sh @@ -26,7 +26,7 @@ USAGE='send_message.sh [-h|--help] "CHAT[ID]" "MESSAGE[ID]" "text|url" ...' # AUTHOR: KayM (gnadelwartz), kay@rrr.de # CREATED: 21.01.2021 08:10 # -#### $$VERSION$$ v1.45-dev-68-ge6838d1 +#### $$VERSION$$ v1.45-dev-69-gb454827 #=============================================================================== #### diff --git a/bin/edit_message.sh b/bin/edit_message.sh index 7bd6119..be810da 100755 --- a/bin/edit_message.sh +++ b/bin/edit_message.sh @@ -23,7 +23,7 @@ USAGE='send_edit_message.sh [-h|--help] [format|caption] "CHAT[ID]" "MESSAGE[ID] # AUTHOR: KayM (gnadelwartz), kay@rrr.de # CREATED: 23.12.2020 16:52 # -#### $$VERSION$$ v1.45-dev-68-ge6838d1 +#### $$VERSION$$ v1.45-dev-69-gb454827 #=============================================================================== #### diff --git a/bin/kickban_user.sh b/bin/kickban_user.sh index 49b3633..f119575 100755 --- a/bin/kickban_user.sh +++ b/bin/kickban_user.sh @@ -20,7 +20,7 @@ USAGE='kickban_user.sh [-h|--help] [-u|--unban] "CHAT[ID]" "USER[ID]" [debug]' # AUTHOR: KayM (gnadelwartz), kay@rrr.de # CREATED: 25.01.2021 20:34 # -#### $$VERSION$$ v1.45-dev-68-ge6838d1 +#### $$VERSION$$ v1.45-dev-69-gb454827 #=============================================================================== #### diff --git a/bin/process_batch.sh b/bin/process_batch.sh index 509d3fb..e406133 100755 --- a/bin/process_batch.sh +++ b/bin/process_batch.sh @@ -21,7 +21,7 @@ USAGE='process_update.sh [-h|--help] [-s|--startbot] [-w|--watch] [-n|--lines n] # AUTHOR: KayM (gnadelwartz), kay@rrr.de # CREATED: 27.02.2021 13:14 # -#### $$VERSION$$ v1.45-dev-68-ge6838d1 +#### $$VERSION$$ v1.45-dev-69-gb454827 #=============================================================================== #### diff --git a/bin/process_update.sh b/bin/process_update.sh index 61fc5db..7ba74ca 100755 --- a/bin/process_update.sh +++ b/bin/process_update.sh @@ -15,7 +15,7 @@ USAGE='process_update.sh [-h|--help] [debug] [