mirror of
https://github.com/octoleo/telegram-bot-bash.git
synced 2024-05-28 07:53:10 +00:00
init: rework adjust user
This commit is contained in:
parent
fb8b022e24
commit
bd664dacfe
33
bashbot.sh
33
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.25-dev-46-g8253a53
|
#### $$VERSION$$ v1.25-dev-53-gfb8b022
|
||||||
##################################################################
|
##################################################################
|
||||||
|
|
||||||
# emmbeded system may claim bash but it is not
|
# emmbeded system may claim bash but it is not
|
||||||
|
@ -1105,7 +1105,7 @@ start_bot() {
|
||||||
# initialize bot environment, user and permissions
|
# initialize bot environment, user and permissions
|
||||||
bot_init() {
|
bot_init() {
|
||||||
[ -n "${BASHBOT_HOME}" ] && cd "${BASHBOT_HOME}" || exit 1
|
[ -n "${BASHBOT_HOME}" ] && cd "${BASHBOT_HOME}" || exit 1
|
||||||
local DEBUG="$1"
|
local runuser touser DEBUG="$1"
|
||||||
# upgrade from old version
|
# upgrade from old version
|
||||||
# currently no action
|
# currently no action
|
||||||
printf "Check for Update actions ...\n"
|
printf "Check for Update actions ...\n"
|
||||||
|
@ -1117,26 +1117,31 @@ bot_init() {
|
||||||
[ -r "${addons}" ] && source "${addons}" "init" "${DEBUG}"
|
[ -r "${addons}" ] && source "${addons}" "init" "${DEBUG}"
|
||||||
done
|
done
|
||||||
printf "Done.\n"
|
printf "Done.\n"
|
||||||
# setup bashbot
|
# ask for bashbot user
|
||||||
[[ "${UID}" -eq "0" ]] && RUNUSER="nobody"
|
runuser="${RUNUSER}"; [ "${UID}" = "0" ] && runuser="nobody"
|
||||||
printf "Enter User to run bashbot [${RUNUSER}]: "
|
printf "Enter User to run bashbot [${runuser}]: "
|
||||||
read -r TOUSER
|
read -r touser
|
||||||
[ -z "${TOUSER}" ] && TOUSER="${RUNUSER}"
|
[ -z "${touser}" ] && touser="${runuser}"
|
||||||
if ! id "${TOUSER}" &>/dev/null; then
|
# check user ...
|
||||||
printf "${RED}User \"${TOUSER}\" not found!${NN}"
|
if ! id "${touser}" &>/dev/null; then
|
||||||
|
printf "${RED}User \"${touser}\" does not exist!${NN}"
|
||||||
exit 3
|
exit 3
|
||||||
else
|
elif [[ "${UID}" != "0" && "${touser}" != "${runuser}" ]]; then
|
||||||
printf "Adjusting files and permissions for user \"${TOUSER}\" ...\n"
|
# different user but not root ...
|
||||||
[ -w "bashbot.rc" ] && sed -i '/^[# ]*runas=/ s/runas=.*$/runas="'"${TOUSER}"'"/' "bashbot.rc"
|
printf "${ORANGE}You are not root change to \"${touser}\" may fail, try \"sudo ./bashbot.sh init\"${NN}" 1>&2
|
||||||
|
fi
|
||||||
|
# adjust permissions
|
||||||
|
printf "Adjusting files and permissions for user \"${touser}\" ...\n"
|
||||||
chmod 711 .
|
chmod 711 .
|
||||||
chmod -R o-w ./*
|
chmod -R o-w ./*
|
||||||
chmod -R u+w "${COUNTFILE}"* "${BLOCKEDFILE}"* "${DATADIR}" logs "${LOGDIR}/"*.log 2>/dev/null
|
chmod -R u+w "${COUNTFILE}"* "${BLOCKEDFILE}"* "${DATADIR}" logs "${LOGDIR}/"*.log 2>/dev/null
|
||||||
chmod -R o-r,o-w "${COUNTFILE}"* "${BLOCKEDFILE}"* "${DATADIR}" "${BOTACL}" 2>/dev/null
|
chmod -R o-r,o-w "${COUNTFILE}"* "${BLOCKEDFILE}"* "${DATADIR}" "${BOTACL}" 2>/dev/null
|
||||||
# jsshDB must writeable by owner
|
# jsshDB must writeable by owner
|
||||||
find . -name '*.jssh*' -exec chmod u+w \{\} +
|
find . -name '*.jssh*' -exec chmod u+w \{\} +
|
||||||
chown -R "${TOUSER}" . ./*
|
chown -R "${touser}" . ./*
|
||||||
printf "Done.\n"
|
printf "Done.\n"
|
||||||
fi
|
# adjust values in bashbot.rc
|
||||||
|
[ -w "bashbot.rc" ] && sed -i '/^[# ]*runas=/ s/runas=.*$/runas="'"${touser}"'"/' "bashbot.rc"
|
||||||
# ask to check bottoken online
|
# ask to check bottoken online
|
||||||
if [ -z "$(getConfigKey "botid")" ]; then
|
if [ -z "$(getConfigKey "botid")" ]; then
|
||||||
printf "Seems to be your first init. Should I verify your bot token online? (y/N) N\b"
|
printf "Seems to be your first init. Should I verify your bot token online? (y/N) N\b"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user