use printf
This commit is contained in:
parent
2e878fd864
commit
03bdecb056
148
bashbot.sh
148
bashbot.sh
|
@ -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.20-0-g2ab00a2
|
||||
#### $$VERSION$$ v1.21-dev-0-g2e878fd
|
||||
#
|
||||
# Exit Codes:
|
||||
# - 0 success (hopefully)
|
||||
|
@ -24,16 +24,17 @@
|
|||
# - 7 can't get bottoken
|
||||
# - 8 curl/wget missing
|
||||
# - 10 not bash!
|
||||
# shellcheck disable=SC2140,SC2031,SC2120,SC1091,SC1117
|
||||
# shellcheck disable=SC2140,SC2031,SC2120,SC1091,SC1117,SC2059
|
||||
|
||||
# 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 "Error: Current shell does not support ARRAY's, may be busbox ash shell. pls install a real bash!";
|
||||
printf "Error: Current shell does not support ARRAY's, may be busbox ash shell. pls install a real bash!\n"
|
||||
exit 10
|
||||
fi
|
||||
|
||||
# are we running in a terminal?
|
||||
NN="\n"
|
||||
if [ -t 1 ] && [ -n "$TERM" ]; then
|
||||
CLEAR='clear'
|
||||
RED='\e[31m'
|
||||
|
@ -41,16 +42,17 @@ if [ -t 1 ] && [ -n "$TERM" ]; then
|
|||
ORANGE='\e[35m'
|
||||
GREY='\e[1;30m'
|
||||
NC='\e[0m'
|
||||
NN="${NN}"
|
||||
fi
|
||||
|
||||
# telegram uses utf-8 characters, check if we have an utf-8 charset
|
||||
if [ "${LANG}" = "${LANG%[Uu][Tt][Ff]*}" ]; then
|
||||
echo -e "${ORANGE}Warning: Telegram uses utf-8, but looks like you are using non utf-8 locale:${NC} ${LANG}"
|
||||
printf "${ORANGE}Warning: Telegram uses utf-8, but looks like you are using non utf-8 locale:${NC} ${LANG}\n"
|
||||
fi
|
||||
|
||||
# we need some bash 4+ features, check for old bash by feature
|
||||
if [ "$({ LC_ALL=C.utf-8 echo -e "\u1111"; } 2>/dev/null)" = "\u1111" ]; then
|
||||
echo -e "${ORANGE}Warning: Missing unicode '\uxxxx' support, missing C.utf-8 locale or to old bash version.${NC}"
|
||||
printf "${ORANGE}Warning: Missing unicode '\uxxxx' support, missing C.utf-8 locale or to old bash version.${NN}"
|
||||
fi
|
||||
|
||||
|
||||
|
@ -117,7 +119,7 @@ debug_checks(){ {
|
|||
|
||||
# some linux, e.g. manajro seems not to have C locale activated by default
|
||||
if _exists locale && [ "$(locale -a | grep -c -e "^C$" -e "^C.utf8$")" -lt 2 ]; then
|
||||
echo -e "${ORANGE}Warning: locale ${NC}${GREY}C${NC}${ORANGE} and/or ${NC}${GREY}C.utf8${NC}${ORANGE} seems missing, use \"${NC}${GREY}locale -a${NC}${ORANGE}\" to show what locales are installed on your system.${NC}"
|
||||
printf "${ORANGE}Warning: locale ${NC}${GREY}C${NC}${ORANGE} and/or ${NC}${GREY}C.utf8${NC}${ORANGE} seems missing, use \"${NC}${GREY}locale -a${NC}${ORANGE}\" to show what locales are installed on your system.${NN}"
|
||||
fi
|
||||
|
||||
# get location and name of bashbot.sh
|
||||
|
@ -134,7 +136,7 @@ if [ "${SCRIPT}" != "${REALME}" ] || [ "$1" = "source" ]; then
|
|||
fi
|
||||
|
||||
BOTCOMMANDS="start, stop, status, help, init, suspendback, resumeback, killback"
|
||||
[[ -z "$1" && -z "${SOURCE}" ]] && echo -e "${ORANGE}Available commands: ${GREY}${BOTCOMMANDS}${NC}" && exit
|
||||
[[ -z "$1" && -z "${SOURCE}" ]] && printf "${ORANGE}Available commands: ${GREY}${BOTCOMMANDS}${NN}" && exit
|
||||
if [ "$1" = "help" ]; then
|
||||
HELP="${BASHBOT_HOME:-.}/README"
|
||||
if [ -n "${CLEAR}" ];then
|
||||
|
@ -159,14 +161,14 @@ RUNUSER="${USER}" # USER is overwritten by bashbot array :-(, save original
|
|||
|
||||
# OK everything setup, lets start
|
||||
if [[ -z "${SOURCE}" && -z "$BASHBOT_HOME" ]] && ! cd "${RUNDIR}" ; then
|
||||
echo -e "${RED}ERROR: Can't change to ${RUNDIR} ...${NC}"
|
||||
printf "${RED}ERROR: Can't change to ${RUNDIR} ...${NN}"
|
||||
exit 1
|
||||
else
|
||||
RUNDIR="."
|
||||
fi
|
||||
|
||||
if [ ! -w "." ]; then
|
||||
echo -e "${ORANGE}WARNING: ${RUNDIR} is not writeable!${NC}"
|
||||
printf "${ORANGE}WARNING: ${RUNDIR} is not writeable!${NN}"
|
||||
ls -ld .
|
||||
fi
|
||||
|
||||
|
@ -190,12 +192,12 @@ if [[ -z "${BOTTOKEN}" && ! -f "${BOTCONFIG}.jssh" ]]; then
|
|||
token="$(< "${TOKENFILE}")"
|
||||
# no old token, ask user
|
||||
elif [ -z "${CLEAR}" ] && [ "$1" != "init" ]; then
|
||||
echo "Running headless, set BOTTOKEN or run ${SCRIPT} init first!"
|
||||
printf "Running headless, set BOTTOKEN or run ${SCRIPT} init first!\n"
|
||||
exit 2
|
||||
else
|
||||
${CLEAR}
|
||||
echo -e "${RED}TOKEN MISSING.${NC}"
|
||||
echo -e "${ORANGE}PLEASE WRITE YOUR TOKEN HERE OR PRESS CTRL+C TO ABORT${NC}"
|
||||
printf "${RED}TOKEN MISSING.${NN}"
|
||||
printf "${ORANGE}PLEASE WRITE YOUR TOKEN HERE OR PRESS CTRL+C TO ABORT${NN}"
|
||||
read -r token
|
||||
fi
|
||||
[ -n "${token}" ] && printf '["bottoken"]\t"%s"\n' "${token}" >> "${BOTCONFIG}.jssh"
|
||||
|
@ -206,12 +208,12 @@ if [[ -z "${BOTTOKEN}" && ! -f "${BOTCONFIG}.jssh" ]]; then
|
|||
if [ -r "${BOTADMIN}" ]; then
|
||||
admin="$(< "${BOTADMIN}")"
|
||||
elif [ -z "${CLEAR}" ]; then
|
||||
echo "Running headless, set botadmin to AUTO MODE!"
|
||||
printf "Running headless, set botadmin to AUTO MODE!\n"
|
||||
else
|
||||
${CLEAR}
|
||||
echo -e "${RED}BOTADMIN MISSING.${NC}"
|
||||
echo -e "${ORANGE}PLEASE WRITE YOUR TELEGRAM ID HERE OR ENTER '?'${NC}"
|
||||
echo -e "${ORANGE}TO MAKE FIRST USER TYPING '/start' TO BOTADMIN${NC}"
|
||||
printf "${RED}BOTADMIN MISSING.${NN}"
|
||||
printf "${ORANGE}PLEASE WRITE YOUR TELEGRAM ID HERE OR ENTER '?'${NN}"
|
||||
printf "${ORANGE}TO MAKE FIRST USER TYPING '/start' TO BOTADMIN${NN}"
|
||||
read -r admin
|
||||
fi
|
||||
[ -z "${admin}" ] && admin='?'
|
||||
|
@ -219,14 +221,14 @@ if [[ -z "${BOTTOKEN}" && ! -f "${BOTCONFIG}.jssh" ]]; then
|
|||
fi
|
||||
# setup botacl file
|
||||
if [ ! -f "${BOTACL}" ]; then
|
||||
echo -e "${ORANGE}Create empty ${BOTACL} file.${NC}"
|
||||
printf "${ORANGE}Create empty ${BOTACL} file.${NC}"
|
||||
printf '\n' >"${BOTACL}"
|
||||
fi
|
||||
# setup data dir file
|
||||
if [ ! -d "${DATADIR}" ]; then
|
||||
mkdir "${DATADIR}"
|
||||
elif [ ! -w "${DATADIR}" ]; then
|
||||
echo -e "${RED}ERROR: Can't write to ${DATADIR}!.${NC}"
|
||||
printf "${RED}ERROR: Can't write to ${DATADIR}!.${NN}"
|
||||
ls -ld "${DATADIR}"
|
||||
exit 2
|
||||
fi
|
||||
|
@ -238,7 +240,7 @@ if [[ -z "${BOTTOKEN}" && ! -f "${BOTCONFIG}.jssh" ]]; then
|
|||
sed 's/COUNT/\[\"/;s/$/\"\]\t\"1\"/' < "${COUNTFILE}" >> "${COUNTFILE}.jssh"
|
||||
fi
|
||||
elif [ ! -w "${COUNTFILE}.jssh" ]; then
|
||||
echo -e "${RED}ERROR: Can't write to ${COUNTFILE}!.${NC}"
|
||||
printf "${RED}ERROR: Can't write to ${COUNTFILE}!.${NN}"
|
||||
ls -l "${COUNTFILE}.jssh"
|
||||
exit 2
|
||||
fi
|
||||
|
@ -262,13 +264,13 @@ if [ -z "${BOTTOKEN}" ]; then
|
|||
BOTTOKEN="$(getConfigKey "bottoken")"
|
||||
if [ -z "${BOTTOKEN}" ]; then
|
||||
BOTERROR="Warning: can't get bot token, try to recover working config..."
|
||||
echo -e "${ORANGE}${BOTERROR}${NC} \c"
|
||||
printf "${ORANGE}${BOTERROR}${NC} "
|
||||
if [ -r "${BOTCONFIG}.jssh.ok" ]; then
|
||||
log_error "${BOTERROR}"
|
||||
cp "${BOTCONFIG}.jssh.ok" "${BOTCONFIG}.jssh"; echo "OK"
|
||||
cp "${BOTCONFIG}.jssh.ok" "${BOTCONFIG}.jssh"; printf "OK\n"
|
||||
BOTTOKEN="$(getConfigKey "bottoken")"
|
||||
else
|
||||
echo -e "\n${RED}Error: Missing bot token! remove ${BOTCONFIG}.jssh and run \"bashbot.sh init\" may fix it.${NC}"
|
||||
printf "\n${RED}Error: Missing bot token! remove ${BOTCONFIG}.jssh and run \"bashbot.sh init\" may fix it.${NN}"
|
||||
exit 7
|
||||
fi
|
||||
fi
|
||||
|
@ -276,16 +278,16 @@ fi
|
|||
|
||||
# BOTTOKEN format checks
|
||||
if ! check_token "${BOTTOKEN}"; then
|
||||
echo -e "${ORANGE}Warning: your bottoken may incorrect. it should have the following format:${NC}"
|
||||
echo -e "${GREY}123456789${RED}:${GREY}Aa-Zz_0Aa-Zz_1Aa-Zz_2Aa-Zz_3Aa-Zz_4${ORANGE} => ${NC}\c"
|
||||
echo -e "${GREY}8-10 digits${RED}:${GREY}35 alphanumeric characters + '_-'${NC}"
|
||||
echo -e "${ORANGE}Your current token is: '${GREY}^$(cat -ve <<<"${BOTTOKEN//:/${RED}:${GREY}}")${ORANGE}'${NC}"
|
||||
printf "${ORANGE}Warning: your bottoken may incorrect. it should have the following format:${NN}"
|
||||
printf "${GREY}123456789${RED}:${GREY}Aa-Zz_0Aa-Zz_1Aa-Zz_2Aa-Zz_3Aa-Zz_4${ORANGE} => ${NC}"
|
||||
printf "${GREY}8-10 digits${RED}:${GREY}35 alphanumeric characters + '_-'${NN}"
|
||||
printf "${ORANGE}Your current token is: '${GREY}^$(cat -ve <<<"${BOTTOKEN//:/${RED}:${GREY}}")${ORANGE}'${NN}"
|
||||
if [[ ! "${BOTTOKEN}" =~ ^[0-9]{8,10}: ]]; then
|
||||
echo -e "${ORANGE}Possible problem in the digits part, len is $(($(wc -c <<<"${BOTTOKEN%:*}")-1))${NC}"
|
||||
[ -n "$(getConfigKey "botid")" ] && echo -e "${GREY}Did you mean: \"${NC}$(getConfigKey "botid")${GREY}\" ?${NC}"
|
||||
printf "${ORANGE}Possible problem in the digits part, len is $(($(wc -c <<<"${BOTTOKEN%:*}")-1))${NN}"
|
||||
[ -n "$(getConfigKey "botid")" ] && printf "${GREY}Did you mean: \"${NC}$(getConfigKey "botid")${GREY}\" ?${NN}"
|
||||
fi
|
||||
[[ ! "${BOTTOKEN}" =~ :[a-zA-Z0-9_-]{35}$ ]] &&\
|
||||
echo -e "${ORANGE}Possible problem in the characters part, len is $(($(wc -c <<<"${BOTTOKEN#*:}")-1))${NC}"
|
||||
printf "${ORANGE}Possible problem in the characters part, len is $(($(wc -c <<<"${BOTTOKEN#*:}")-1))${NN}"
|
||||
fi
|
||||
|
||||
|
||||
|
@ -317,7 +319,7 @@ export res CAPTION ME
|
|||
COMMANDS="${BASHBOT_ETC:-.}/commands.sh"
|
||||
if [ -z "${SOURCE}" ]; then
|
||||
if [ ! -f "${COMMANDS}" ] || [ ! -r "${COMMANDS}" ]; then
|
||||
echo -e "${RED}ERROR: ${COMMANDS} does not exist or is not readable!.${NC}"
|
||||
printf "${RED}ERROR: ${COMMANDS} does not exist or is not readable!.${NN}"
|
||||
ls -l "${COMMANDS}"
|
||||
exit 3
|
||||
fi
|
||||
|
@ -338,11 +340,11 @@ done
|
|||
|
||||
# do we have BSD sed
|
||||
if ! sed '1ia' </dev/null 2>/dev/null; then
|
||||
echo -e "${ORANGE}Warning: You may run on a BSD style system without gnu utils ...${NC}"
|
||||
printf "${ORANGE}Warning: You may run on a BSD style system without gnu utils ...${NN}"
|
||||
fi
|
||||
#jsonDB is now mandatory
|
||||
if ! _is_function jssh_newDB ; then
|
||||
echo -e "${RED}ERROR: Mandatory module jsonDB is missing or not readable!"
|
||||
printf "${RED}ERROR: Mandatory module jsonDB is missing or not readable!${NN}"
|
||||
exit 6
|
||||
fi
|
||||
|
||||
|
@ -523,9 +525,9 @@ else
|
|||
else
|
||||
# ups, no curl AND no wget
|
||||
if [ -n "${BASHBOT_WGET}" ]; then
|
||||
echo -e "${RED}Error: You set BASHBOT_WGET but no wget found!${NC}"
|
||||
printf "${RED}Error: You set BASHBOT_WGET but no wget found!${NN}"
|
||||
else
|
||||
echo -e "${RED}Error: curl and wget not found, install curl!${NC}"
|
||||
printf "${RED}Error: curl and wget not found, install curl!${NN}"
|
||||
fi
|
||||
exit 8
|
||||
fi
|
||||
|
@ -649,7 +651,7 @@ getBotName() {
|
|||
# save botname and id
|
||||
setConfigKey "botname" "${BOTARRAY["result","username"]}"
|
||||
setConfigKey "botid" "${BOTARRAY["result","id"]}"
|
||||
echo "${BOTARRAY["result","username"]}"
|
||||
printf "${BOTARRAY["result","username"]}\n"
|
||||
}
|
||||
|
||||
# pure bash implementation, done by KayM (@gnadelwartz)
|
||||
|
@ -1102,42 +1104,42 @@ bot_init() {
|
|||
[ -n "${BASHBOT_HOME}" ] && cd "${BASHBOT_HOME}" || exit 1
|
||||
local DEBUG="$1"
|
||||
# upgrade from old version
|
||||
echo "Check for Update actions ..."
|
||||
printf "Check for Update actions ...\n"
|
||||
local OLDTMP="${BASHBOT_VAR:-.}/tmp-bot-bash"
|
||||
[ -d "${OLDTMP}" ] && { mv -n "${OLDTMP}/"* "${DATADIR}"; rmdir "${OLDTMP}"; }
|
||||
# no more existing modules
|
||||
[ -f "modules/inline.sh" ] && rm -f "modules/inline.sh"
|
||||
# load addons on startup
|
||||
echo "Done."
|
||||
echo "Initialize modules and addons ..."
|
||||
printf "Done.\n"
|
||||
printf "Initialize modules and addons ...\n"
|
||||
for addons in "${ADDONDIR:-.}"/*.sh ; do
|
||||
# shellcheck source=./modules/aliases.sh
|
||||
[ -r "${addons}" ] && source "${addons}" "init" "${DEBUG}"
|
||||
done
|
||||
echo "Done."
|
||||
printf "Done.\n"
|
||||
if [[ ! -d "logs" ]]; then
|
||||
echo "Move Logfiles ..."
|
||||
printf "Move Logfiles ...\n"
|
||||
mkdir logs 2>/dev/null
|
||||
for MVLOG in DEBUG.log MESSAGE.log ERROR.log BASHBOT.log
|
||||
do
|
||||
[ -f "${MVLOG}" ] && mv "${MVLOG}" logs 2>/dev/null
|
||||
done
|
||||
echo "Done."
|
||||
printf "Done.\n"
|
||||
fi
|
||||
# setup bashbot
|
||||
[[ "${UID}" -eq "0" ]] && RUNUSER="nobody"
|
||||
echo -n "Enter User to run bashbot [$RUNUSER]: "
|
||||
printf "Enter User to run bashbot [$RUNUSER]: "
|
||||
read -r TOUSER
|
||||
[ -z "$TOUSER" ] && TOUSER="$RUNUSER"
|
||||
if ! id "$TOUSER" &>/dev/null; then
|
||||
echo -e "${RED}User \"$TOUSER\" not found!${NC}"
|
||||
printf "${RED}User \"$TOUSER\" not found!${NN}"
|
||||
exit 3
|
||||
else
|
||||
# shellcheck disable=SC2009
|
||||
oldbot="$(ps -fu "$TOUSER" | grep startbot | grep -v -e 'grep' -e '\-startbot' )"
|
||||
[ -n "${oldbot}" ] && \
|
||||
echo -e "${ORANGE}Warning: At least one not upgraded TMUX bot is running! You must stop it with kill command:${NC}\\n${oldbot}"
|
||||
echo "Adjusting files and permissions for user \"${TOUSER}\" ..."
|
||||
printf "${ORANGE}Warning: At least one not upgraded TMUX bot is running! You must stop it with kill command:${NN}${oldbot}\n"
|
||||
printf "Adjusting files and permissions for user \"${TOUSER}\" ...\n"
|
||||
[ -w "bashbot.rc" ] && sed -i '/^[# ]*runas=/ s/runas=.*$/runas="'$TOUSER'"/' "bashbot.rc"
|
||||
chown -R "$TOUSER" . ./*
|
||||
chmod 711 .
|
||||
|
@ -1146,45 +1148,45 @@ bot_init() {
|
|||
chmod -R o-r,o-w "${COUNTFILE}"* "${BLOCKEDFILE}"* "${DATADIR}" "${TOKENFILE}" "${BOTADMIN}" "${BOTACL}" 2>/dev/null
|
||||
# jsshDB must writeable by owner
|
||||
find . -name '*.jssh*' -exec chmod u+w \{\} +
|
||||
echo "Done."
|
||||
printf "Done.\n"
|
||||
fi
|
||||
# ask to check bottoken online
|
||||
if [ -z "$(getConfigKey "botid")" ]; then
|
||||
echo -e "Seems to be your first init. Should I verify your bot token online? (y/N) N\b\c"
|
||||
printf "Seems to be your first init. Should I verify your bot token online? (y/N) N\b"
|
||||
read -r ANSWER
|
||||
if [[ "${ANSWER}" =~ ^[Yy] ]]; then
|
||||
echo -e "${GREEN}Contacting telegram to verify your bot token ...${NC}"
|
||||
printf "${GREEN}Contacting telegram to verify your bot token ...${NN}"
|
||||
$0 botname
|
||||
fi
|
||||
fi
|
||||
# check if botconf if seems valid
|
||||
echo -e "${GREEN}This is your bot config:${NC}"
|
||||
printf "${GREEN}This is your bot config:${NN}"
|
||||
sed 's/^/\t/' "${BOTCONFIG}.jssh" | grep -vF '["bot_config_key"]'
|
||||
if [[ "$(getConfigKey "bottoken")" =~ ^[0-9]{8,10}:[a-zA-Z0-9_-]{35}$ && "$(getConfigKey "botadmin")" =~ ^[0-9]+$ ]]; then
|
||||
echo -e "Bot config seems to be valid. Should I make a backup copy? (Y/n) Y\b\c"
|
||||
printf "Bot config seems to be valid. Should I make a backup copy? (Y/n) Y\b"
|
||||
read -r ANSWER
|
||||
if [[ -z "${ANSWER}" || "${ANSWER}" =~ ^[^Nn] ]]; then
|
||||
echo "Copy bot config to ${BOTCONFIG}.jssh.ok ..."
|
||||
printf "Copy bot config to ${BOTCONFIG}.jssh.ok ...\n"
|
||||
cp "${BOTCONFIG}.jssh" "${BOTCONFIG}.jssh.ok"
|
||||
fi
|
||||
else
|
||||
echo -e "${ORANGE}Bot config may not complete, pls check.${NC}"
|
||||
printf "${ORANGE}Bot config may not complete, pls check.${NN}"
|
||||
fi
|
||||
# show result
|
||||
ls -ld "${DATADIR}" "${LOGDIR}" ./*.jssh* ./*.sh 2>/dev/null
|
||||
}
|
||||
|
||||
if ! _is_function send_message ; then
|
||||
echo -e "${RED}ERROR: send_message is not available, did you deactivate ${MODULEDIR}/sendMessage.sh?${NC}"
|
||||
printf "${RED}ERROR: send_message is not available, did you deactivate ${MODULEDIR}/sendMessage.sh?${NN}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# get location of JSON.sh, download if not exist
|
||||
JSONSHFILE="${BASHBOT_JSONSH:-${SCRIPTDIR}/JSON.sh/JSON.sh}"
|
||||
[[ "${JSONSHFILE}" != *"/JSON.sh" ]] && echo -e "${RED}ERROR: \"${JSONSHFILE}\" ends not with \"JSONS.sh\".${NC}" && exit 3
|
||||
[[ "${JSONSHFILE}" != *"/JSON.sh" ]] && printf "${RED}ERROR: \"${JSONSHFILE}\" ends not with \"JSONS.sh\".${NN}" && exit 3
|
||||
|
||||
if [ ! -f "${JSONSHFILE}" ]; then
|
||||
echo "Seems to be first run, Downloading ${JSONSHFILE}..."
|
||||
printf "Seems to be first run, Downloading ${JSONSHFILE}...\n"
|
||||
[ "${SCRIPTDIR}/JSON.sh/JSON.sh" = "${JSONSHFILE}" ] &&\
|
||||
mkdir "${SCRIPTDIR}/JSON.sh" 2>/dev/null && chmod +w "${SCRIPTDIR}/JSON.sh"
|
||||
getJson "https://cdn.jsdelivr.net/gh/dominictarr/JSON.sh/JSON.sh" >"${JSONSHFILE}"
|
||||
|
@ -1210,14 +1212,14 @@ if [ -z "${SOURCE}" ]; then
|
|||
ME="$(getBotName)"
|
||||
if [ -n "${ME}" ]; then
|
||||
# ok we have a connection and got botname, save it
|
||||
[ -n "${CLEAR}" ] && echo -e "${GREY}Bottoken is valid ...${NC}"
|
||||
[ -n "${CLEAR}" ] && printf "${GREY}Bottoken is valid ...${NN}"
|
||||
jssh_updateKeyDB "botname" "${ME}" "${BOTCONFIG}"
|
||||
rm -f "${BOTCONFIG}.jssh.flock"
|
||||
else
|
||||
echo -e "${GREY}Info: Can't get Botname from Telegram, try cached one ...${NC}"
|
||||
printf "${GREY}Info: Can't get Botname from Telegram, try cached one ...${NN}"
|
||||
ME="$(getConfigKey "botname")"
|
||||
if [ -z "$ME" ]; then
|
||||
echo -e "${RED}ERROR: No cached botname, can't continue! ...${NC}"
|
||||
printf "${RED}ERROR: No cached botname, can't continue! ...${NN}"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
@ -1226,8 +1228,8 @@ if [ -z "${SOURCE}" ]; then
|
|||
;;&
|
||||
# used to send output of background and interactive to chats
|
||||
"outproc") # $2 chat_id $3 identifier of job, internal use only!
|
||||
[ -z "$3" ] && echo "No job identifier" && exit 3
|
||||
[ -z "$2" ] && echo "No chat to send to" && exit 3
|
||||
[ -z "$3" ] && printf "No job identifier\n" && exit 3
|
||||
[ -z "$2" ] && printf "No chat to send to\n" && exit 3
|
||||
ME="$(getConfigKey "botname")"
|
||||
# read until terminated
|
||||
while read -r line ;do
|
||||
|
@ -1289,7 +1291,7 @@ if [ -z "${SOURCE}" ]; then
|
|||
;;
|
||||
# send message to all users
|
||||
'broadcast')
|
||||
echo -e "${ORANGE}Broadcast is a separate command now, see ${BASHBOT_HOME:-.}/bin/send_broadcast.sh --help${NC}"
|
||||
printf "${ORANGE}Broadcast is a separate command now, see ${BASHBOT_HOME:-.}/bin/send_broadcast.sh --help${NN}"
|
||||
"${BASHBOT_HOME:-.}"/bin/send_broadcast.sh --help
|
||||
exit
|
||||
;;
|
||||
|
@ -1299,10 +1301,10 @@ if [ -z "${SOURCE}" ]; then
|
|||
SESSION="${ME:-_bot}-startbot"
|
||||
BOTPID="$(proclist "${SESSION}")"
|
||||
if [ -n "${BOTPID}" ]; then
|
||||
echo -e "${GREEN}Bot is running with UID ${RUNUSER}.${NC}"
|
||||
printf "${GREEN}Bot is running with UID ${RUNUSER}.${NN}"
|
||||
exit
|
||||
else
|
||||
echo -e "${ORANGE}No Bot running with UID ${RUNUSER}.${NC}"
|
||||
printf "${ORANGE}No Bot running with UID ${RUNUSER}.${NN}"
|
||||
exit 5
|
||||
fi
|
||||
debug_checks "end status" "$@"
|
||||
|
@ -1319,9 +1321,9 @@ if [ -z "${SOURCE}" ]; then
|
|||
printf "Session Name: %s\n" "${SESSION}"
|
||||
sleep 1
|
||||
if [ -n "$(proclist "${SESSION}")" ]; then
|
||||
echo -e "${GREEN}Bot started successfully.${NC}"
|
||||
printf "${GREEN}Bot started successfully.${NN}"
|
||||
else
|
||||
echo -e "${RED}An error occurred while starting the bot.${NC}"
|
||||
printf "${RED}An error occurred while starting the bot.${NN}"
|
||||
exit 5
|
||||
fi
|
||||
debug_checks "end start" "$@"
|
||||
|
@ -1337,34 +1339,34 @@ if [ -z "${SOURCE}" ]; then
|
|||
# inform botadmin about stop
|
||||
ADMIN="$(getConfigKey "botadmin")"
|
||||
[ -n "${ADMIN}" ] && send_normal_message "${ADMIN}" "Bot ${ME} stopped ..." &
|
||||
echo -e "${GREEN}OK. Bot stopped successfully.${NC}"
|
||||
printf "${GREEN}OK. Bot stopped successfully.${NN}"
|
||||
else
|
||||
echo -e "${RED}An error occurred while stopping bot.${NC}"
|
||||
printf "${RED}An error occurred while stopping bot.${NN}"
|
||||
exit 5
|
||||
fi
|
||||
else
|
||||
echo -e "${ORANGE}No Bot running with UID ${RUNUSER}.${NC}"
|
||||
printf "${ORANGE}No Bot running with UID ${RUNUSER}.${NN}"
|
||||
fi
|
||||
debug_checks "end stop" "$@"
|
||||
exit
|
||||
;;
|
||||
# suspend, resume or kill background jobs
|
||||
"suspendb"*|"resumeb"*|"killb"*)
|
||||
_is_function job_control || { echo -e "${RED}Module background is not available!${NC}"; exit 3; }
|
||||
_is_function job_control || { printf "${RED}Module background is not available!${NN}"; exit 3; }
|
||||
ME="$(getConfigKey "botname")"
|
||||
job_control "$1"
|
||||
debug_checks "end background $1" "$@"
|
||||
;;
|
||||
*)
|
||||
echo -e "${RED}${REALME##*/}: unknown command${NC}"
|
||||
echo -e "${RED}Available commands: ${GREY}${BOTCOMMANDS}${NC}" && exit
|
||||
printf "${RED}${REALME##*/}: unknown command${NN}"
|
||||
printf "${RED}Available commands: ${GREY}${BOTCOMMANDS}${NN}" && exit
|
||||
exit 4
|
||||
;;
|
||||
esac
|
||||
|
||||
# warn if root
|
||||
if [[ "${UID}" -eq "0" ]] ; then
|
||||
echo -e "\\n${ORANGE}WARNING: ${SCRIPT} was started as ROOT (UID 0)!${NC}"
|
||||
echo -e "${ORANGE}You are at HIGH RISK when running a Telegram BOT with root privileges!${NC}"
|
||||
printf "\\n${ORANGE}WARNING: ${SCRIPT} was started as ROOT (UID 0)!${NN}"
|
||||
printf "${ORANGE}You are at HIGH RISK when running a Telegram BOT with root privileges!${NN}"
|
||||
fi
|
||||
fi # end source
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
# AUTHOR: KayM (gnadelwartz), kay@rrr.de
|
||||
# CREATED: 23.12.2020 16:52
|
||||
#
|
||||
#### $$VERSION$$ v1.20-4-g1bd1727
|
||||
#### $$VERSION$$ v1.21-dev-0-g2e878fd
|
||||
#===============================================================================
|
||||
|
||||
####
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
# AUTHOR: KayM (gnadelwartz), kay@rrr.de
|
||||
# CREATED: 25.12.2020 20:24
|
||||
#
|
||||
#### $$VERSION$$ v1.20-4-g1bd1727
|
||||
#### $$VERSION$$ v1.21-dev-0-g2e878fd
|
||||
#===============================================================================
|
||||
|
||||
####
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
# AUTHOR: KayM (gnadelwartz), kay@rrr.de
|
||||
# CREATED: 16.12.2020 11:34
|
||||
#
|
||||
#### $$VERSION$$ v1.20-4-g1bd1727
|
||||
#### $$VERSION$$ v1.21-dev-0-g2e878fd
|
||||
#===============================================================================
|
||||
|
||||
####
|
||||
|
|
Loading…
Reference in New Issue