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
|
|
|
|
#
|
2020-12-27 09:38:49 +00:00
|
|
|
#### $$VERSION$$ v1.21-dev-2-gde31231
|
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
|
|
|
|
echo "Bashbot.sh not found in \"${BASHBOT_HOME}\""
|
|
|
|
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
|
|
|
|
echo "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
|
|
|
|
echo "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")"
|
|
|
|
[[ -z "${BOT_ADMIN}" || "${BOT_ADMIN}" == "?" ]] && echo -e "${ORANGE}Warning: Botadmin not set, did you forget to sent command${NC} /start"
|
|
|
|
[[ -z "${BOT_NAME}" ]] && echo -e "${ORANGE}Warning: Botname not set, did you ever run bashbot?"
|
2020-12-25 17:43:36 +00:00
|
|
|
|