init: improve change user for regular users

This commit is contained in:
Kay Marquardt (Gnadelwartz) 2021-02-07 16:56:35 +01:00
parent a6ff405cc5
commit 429c230627
2 changed files with 28 additions and 23 deletions

View File

@ -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,6 +275,9 @@ if [ -z "${BOTTOKEN}" ]; then
[ -z "${admin}" ] && admin='?'
printf '["botadmin"]\t"%s"\n' "${admin}" >> "${BOTCONFIG}.jssh"
fi
# skip on init
if [ "$1" != "init" ]; then
# setup botacl file
if [ ! -f "${BOTACL}" ]; then
printf "${GREY}Create initial ${BOTACL} file.${NN}"
@ -282,7 +285,8 @@ if [ -z "${BOTTOKEN}" ]; then
fi
# check data dir file
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
# setup count file
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"
fi
fi
fi
if [[ ! -d "${LOGDIR}" || ! -w "${LOGDIR}" ]]; then
LOGDIR="${RUNDIR:-.}"

View File

@ -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