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
11
bashbot.sh
11
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,6 +275,9 @@ 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
|
||||||
|
|
||||||
|
# skip on init
|
||||||
|
if [ "$1" != "init" ]; then
|
||||||
# setup botacl file
|
# setup botacl file
|
||||||
if [ ! -f "${BOTACL}" ]; then
|
if [ ! -f "${BOTACL}" ]; then
|
||||||
printf "${GREY}Create initial ${BOTACL} file.${NN}"
|
printf "${GREY}Create initial ${BOTACL} file.${NN}"
|
||||||
@ -282,7 +285,8 @@ if [ -z "${BOTTOKEN}" ]; then
|
|||||||
fi
|
fi
|
||||||
# check data dir file
|
# check data dir file
|
||||||
if [ ! -w "${DATADIR}" ]; then
|
if [ ! -w "${DATADIR}" ]; then
|
||||||
printf "${RED}WARNING: ${DATADIR} does not exist or is not writeable!.${NN}"
|
printf "${RED}ERROR: ${DATADIR} does not exist or is not writeable!.${NN}"
|
||||||
|
exit_source 2
|
||||||
fi
|
fi
|
||||||
# setup count file
|
# setup count file
|
||||||
if [ ! -f "${COUNTFILE}.jssh" ]; then
|
if [ ! -f "${COUNTFILE}.jssh" ]; then
|
||||||
@ -296,6 +300,7 @@ if [ -z "${BOTTOKEN}" ]; then
|
|||||||
printf '["blocked_user_or_chat_id"]\t"name and reason"\n' >>"${BLOCKEDFILE}.jssh"
|
printf '["blocked_user_or_chat_id"]\t"name and reason"\n' >>"${BLOCKEDFILE}.jssh"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ ! -d "${LOGDIR}" || ! -w "${LOGDIR}" ]]; then
|
if [[ ! -d "${LOGDIR}" || ! -w "${LOGDIR}" ]]; then
|
||||||
LOGDIR="${RUNDIR:-.}"
|
LOGDIR="${RUNDIR:-.}"
|
||||||
|
@ -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