2020-12-18 13:53:44 +00:00
|
|
|
#!/bin/bash
|
|
|
|
#===============================================================================
|
|
|
|
#
|
2020-12-25 17:43:36 +00:00
|
|
|
# FILE: bashbot_env.inc.sh
|
2020-12-18 13:53:44 +00:00
|
|
|
#
|
2020-12-25 17:43:36 +00:00
|
|
|
# USAGE: source bashbot_env.inc.sh [debug]
|
|
|
|
#
|
2020-12-18 13:53:44 +00:00
|
|
|
# DESCRIPTION: set bashbot environment for all scripts in this directory
|
|
|
|
#
|
2020-12-25 17:43:36 +00:00
|
|
|
# OPTIONS: $1 - will be forwarded ro bashbot, e.g. debug
|
2020-12-18 13:53:44 +00:00
|
|
|
#
|
|
|
|
# LICENSE: WTFPLv2 http://www.wtfpl.net/txt/copying/
|
|
|
|
# AUTHOR: KayM (gnadelwartz), kay@rrr.de
|
|
|
|
# CREATED: 18.12.2020 12:27
|
|
|
|
#
|
2021-01-17 08:57:08 +00:00
|
|
|
#### $$VERSION$$ v1.30-0-g3266427
|
2020-12-18 13:53:44 +00:00
|
|
|
#===============================================================================
|
|
|
|
|
2020-12-25 18:16:54 +00:00
|
|
|
############
|
2020-12-18 13:53:44 +00:00
|
|
|
# set where your bashbot lives
|
2020-12-25 19:57:05 +00:00
|
|
|
export BASHBOT_HOME BASHBOT_ETC BASHBOT_VAR FILE_REGEX
|
2020-12-25 18:42:58 +00:00
|
|
|
|
2020-12-18 13:53:44 +00:00
|
|
|
# default: one dir up
|
|
|
|
BASHBOT_HOME="$(cd "${BASH_SOURCE[0]%/*}" >/dev/null 2>&1 && pwd)/../"
|
2020-12-25 18:16:54 +00:00
|
|
|
[ "${BASHBOT_HOME}" = "/../" ] && BASHBOT_HOME="../"
|
|
|
|
|
|
|
|
# set you own BASHBOT_HOME if different, e.g.
|
|
|
|
# BASHBOT_HOME="/usr/local/telegram-bot-bash"
|
|
|
|
BASHBOT_VAR="${BASHBOT_HOME}"
|
2020-12-25 19:57:05 +00:00
|
|
|
BASHBOT_ETC="${BASHBOT_HOME}"
|
2020-12-18 13:53:44 +00:00
|
|
|
|
|
|
|
#####
|
|
|
|
# if files are not readable, eviroment is wrong or bashbot is not initialized
|
|
|
|
|
2020-12-25 18:16:54 +00:00
|
|
|
# source bashbot
|
|
|
|
if [ ! -r "${BASHBOT_HOME}/bashbot.sh" ]; then
|
2021-01-02 22:29:30 +00:00
|
|
|
printf "%s\n" "Bashbot.sh not found in \"${BASHBOT_HOME}\""
|
2020-12-25 18:16:54 +00:00
|
|
|
exit 4
|
|
|
|
fi
|
|
|
|
|
2020-12-18 13:53:44 +00:00
|
|
|
# check for botconfig.jssh readable
|
2020-12-25 18:16:54 +00:00
|
|
|
if [ ! -r "${BASHBOT_ETC}/botconfig.jssh" ]; then
|
2021-01-02 22:29:30 +00:00
|
|
|
printf "%s\n" "Bashbot config file in \"${BASHBOT_ETC}\" does not exist or is not readable."
|
2020-12-18 13:53:44 +00:00
|
|
|
exit 3
|
|
|
|
fi
|
|
|
|
# check for count.jssh readable
|
2020-12-25 18:16:54 +00:00
|
|
|
if [ ! -r "${BASHBOT_VAR}/count.jssh" ]; then
|
2021-01-02 22:29:30 +00:00
|
|
|
printf "%s\n" "Bashbot count file in \"${BASHBOT_VAR}\" does not exist or is not readable. Did you run bashbot init?"
|
2020-12-18 13:53:44 +00:00
|
|
|
exit 3
|
|
|
|
fi
|
|
|
|
|
2020-12-26 19:39:21 +00:00
|
|
|
# shellcheck disable=SC1090
|
|
|
|
source "${BASHBOT_HOME}/bashbot.sh" source "$1"
|
|
|
|
|
2020-12-27 09:38:49 +00:00
|
|
|
# overwrite bot FILE regex to BASHBOT_VAR
|
2020-12-26 19:39:21 +00:00
|
|
|
# change this to the location you want to allow file uploads from
|
2020-12-27 09:38:49 +00:00
|
|
|
UPLOADDIR="${BASHBOT_VAR%/bin*}"
|
|
|
|
FILE_REGEX="${UPLOADDIR}/.*"
|
2020-12-26 19:39:21 +00:00
|
|
|
|
2020-12-25 18:16:54 +00:00
|
|
|
# get and check ADMIN and NAME
|
|
|
|
BOT_ADMIN="$(getConfigKey "botadmin")"
|
|
|
|
BOT_NAME="$(getConfigKey "botname")"
|
2021-01-02 22:29:30 +00:00
|
|
|
[[ -z "${BOT_ADMIN}" || "${BOT_ADMIN}" == "?" ]] && printf "%s\n" "${ORANGE}Warning: Botadmin not set, did you forget to sent command${NC} /start"
|
|
|
|
[[ -z "${BOT_NAME}" ]] && printf "%s\n" "${ORANGE}Warning: Botname not set, did you ever run bashbot?"
|
2020-12-25 17:43:36 +00:00
|
|
|
|