combine printf

This commit is contained in:
Kay Marquardt (Gnadelwartz) 2021-01-01 21:48:59 +01:00
parent 03c8c9ded5
commit ed1cc4a37f
2 changed files with 57 additions and 8 deletions

View File

@ -30,7 +30,7 @@
# 8 - curl/wget missing
# 10 - not bash!
#
#### $$VERSION$$ v1.21-pre-10-g726357a
#### $$VERSION$$ v1.21-pre-11-g03c8c9d
##################################################################
# emmbeded system may claim bash but it is not
@ -140,9 +140,7 @@ RUNDIR="$(dirname "$0")"
MODULEDIR="${SCRIPTDIR}/modules"
# adjust locations based on source and real name
if [ "${SCRIPT}" != "${REALME}" ] || [ "$1" = "source" ]; then
SOURCE="yes"
fi
[[ "${SCRIPT}" != "${REALME}" || "$1" == "source" ]] && SOURCE="yes"
if [ -n "$BASHBOT_HOME" ]; then
SCRIPTDIR="$BASHBOT_HOME"
@ -210,8 +208,7 @@ if [ -z "${BOTTOKEN}" ]; then
printf "Running headless, set BOTTOKEN or run ${SCRIPT} init first!\n"
exit 2
else
printf "${RED}ENTER BOT TOKEN...${NN}"
printf "${ORANGE}PLEASE WRITE YOUR TOKEN HERE OR PRESS CTRL+C TO ABORT${NN}"
printf "${RED}ENTER BOT TOKEN...${NN}${ORANGE}PLEASE WRITE YOUR TOKEN HERE OR PRESS CTRL+C TO ABORT${NN}"
read -r token
printf "\n"
fi
@ -223,8 +220,7 @@ if [ -z "${BOTTOKEN}" ]; then
if [ -z "${INTERACTIVE}" ]; then
printf "Running headless, set botadmin to AUTO MODE!\n"
else
printf "${RED}ENTER BOT ADMIN...${NN}"
printf "${ORANGE}PLEASE WRITE YOUR TELEGRAM ID HERE OR PRESS ENTER\nTO MAKE FIRST USER TYPING '/start' BOT ADMIN${NN}?\b"
printf "${RED}ENTER BOT ADMIN...${NN}${ORANGE}PLEASE WRITE YOUR TELEGRAM ID HERE OR PRESS ENTER\nTO MAKE FIRST USER TYPING '/start' BOT ADMIN${NN}?\b"
read -r admin
fi
[ -z "${admin}" ] && admin='?'

53
xxx Normal file
View File

@ -0,0 +1,53 @@
# CREATE botconfig if not exist
# assume everything already set up correctly if TOKEN is set
if [ -z "${BOTTOKEN}" ]; then
# BOTCONFIG does not exist, create
[ ! -f "${BOTCONFIG}.jssh" ] && printf '["bot_config_key"]\t"config_key_value"\n' >>"${BOTCONFIG}.jssh"
if [ -z "$(getConfigKey "bottoken")" ]; then
# ask user for bot token
if [ -z "${INTERACTIVE}" ] && [ "$1" != "init" ]; then
printf "Running headless, set BOTTOKEN or run ${SCRIPT} init first!\n"
exit 2
else
printf "${RED}ENTER BOT TOKEN...${NN}${ORANGE}PLEASE WRITE YOUR TOKEN HERE OR PRESS CTRL+C TO ABORT${NN}"
read -r token
printf "\n"
fi
[ -n "${token}" ] && printf '["bottoken"]\t"%s"\n' "${token}" >> "${BOTCONFIG}.jssh"
fi
# no botadmin, setup botadmin
if [ -z "$(getConfigKey "botadmin")" ]; then
# ask user for bot admin
if [ -z "${INTERACTIVE}" ]; then
printf "Running headless, set botadmin to AUTO MODE!\n"
else
printf "${RED}ENTER BOT ADMIN...${NN}${ORANGE}PLEASE WRITE YOUR TELEGRAM ID HERE OR PRESS ENTER\nTO MAKE FIRST USER TYPING '/start' BOT ADMIN${NN}?\b"
read -r admin
fi
[ -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}ERROR: ${DATADIR} does not exist or is not writeable!.${NN}"
exit 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}ERROR: Can't write to ${COUNTFILE}!.${NN}"
ls -l "${COUNTFILE}.jssh"
exit 2
fi
# setup blocked file
if [ ! -f "${BLOCKEDFILE}.jssh" ]; then
printf '["blocked_user_or_chat_id"]\t"name and reason"\n' >>"${BLOCKEDFILE}.jssh"
fi
fi