mirror of
https://github.com/octoleo/telegram-bot-bash.git
synced 2024-11-24 16:27:33 +00:00
init: improve change user for regular users
This commit is contained in:
parent
a6ff405cc5
commit
429c230627
47
bashbot.sh
47
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-1-g34455c2
|
||||
#### $$VERSION$$ v1.45-dev-2-ga6ff405
|
||||
##################################################################
|
||||
|
||||
# are we running in a terminal?
|
||||
@ -161,7 +161,7 @@ debug_checks(){ {
|
||||
[ -z "$(getConfigKey "botadmin")" ] && printf "%(%c)T: %s\n" -1 "Bot admin is missing! =========="
|
||||
# call user defined debug_checks if exists
|
||||
_exec_if_function my_debug_checks "$(_date)" "${where}" "$*"
|
||||
} >>"${DEBUGLOG}"
|
||||
} 2>/dev/null >>"${DEBUGLOG}"
|
||||
}
|
||||
|
||||
# some Linux distributions (e.g. Manjaro) doesn't seem to have C locale activated by default
|
||||
@ -275,25 +275,30 @@ if [ -z "${BOTTOKEN}" ]; then
|
||||
[ -z "${admin}" ] && admin='?'
|
||||
printf '["botadmin"]\t"%s"\n' "${admin}" >> "${BOTCONFIG}.jssh"
|
||||
fi
|
||||
# setup botacl file
|
||||
if [ ! -f "${BOTACL}" ]; then
|
||||
printf "${GREY}Create initial ${BOTACL} file.${NN}"
|
||||
printf '\n' >"${BOTACL}"
|
||||
fi
|
||||
# check data dir file
|
||||
if [ ! -w "${DATADIR}" ]; then
|
||||
printf "${RED}WARNING: ${DATADIR} does not exist or is not writeable!.${NN}"
|
||||
fi
|
||||
# setup count file
|
||||
if [ ! -f "${COUNTFILE}.jssh" ]; then
|
||||
printf '["counted_user_chat_id"]\t"num_messages_seen"\n' >> "${COUNTFILE}.jssh"
|
||||
elif [ ! -w "${COUNTFILE}.jssh" ]; then
|
||||
printf "${RED}WARNING: Can't write to ${COUNTFILE}!.${NN}"
|
||||
ls -l "${COUNTFILE}.jssh"
|
||||
fi
|
||||
# setup blocked file
|
||||
if [ ! -f "${BLOCKEDFILE}.jssh" ]; then
|
||||
printf '["blocked_user_or_chat_id"]\t"name and reason"\n' >>"${BLOCKEDFILE}.jssh"
|
||||
|
||||
# skip on init
|
||||
if [ "$1" != "init" ]; then
|
||||
# setup botacl file
|
||||
if [ ! -f "${BOTACL}" ]; then
|
||||
printf "${GREY}Create initial ${BOTACL} file.${NN}"
|
||||
printf '\n' >"${BOTACL}"
|
||||
fi
|
||||
# check data dir file
|
||||
if [ ! -w "${DATADIR}" ]; then
|
||||
printf "${RED}ERROR: ${DATADIR} does not exist or is not writeable!.${NN}"
|
||||
exit_source 2
|
||||
fi
|
||||
# setup count file
|
||||
if [ ! -f "${COUNTFILE}.jssh" ]; then
|
||||
printf '["counted_user_chat_id"]\t"num_messages_seen"\n' >> "${COUNTFILE}.jssh"
|
||||
elif [ ! -w "${COUNTFILE}.jssh" ]; then
|
||||
printf "${RED}WARNING: Can't write to ${COUNTFILE}!.${NN}"
|
||||
ls -l "${COUNTFILE}.jssh"
|
||||
fi
|
||||
# setup blocked file
|
||||
if [ ! -f "${BLOCKEDFILE}.jssh" ]; then
|
||||
printf '["blocked_user_or_chat_id"]\t"name and reason"\n' >>"${BLOCKEDFILE}.jssh"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
|
@ -11,7 +11,7 @@
|
||||
# AUTHOR: KayM (gnadelwartz), kay@rrr.de
|
||||
# CREATED: 27.01.2021 13:42
|
||||
#
|
||||
#### $$VERSION$$ v1.45-dev-1-g34455c2
|
||||
#### $$VERSION$$ v1.45-dev-2-ga6ff405
|
||||
#===============================================================================
|
||||
# shellcheck disable=SC2059
|
||||
|
||||
@ -70,7 +70,7 @@ bot_init() {
|
||||
if ! id "${touser}" &>/dev/null; then
|
||||
printf "${RED}User \"${touser}\" does not exist!${NN}"
|
||||
exit 3
|
||||
elif [[ "${UID}" != "0" && "${touser}" != "${RUNUSER}" ]]; then
|
||||
elif [ "${UID}" != "0" ]; then
|
||||
# different user but not root ...
|
||||
printf "${ORANGE}You are not root, adjusting permissions may fail. Try \"sudo ./bashbot.sh init\"${NN}Press <CTRL+C> to stop or <Enter> to continue..." 1>&2
|
||||
[ -n "${INTERACTIVE}" ] && read -r runuser
|
||||
|
Loading…
Reference in New Issue
Block a user