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
|
# 8 - curl/wget missing
|
||||||
# 10 - not bash!
|
# 10 - not bash!
|
||||||
#
|
#
|
||||||
#### $$VERSION$$ v1.45-dev-1-g34455c2
|
#### $$VERSION$$ v1.45-dev-2-ga6ff405
|
||||||
##################################################################
|
##################################################################
|
||||||
|
|
||||||
# are we running in a terminal?
|
# 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! =========="
|
[ -z "$(getConfigKey "botadmin")" ] && printf "%(%c)T: %s\n" -1 "Bot admin is missing! =========="
|
||||||
# call user defined debug_checks if exists
|
# call user defined debug_checks if exists
|
||||||
_exec_if_function my_debug_checks "$(_date)" "${where}" "$*"
|
_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
|
# 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='?'
|
[ -z "${admin}" ] && admin='?'
|
||||||
printf '["botadmin"]\t"%s"\n' "${admin}" >> "${BOTCONFIG}.jssh"
|
printf '["botadmin"]\t"%s"\n' "${admin}" >> "${BOTCONFIG}.jssh"
|
||||||
fi
|
fi
|
||||||
# setup botacl file
|
|
||||||
if [ ! -f "${BOTACL}" ]; then
|
# skip on init
|
||||||
printf "${GREY}Create initial ${BOTACL} file.${NN}"
|
if [ "$1" != "init" ]; then
|
||||||
printf '\n' >"${BOTACL}"
|
# setup botacl file
|
||||||
fi
|
if [ ! -f "${BOTACL}" ]; then
|
||||||
# check data dir file
|
printf "${GREY}Create initial ${BOTACL} file.${NN}"
|
||||||
if [ ! -w "${DATADIR}" ]; then
|
printf '\n' >"${BOTACL}"
|
||||||
printf "${RED}WARNING: ${DATADIR} does not exist or is not writeable!.${NN}"
|
fi
|
||||||
fi
|
# check data dir file
|
||||||
# setup count file
|
if [ ! -w "${DATADIR}" ]; then
|
||||||
if [ ! -f "${COUNTFILE}.jssh" ]; then
|
printf "${RED}ERROR: ${DATADIR} does not exist or is not writeable!.${NN}"
|
||||||
printf '["counted_user_chat_id"]\t"num_messages_seen"\n' >> "${COUNTFILE}.jssh"
|
exit_source 2
|
||||||
elif [ ! -w "${COUNTFILE}.jssh" ]; then
|
fi
|
||||||
printf "${RED}WARNING: Can't write to ${COUNTFILE}!.${NN}"
|
# setup count file
|
||||||
ls -l "${COUNTFILE}.jssh"
|
if [ ! -f "${COUNTFILE}.jssh" ]; then
|
||||||
fi
|
printf '["counted_user_chat_id"]\t"num_messages_seen"\n' >> "${COUNTFILE}.jssh"
|
||||||
# setup blocked file
|
elif [ ! -w "${COUNTFILE}.jssh" ]; then
|
||||||
if [ ! -f "${BLOCKEDFILE}.jssh" ]; then
|
printf "${RED}WARNING: Can't write to ${COUNTFILE}!.${NN}"
|
||||||
printf '["blocked_user_or_chat_id"]\t"name and reason"\n' >>"${BLOCKEDFILE}.jssh"
|
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
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
# AUTHOR: KayM (gnadelwartz), kay@rrr.de
|
# AUTHOR: KayM (gnadelwartz), kay@rrr.de
|
||||||
# CREATED: 27.01.2021 13:42
|
# CREATED: 27.01.2021 13:42
|
||||||
#
|
#
|
||||||
#### $$VERSION$$ v1.45-dev-1-g34455c2
|
#### $$VERSION$$ v1.45-dev-2-ga6ff405
|
||||||
#===============================================================================
|
#===============================================================================
|
||||||
# shellcheck disable=SC2059
|
# shellcheck disable=SC2059
|
||||||
|
|
||||||
@ -70,7 +70,7 @@ bot_init() {
|
|||||||
if ! id "${touser}" &>/dev/null; then
|
if ! id "${touser}" &>/dev/null; then
|
||||||
printf "${RED}User \"${touser}\" does not exist!${NN}"
|
printf "${RED}User \"${touser}\" does not exist!${NN}"
|
||||||
exit 3
|
exit 3
|
||||||
elif [[ "${UID}" != "0" && "${touser}" != "${RUNUSER}" ]]; then
|
elif [ "${UID}" != "0" ]; then
|
||||||
# different user but not root ...
|
# 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
|
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
|
[ -n "${INTERACTIVE}" ] && read -r runuser
|
||||||
|
Loading…
Reference in New Issue
Block a user