diff --git a/bashbot.sh b/bashbot.sh index c381468..aa7a71e 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.41-0-gad1b91f +#### $$VERSION$$ v1.45-dev-1-g34455c2 ################################################################## # are we running in a terminal? @@ -178,10 +178,10 @@ RUNDIR="$(dirname "$0")" MODULEDIR="${SCRIPTDIR}/modules" # adjust stuff for source, use return from source without source -alias exit_source='exit' +exit_source() { exit "$1"; } if [[ "${SCRIPT}" != "${REALME}" || "$1" == "source" ]]; then SOURCE="yes" - [ -z "$1" ] && alias exit_source='printf "Exit from source ...\n";return' + [ -z "$1" ] && exit_source() { printf "Exit from source ...\n"; return "$1"; } fi # emmbeded system may claim bash but it is not @@ -282,16 +282,14 @@ if [ -z "${BOTTOKEN}" ]; then fi # check data dir file if [ ! -w "${DATADIR}" ]; then - printf "${RED}ERROR: ${DATADIR} does not exist or is not writeable!.${NN}" - exit_source 2 + 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}ERROR: Can't write to ${COUNTFILE}!.${NN}" + printf "${RED}WARNING: Can't write to ${COUNTFILE}!.${NN}" ls -l "${COUNTFILE}.jssh" - exit_source 2 fi # setup blocked file if [ ! -f "${BLOCKEDFILE}.jssh" ]; then diff --git a/bin/bashbot_init.inc.sh b/bin/bashbot_init.inc.sh index 382b0ec..7c918cf 100644 --- a/bin/bashbot_init.inc.sh +++ b/bin/bashbot_init.inc.sh @@ -5,13 +5,13 @@ # # USAGE: source bashbot_init.inc.sh # -# DESCRIPTION: extend / overwrite bashbot initialisation +# DESCRIPTION: extend / overwrite bashbot initialisation # # LICENSE: WTFPLv2 http://www.wtfpl.net/txt/copying/ # AUTHOR: KayM (gnadelwartz), kay@rrr.de # CREATED: 27.01.2021 13:42 # -#### $$VERSION$$ v1.40-0-gf9dab50 +#### $$VERSION$$ v1.45-dev-1-g34455c2 #=============================================================================== # shellcheck disable=SC2059 @@ -54,17 +54,23 @@ bot_init() { [ -r "${addons}" ] && source "${addons}" "init" "${DEBUG}" done printf "Done.\n" - # ask for bashbot user - # shellcheck disable=SC2153 - runuser="${RUNUSER}"; [ "${UID}" = "0" ] && runuser="nobody" + # guess bashbot from botconfig.jssh owner:group + [ -f "${BOTCONFIG}.jssh" ] && runuser="$(stat -c '%U' "${BOTCONFIG}.jssh"):$(stat -c '%G' "${BOTCONFIG}.jssh")" + # empty or ":" use user running init, nobody for root + if [ "${#runuser}" -lt 3 ]; then + # shellcheck disable=SC2153 + runuser="${RUNUSER}" + [ "${UID}" = "0" ] && runuser="nobody" + fi printf "Enter User to run bashbot [${runuser}]: " read -r chown - [ -z "${chown}" ] && chown="${runuser}"; touser="${chown%:*}" + [ -z "${chown}" ] && chown="${runuser}" + touser="${chown%:*}" # check user ... 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" && "${touser}" != "${RUNUSER}" ]]; 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