From 429c2306274bc5d82235b15bfbdfa5e0e514fcdf Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sun, 7 Feb 2021 16:56:35 +0100 Subject: [PATCH] init: improve change user for regular users --- bashbot.sh | 47 +++++++++++++++++++++++------------------ bin/bashbot_init.inc.sh | 4 ++-- 2 files changed, 28 insertions(+), 23 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index aa7a71e..14de2d1 100755 --- a/bashbot.sh +++ b/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 diff --git a/bin/bashbot_init.inc.sh b/bin/bashbot_init.inc.sh index 7c918cf..48d7f13 100644 --- a/bin/bashbot_init.inc.sh +++ b/bin/bashbot_init.inc.sh @@ -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 to stop or to continue..." 1>&2 [ -n "${INTERACTIVE}" ] && read -r runuser